About protected pages #1403
Replies: 2 comments 1 reply
|
Correction, August 29: This answer was wrong about |
|
Hi @monsieurmerle, I need to correct my earlier reply. Your EDIT 2 approach is right, and my suggestion to use I mixed up what So yes, keep this at the top of each protected page: set id_user = (...);
select 'redirect' as component,
'login.sql?error' as link
where $id_user is null;This is the same pattern used in SQLPage's authentication example. If you want to reduce the repetition, you can move the user lookup into a database view or function, or use one session table with Sorry about that. I should not have presented the |
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Hi again everyone,
I have a new question, but first some context :
The app I am making has four types of users : administrators, companies, managers and workers (sometimes called technical workers). Most pages are only accessible to one type of user, though some are shared between the companies and managers, as well as handlers and pages where the user is asked if they are sure about deleting some things.
Each user must log in to use the app, and I am storing session tokens in four separate tokens (one per user type) :
For each user, there is a dedicated table where the hashed password, username, etc.. are stored.
Each protected page begins with some variations of :
Where I check the user is allowed to be here, redirected to login if he isn't and the id of the user is gathered before the header is displayed. (depending on the page, the token is compared to the matching session table) (there are also different headers for each user type)
So, everything works as it is now, but I am wondering if it would be possible to tuck some part of it away to only have the code once and just have to call it.
I don't know if I can protect a page while allowing multiple types of users to have access to it (because pages accessible to multiple user types are not protected for now), I am maybe thinking of using something like :
You will have noticed the line :
I use it for a lot of different things, in pages shared between user types it helps determine where to redirect depending who the user is. So I do need it.
Please tell me if it is possible to simplify the code, I am aware that this is not the best at all, but I do not know of any better way to do it yet. I can't really make a minimal reproducible example, as it works as it is.
Thank you in advance for any help you can bring
EDIT : regarding the variable id_user, I am trying to find a way to declare varibles that I could access from all pages (it can be by calling the page where they are declared). I am trying to use the dynamic component for this without success, is this a job for a cookie ?
EDIT 2 : I found and have tried the way pages are protected in the User Management example, using only
to handle the protection. It seems to work for now and is more compact. Please tell me if this is a bad idea
All reactions