Jump to content

User Redirect After Login based on Two Conditions for Two different user types


Recommended Posts

Hi, 

 

My App has two suer types - Host and Businesses, at login I want to redirect each user to a different webpage where they will have access to different data pages.  I also want to create a condition whereby if they have completed set up, they will be directed to the main homepage for that user, and if they have they will be directed to a setup page to complete set up.  My initial Authorization Table contains three data sets to help me achieve this:

User Type: Host/Business - (Drop Down in Data page)

Set Up Complete Host: Yes/No - Hidden

Set Up complete Business Yes/No - Hidden. I have amended the following script to try and work but its not working:

 

<script>
}
else if ("[@authfield:membership_type]" == "Business") && ([@authfield:business_set_up_complete]" == "No") { window.location = "https://www.test.com/business-set-up/"; }
}
else if ("[@authfield:membership_type]" == "Business") && ([@authfield:business_set_up_complete]" == "Yes"){ window.location = "https://www.test.com/business-home.html";

else if ("[@authfield:membership_type:host]" == "Host") && ([@authfield:business_set_up_complete]" == "No") { window.location = "https://www.test.com/host-set-up/"; }

else if ("[@authfield:membership_type:host]" == "Host") && ([@authfield:business_set_up_complete]" == "No") { window.location = "http://www.test.com/host-home.html";
}
</script>

Link to comment
Share on other sites

Hi @SamNZ - may you please try this:

<script>

if ("[@authfield:membership_type]" == "Business") && ("[@authfield:business_set_up_complete]" == "No") { 
  window.location = "https://www.test.com/business-set-up/"; 
}
else if ("[@authfield:membership_type]" == "Business") && ("[@authfield:business_set_up_complete]" == "Yes"){ 
  window.location = "https://www.test.com/business-home.html";
} 
else if ("[@authfield:membership_type:host]" == "Host") && ("[@authfield:business_set_up_complete]" == "No") { 
 window.location = "https://www.test.com/host-set-up/"; 
}

else if ("[@authfield:membership_type:host]" == "Host") && ("[@authfield:business_set_up_complete]" == "No") { 
  window.location = "http://www.test.com/host-home.html";
}

</script>

There seems to be missing quotes in your code and unexpected identifier. 

Here's a reference: https://howto.caspio.com/tech-tips-and-articles/common-customizations/create-user-specific-redirect-after-login/

Link to comment
Share on other sites

Thanks you so much, really helpful.

Okay so I think I need t set up my views, and change the user type to yes no questions, but my problem is to keep it clean for my users, I need to them to be able to select one of the other, creating two users both with Yes No questions creates the ability to select both user types as yes, which I do not want, then if I just base it on one yes no questions, i can only have one user type in my form, ie Host Yes/No, so if its no they are a business user, but I cant create a selectable option for Businesses so it will be confusing. The Caspio tutorial works well if someone else is signing people, ie: the admin, not if you want people to sign themselves up, or is there a trick here I am missing? 

Link to comment
Share on other sites

Maybe its just me, but the user interface seems different, has Caspio changed since this was created in 2014?  Ive created views based on:

 

user type selected

accoutn active

Set Up complete

but when i goto authentications, it doesn't give me the options of using these views?

Link to comment
Share on other sites

@SamNZ You don't need to use yes/no fields. You can use whatever you want, really, for the redirections. 

Personally, I would keep Membership Type as a text(255), so that the user can select either Business or Host. Then, if you need to in the future, you can expand that with more options much more easily than you would if you were using a Yes/No field for every role.

Then, for business_set_up_complete, you could either use text(255), or if the only options are Yes and No, then you can use the yes/no field. 

The redirection script can be changed to fit your needs, but the one that @Meekeee shared should work for how you first had it set up (I do not think it will work if you change all fields to Yes/No).

 

Then, in your submission form for creating user profiles, you would have a dropdown or radio buttons to select which Membership Type. I'm not sure if you are letting the users state that their business set up is complete or if you are calculating that yourself, but if they do then you can either make that a checkbox or radio buttons too so. Now you have the data you need for the login redirections.

 

 

Link to comment
Share on other sites

Just now, SamNZ said:

Maybe its just me, but the user interface seems different, has Caspio changed since this was created in 2014?  Ive created views based on:

but when i goto authentications, it doesn't give me the options of using these views?

The answer to both of these can be found in the how to site.

https://howto.caspio.com/

I highly, highly recommend looking through this as it can help you tremendously when first starting. You can find changes in the Release Notes section and how to use views in authentications in the Authentication section.

Link to comment
Share on other sites

Also, you don't need to make views for the roles for redirection. You can just use your User Table. The javascript is doing the filtering with the two conditions set already. You need the full datasource for the redirections to work.

i.e., if you set the datasource to Host_View, then your Business members won't be included in the datasource, so they won't be able to log in. 

Link to comment
Share on other sites

So it still wouldnt work, so i tweaked it to test the host and business parameters and this worked, 

<script>
if ("[@authfield:membership_type]" == "Business"){ 
  window.location = "https://test.com/business-homepage/"; 

else if ("[@authfield:membership_type:host]" == "Host")  { 
 window.location = "https://test.com/host-homepage/"; 
}
</script>

 

I wonder if its the "&&" feature or the Yes/No.... 

Link to comment
Share on other sites

18 minutes ago, SamNZ said:

I wonder if its the "&&" feature or the Yes/No....

One thing to keep in mind with Yes/No fields is that Caspio doesn't treat the values the same in all instances. Sometimes Yes and No equal 1 and 0, sometimes Y and N, sometimes Yes and No. If whatever you are doing isn't working in the future, try the different value types just in case.

Don't know why they don't keep it uniform throughout. 

Link to comment
Share on other sites

  • 1 year later...

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
Reply to this topic...

×   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...