Answer the question
In order to leave comments, you need to log in
How to implement login/authorization with express js?
Good day to all.
I am doing a project on express, it remains for me to implement authorization.
my html/ejs with login :
<%= errr %>
<form class="form-signin"id="log form" type='post' action="/login/">
<h2 class="form-signin-heading">Вход в систему</h2>
<input type="text" class="form-control" name="usernames" placeholder="Логин" required autofocus="" autocomplete="off"/>
<input type="password" class="form-control" name="password" placeholder="Пароль" required autocomplete="off"/>
<button id="send" type='submit' class="btn btn-lg btn-primary btn-block" >Вход</button>
</form>
router.post('/login/', function (req, res, next) {
var log_user = req.body.usernames;
var log_passw = req.body.password
if(log_user == user_one && log_passw == passw_one ){
res.render('index_one',{some_data:'this_user_data'})
}else if(log_user == user_second && log_passw == passw_second ) {
res.render('index_second',{some_data:'this_user_data'})
}else{
а что написать здесь, чтобы оповестить пользователя об ошибке и оставить его на странице входа? }
})
Answer the question
In order to leave comments, you need to log in
You do not want to take a ready-made solution ?
In a template with a login, it makes sense to display the login in the login input field for the convenience of the user.
Hmm ... I did what you advised, it works, but there is one BUT!
After a successful user login, if you click on the "back" button / arrow in the browser, you go to the previous page, with entering a password and login, and if you now click on the "forward" button / arrow here, then you enter without entering a login and password.
Is it some kind of browser cache? how to deal with it?
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question