Answer the question
In order to leave comments, you need to log in
How to properly organize the site robot on nodejs?
I am developing a small application, but I have no experience in server-side programming. Node.js application, ejs templating engine.
It is necessary that it be like this:
1. At the entrance it asks for a login / password.
2. If true - shows the main page.
3. The user enters data, sends it via ajax.
4. The server, having received a request, changes the appearance of this page (the data on it).
What is now:
On entry ("/") index.js:
router.get('/', function(req, res) {
if (req.signedCookies.rememberme == 'registered') {
var register = true
res.render('index', { register:register });
} else {
var register = false;
res.render('index', { register:register });
}
});
<% if (register == false) { %>
<%= include login.ejs %>
<% } %>
<% if (register == true) { %>
<%= include main.ejs %>
<% } %>
res.cookie('ImRegistered', 'registered', { maxAge: 900000, signed: true })
res.render('index', { register:register, somevar: 'someval' });
Answer the question
In order to leave comments, you need to log in
Authorization through cookies - holes are safe, especially since they are not even obfuscated.
From the cookie name ImRegistered and signed, you can understand why it is needed and substitute your value.
Use sessions https://github.com/expressjs/session
Offtopic: terrible code. First, don't declare variables in conditional blocks. Secondly, don't you see that you have the same thing written twice?
router.get('/', function(req, res) {
res.render('index', { register: req.signedCookies.rememberme == 'registered' })
});
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question