Jump to content
  • 0

Login script that checks a box in table during log in


techguy
 Share

Question

I am using a login script that re-directs a person to a specific page based on a role in. Is there a way to modify this script to check a yes/no box to yes when logging in.. then somehow run a script that checks the biox to "no" when logging out of the system or being timed out of the system?

 

Here is the script I am using to log in...

 

<script>
if("[@authfield:Role]" == "Admin"){
window.location = "admin.html?UserID=[@authfield:User_ID]";
}
else if("[@authfield:Role]" == "Agent"){
window.location = "actionlog.html?UserID=[@authfield:User_ID]&FN=[@authfield:First_Name]&LN=[@authfield:Last_Name]";
}
else{
window.location = "oops.html";
}
</script>

 

Thanks

-Mike

 

 

Link to comment
Share on other sites

8 answers to this question

Recommended Posts

  • 0

Hello. I am trying to determine a way for users to see other users that are currently logged into an app. Caspio does not make this easy (or I am not finding a way to do this without programming). I thought a check box in the user table would be an easy way to see if the user is logged in or out. When they log in, the system checks the box and when they log out the system unchecks the box. All other low code platforms I have used was able to do this without custom code..

 

Any suggestions to make it so you can add this to app users to see if they are logged in or not?

Link to comment
Share on other sites

  • 0

HI I had the same issue when I created my app.  Here's what I did and I hope it helps:

1. Create a Timestamp field in your table that is checked Stamp on update; call it Logged_in_time (or whatever)

2. Have all users log in to a Single Record update form instead of a report page.  A logged out user will see the login form first

2. Place a hidden field  that updates something in the auth users record (perhaps Latitude /Longitude, or a yes/no field that is titled Logged_in)

3. When the users logs into the form, hide the form instead with a display:none, and place code at the bottome of the form to autosubmit; theres help in the formun on that.  When it autosubmits, it updates the record, and it you can direct it to your report page.

4. Your Timestamp is now updated and it "appears" that the user is logged in.  Sort your data by Timestamp date  z to a so the newest "logged in" members will appear first.

5.  I didnt care if the user logged out because I sorted my data showing newest people first, but You could create a yes/no update form that when the "sign out" it actually updates this field to no, and sort your data by Logged_in yes/no field instead.

 

What do you think?

Link to comment
Share on other sites

  • 0

I tried this with a datapage but could not get it working properly since I am using a html login page the redirects users based on role. But I will try this method and see how it works. I appreciate your help. It is crazy to me that the system is capturing login info (as I see it in the admin side of caspio) but I can not build any pages based on that or create any way for the system to know if someone is logged in. Thank you so much for responding. I thought about moving to another platform since so many things need to be "worked" around to make work that other systems just have built in and very easy to make work... we will see!!

 

Thanks again!

Link to comment
Share on other sites

  • 0

I think what your doing can be done!...Just use an single update record form and have users  sign in and when they do they wont see the form which will auto submit and redirects to a report page; I forgot to tell you to give the autosubmit a 1 or 2 second delay or it "goes to fast" for it to work..

  Yes i could not believe that there is no way in Caspio to see users logged in and a lot of things do need to be worked on that are instantly there on some other platforms (logiforms).  I tried some others but came back here because of the unlimited data transfer, members, and the image shrink feature, and now they have SMS and triggers (didnt have 2 years ago).   But yes Caspio has to be worked around like: Why cant a Unique field auto check the server when a user is filling out the field to see if the Name is available instead of going thru the whole form process only to get an error; the Delete confirmation Box is annoying (id like to have the user just hit a delete button and thats it without that stupid pop up box thats not even mobile ready; lot of cut and pasting in this platform (it should be features there already).

Link to comment
Share on other sites

  • 0

Hi,

 

Just to elaborate @AtayBalunbalunan's solution, you may try to implement this solution.

 

0.) Add an 'isLoggedIn' field (DataType: Yes/No) to your Users Table.

 

1.) For your Login, Create a Single-Record Update (SRU) DataPage (Login DataPage) and set Restrict Access to your Authentication

1.1.) Set your isLoggedIn field to 'Hidden' and check OnLoad, receive "Yes"

1.2.) Create a Virtual Field and check OnExit in the Advanced Tab.

1.3.) Create a Footer, disable the HTML Editor from the Advanced Tab, paste>modify the code snippet

<script>

  var vf = document.querySelector(`[action*='[@cbAppKey]'] [id*=cbParamVirtual1]`);

  if ('[@field:role]' == 'admin') {
  	vf.value = "https://www.google.com";
  }
  else if ('[@field:role]' == 'user') {
  	vf.value = "https://www.youtube.com";
  }
  else {
  	vf.value = "https://www.facebook.com"
  }

  vf.form.submit();


</script>

 

1.4.) Set your Destination Options to 'Go to a new page', and set the Page URL to go to [@Virtual1].

 

2.) Set your Authentication > Timeout and redirection > Designated entry Page to 'Go to a DataPage' and set it to your Login DataPage

 

3.) For your Logout, duplicate>rename your Login DataPage (Let's call it Logout DataPage for this example)

3.1.) Set your isLoggedIn field to 'Hidden' and un-check OnLoad, receive "Yes"

3.2) Replace the entire footer code with the snippet below, and hit Finish:

<script>
  var vf = document.querySelector(`[action*="[@cbAppKey]"] [id*=cbParamVirtual1]`);
  vf.value += '/folderlogout';
  vf.form.submit();
</script>

 

For all your logout Links, just point your users to Logout DataPage to uncheck the isLoggedIn field from your users table.

 

Also attaching the app that I made with this implementation though you might need to modify the links in ILI Login DataPage > Footer for it to work.

Is_Logged_In_1_0_2019-Jan-08_2340.zip

 

The usernames are: dn31337, user1, and user2.

 

Hope this helps.

 

Cheers,

DN31337

 

Link to comment
Share on other sites

  • 0

In addition to my previous post,

 

> It works just by importing.

> You will need to Bulk Deploy all the DataPages before you'll be able to use it.

image.thumb.png.bb6df13c4c4efd17e4318ef4a4e0b7a7.png

 

> The isLoggedIn field will not be unchecked unless the user goes to the Logout DataPage. In that case, just create a Task that will cleanse your Users table

image.thumb.png.f67a73e83f732a5cd42af79f7889d901.png

 

Regards,

DN31337

Link to comment
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...
 Share

×
×
  • Create New...