Commit 22482a26 authored by Rosanny Sihombing's avatar Rosanny Sihombing
Browse files

Update README.md

parent b636d452
...@@ -7,31 +7,36 @@ There are 2 options: ...@@ -7,31 +7,36 @@ There are 2 options:
- However, having redundant pages often leads to inconsistency and other problems. - However, having redundant pages often leads to inconsistency and other problems.
2. Use view engine to enable having if-else conditions on 1 page 2. Use view engine to enable having if-else conditions on 1 page
- This is the option I take for this project. - This is the option I take for this project.
- You need to get familiar with the view engine. I use pug (https://pugjs.org/api/getting-started.html) on this project. - You need to get familiar with the view engine. I use [pug](https://pugjs.org/api/getting-started.html) on this project.
- You can convert your existing html page to pug using this website: https://html-to-pug.com/. I have tried it to convert index.html(https://gitlab.com/Cholgrrr/m4labplatform/-/blob/sso/vcm/index.html) to index.pug(https://gitlab.com/Cholgrrr/m4labplatform/-/blob/sso/vcm/index.pug) and it works. - You can convert your existing html page to pug using this website: https://html-to-pug.com/. I have tried it to convert [index.html](https://gitlab.com/Cholgrrr/m4labplatform/-/blob/sso/vcm/index.html) to [index.pug](https://gitlab.com/Cholgrrr/m4labplatform/-/blob/sso/vcm/index.pug) and it works.
- Example on this project: - Example on this project, define the route on `server.js`:
define the route on server.js: ```
app.get('/index', function (req, res) { app.get('/index', function (req, res) {
if (req.isAuthenticated()) { if (req.isAuthenticated()) {
res.render('index', { res.render('index', {
userLogin: true userLogin: true
}) })
} else { } else {
res.render('index', { res.render('index', {
userLogin: false userLogin: false
}) })
} }
}) })
then use the userLogin parameter in the if-else condition on index.pug: ```
if userLogin == true then use the `userLogin` parameter in the if-else condition on index.pug:
button#tourstart-btn.buttonset.one(onclick='stopStory()') ```
span.i18n_balloon_startscreen_btn Start if userLogin == true
else button#tourstart-btn.buttonset.one(onclick='stopStory()')
button span.i18n_balloon_startscreen_btn Start
span.i18n_balloon_startscreen_btn Login else
button
span.i18n_balloon_startscreen_btn Login
```
### Preventing user to directly access an html ### Preventing user to directly access an html
If you choose option 1 and want to prevent users to directly access an html, you can try to redirect them to any page you want just like the following: If you choose option 1 and want to prevent users to directly access an html, you can try to redirect them to any page you want just like the following:
```
app.get('/index.html', function (req, res) { app.get('/index.html', function (req, res) {
res.redirect('/index') res.redirect('/index')
}) })
```
\ No newline at end of file
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment