I am trying to conditionally show/hide HTML elements based what type of user is logged in. I’m not too familiar with how Caspio sessions are handled and how they relate to my HTML pages. I also have very little Javascript experience.
There should be three levels of access, Admin, Manager, and User. I currently have an authentication table that has three users and three yes/no fields (admin/manager/user), each user is a different type.
My first idea was to use cookie data. On successfully logging into my authentication form it would make a cookie for user type which would have a value of admin, manager, or user. Then I could use that cookie to add the display:none style to certain elements that I don’t want lower access users viewing.
My problem is that I’m not sure how to do that with Javascript, or if that is the best practice.
I currently have an HTML Datapage linked to my Authentication. On that page is this code:
var type_admin = '[@authfield:admin]';
var type_manager = '[@authfield:manager';
var type_user = '[@authfield:user]';
if (type_admin == "Yes")
{
document.cookie="type=admin";
}
else if (type_manager == “Yesâ€)
{
document.cookie="type=manager";
}
else if (type_user == “Yesâ€)
{
document.cookie="type=user";
}
Then I assume I would just reference the cookie on my HTML pages somewhat like this:
<div class="adminContent">
Show this content if the user is Admin
</div>
<div class=â€managerContentâ€>
Show this content if the user id Manager
</div>
<div class=â€userContentâ€>
Otherwise show this content
</div>
In the end I would like to be able to filter things like navigation buttons or div blocks. It would be great to have an Admin Tools link in the navigation that only Admins/Managers could see.
I’m not sure the specifics of getting something like this to work. Also I don’t know how to keep that @authfield data throughout different HTML pages (not linked to Caspio) and I’m just assuming Cookies are the best option. Any help would be greatly appreciated.
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.
Question
Domco
I am trying to conditionally show/hide HTML elements based what type of user is logged in. I’m not too familiar with how Caspio sessions are handled and how they relate to my HTML pages. I also have very little Javascript experience.
There should be three levels of access, Admin, Manager, and User. I currently have an authentication table that has three users and three yes/no fields (admin/manager/user), each user is a different type.
My first idea was to use cookie data. On successfully logging into my authentication form it would make a cookie for user type which would have a value of admin, manager, or user. Then I could use that cookie to add the display:none style to certain elements that I don’t want lower access users viewing.
My problem is that I’m not sure how to do that with Javascript, or if that is the best practice.
I currently have an HTML Datapage linked to my Authentication. On that page is this code:
Then I assume I would just reference the cookie on my HTML pages somewhat like this:
Here are the HTML/PHP files I’m working with:
http://domco.us/vita/test/
And here is the login page that’s just an embedded Datapage:
http://domco.us/vita/page_login.php
In the end I would like to be able to filter things like navigation buttons or div blocks. It would be great to have an Admin Tools link in the navigation that only Admins/Managers could see.
I’m not sure the specifics of getting something like this to work. Also I don’t know how to keep that @authfield data throughout different HTML pages (not linked to Caspio) and I’m just assuming Cookies are the best option. Any help would be greatly appreciated.
Link to comment
Share on other sites
6 answers to this question
Recommended Posts
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.