简体   繁体   中英

How to serve index.html with certain elements to certain users?

I am wanting to serve various users a index.html page however certain users can only see certain elements such as buttons for example. I'm using the Express framework, I know you can "register" views then feed the allow / deny certain web pages to a user but I want to allow / deny certain elements for a webpage when the login. Was wondering if anyone has experience in this?

This is a relatively common use case. Logged in users generally show some sort of account link, while logged out users generally show a login button, or perhaps a signup button.

I have never used express, but its documentation suggests using jade templating engine which should support conditionals.

http://expressjs.com/guide/using-template-engines.html

With jade, you could render an index.html using a context containing a user, and render the specific template elements conditionally:

http://jade-lang.com/reference/conditionals/


Another approach is rendering completely separate index.html files based on your user classes.


tempalte inheritance is another powerful tool to render similar templates to different users. Generally it is used to contain your base template information, ie site-wide header, footer, body container


and keep in mind, conditionally showing links and elements and buttons on a page isn't enough to protect your site, if a user shouldn't access a specific endpoint then authentication/authorization needs to be enforced on the server side

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM