Jump to content
  • 0
alexeightsix

How To Determine If The User Is Currently Logged In?

Question

Hello,

 

I'm trying to integrate Caspio into my WordPress theme and I need to show/hide content based on the condition of the user being logged in or not to Caspio. Does Caspio provide a variable or some way for me to check if the current user is logged in?

 

Thanks

 

Share this post


Link to post
Share on other sites

9 answers to this question

Recommended Posts

  • 0

Hello alexeightsix,

 

As far as I know, if you have assigned a DataPage with Authentication, and a user is not logged in, he/she will see the Login page of the Authentication.

You can read more details about Authentications in the article or see the video.

Share this post


Link to post
Share on other sites
  • 0

I understand this point, but for example I need to show/hide a sidebar based on the fact of the user being logged in or not to caspio. Does caspio provide an API/variables for the developer to query ?

 

Hello alexeightsix,

 

As far as I know, if you have assigned a DataPage with Authentication, and a user is not logged in, he/she will see the Login page of the Authentication.

You can read more details about Authentications in the article or see the video.

Share this post


Link to post
Share on other sites
  • 0

If a DataPage that requires authentication is not authenticated it won't populate; so you can test for the presence of elements within said DataPage.

 

Create a DataPage that requires authentication that contains the following div

<div id="loggedInTestDiv">Hi</div>

Embed and hide it.

<div id="loggedInTestPage">
    <script ... Caspio Data Page ...></script>
</div>

#loggedInTestPage  {
    display: none;
}

Determine the Div's existence and show or hide the Side Bar.

http://stackoverflow.com/questions/10886190/check-if-a-div-does-not-exist-with-javascript

var mySideBar = document.getElementById('sideBar');
var myTestElem = document.getElementById('loggedInTestDiv');
if (myTestElem == null) {
    //user not logged in
    mySideBar.style.display = 'none';
  } else {
    //user logged in
    mySideBar.style.display = 'inline':
  }

Hope it Helps

Share this post


Link to post
Share on other sites
  • 0

 

On 11/12/2016 at 2:09 AM, skauntey said:

Hi ezIQchad,

Could you please elaborate, how to install the script you have mentioned here? In theory, I find it quite useful but faced some difficulties while implementing right codes at right places.

Thanks in advance.

  • What are you trying to accomplish?
  • What have you tried?
  • What happened?
  • What did you expect to happen?

Share this post


Link to post
Share on other sites
  • 0

Hi, have a similar question:

Im trying to send a notification to currently logged-in user, when he/she adds a record in one of the tables. I was able to hardcode who to send it to, but now am trying to check which user has added the record, then look up this user's email/phone and send notification to that user. How can I do that? 

 

I have a User table (fields: ID, password, contact info) and Records table that contain RecordId, RecordName and UserWhoUpdated. Trying to send based on updates to Records table. by User who Updated. Thanks

Share this post


Link to post
Share on other sites
  • 0

In authentication you have the option to send users to a specific page if they are not logged in. So you can have two versions of your web page one that is being shown to the users who are not logged in and another one for logged in user. You can create Caspio HTML page for this purpose as well. For instance if you want to show different menus

Share this post


Link to post
Share on other sites
  • 0

Hi all,

Sorry, I know this is a very old topic, but I tried to follow ezIQchad code, but I have some questions about it, because mine is not working. These were my steps

1)  created a HTML datapage in caspio and added the code:

<div id="loggedInTestDiv">Hi</div>

2) I created a page in Divi (my theme) and put there a "Divi code module" that calls the login datapage above and also the other datapage I want to show only if the user is logged in. (For test purposes I removed the display:none from the code)

<div id="loggedInTestPage">
    <script type="text/javascript" src="https://c3bkr431.caspio.com/dp/ae7e40008cfca8cb29f54162918a/net"></script>
</div>
<div id="asia"> 
    <script type="text/javascript" src="https://c3bkr431.caspio.com/dp/ae7e40008cfca8cb29f54162918a/net"></script> 
</div>

3) Added the Javascript in the same module so I end up with only one moude with all the code (I kept the variable names for tests purposes):

<div id="loggedInTestPage"> 
     <script type="text/javascript" src="https://c3bkr431.caspio.com/dp/ae7e40008cfca8cb29f54162918a/net"></script> 
</div>
<div id="asia"> 
   <script type="text/javascript" src="https://c3bkr431.caspio.com/dp/ae7e40008cfca8cb29f54162918a/net"></script> 
</div>

<script type="text/javascript">
var mySideBar = document.getElementById('sideBar');
var myTestElem = document.getElementById('loggedInTestDiv');
if (myTestElem == null) {
    //user not logged in
    mySideBar.style.display = 'none';
  } else {
    //user logged in
    mySideBar.style.display = 'inline';
  }
</script>

 

 

 

Share this post


Link to post
Share on other sites
  • 0

Unsure, but I wonder if the authenticated DataPage has not had a chance to load yet so the test will always fail as it runs too early.

Try an iframe deployment and run the check onload.

<iframe name="dp_name" title="dp_name" src="https://123.caspio.com/dp/123">Sorry, but your browser does not support frames.</iframe>

<script>
  var loggedInTestIfr = document.getElementsByName('dp_name')[0];
  loggedInTestIfr.onload = function(){ checkLoggedIn(); };
  
  function checkLoggedIn(){
    var myTestElem = document.getElementById('loggedInTestDiv');
    if (myTestElem == null) {
        //user not logged in
        console.log('Not logged in');
    } else {
        //user logged in
        console.log('Logged in');
    }
  }
</script>

What is the URL for you page? I'll take a look (if you also answer, or at least try to answer, the questions above)

Share this post


Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Answer this question...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...

×
×
  • Create New...