Redirect back to previous page when visiting login and sign up pages after user is already logged in
This commit is contained in:
@ -160,7 +160,9 @@ passport.use(new GoogleStrategy({
|
|||||||
|
|
||||||
// Simple route middleware to ensure user is authenticated. Otherwise send to login page.
|
// Simple route middleware to ensure user is authenticated. Otherwise send to login page.
|
||||||
exports.ensureAuthenticated = function ensureAuthenticated(req, res, next) {
|
exports.ensureAuthenticated = function ensureAuthenticated(req, res, next) {
|
||||||
if (req.isAuthenticated()) { return next(); }
|
if (req.isAuthenticated()) {
|
||||||
|
return next();
|
||||||
|
}
|
||||||
res.redirect('/login');
|
res.redirect('/login');
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -17,6 +17,10 @@ exports.account = function(req, res) {
|
|||||||
* GET /login
|
* GET /login
|
||||||
*/
|
*/
|
||||||
exports.getLogin = function(req, res) {
|
exports.getLogin = function(req, res) {
|
||||||
|
if (req.user) {
|
||||||
|
return res.redirect('back');
|
||||||
|
}
|
||||||
|
|
||||||
res.render('login', {
|
res.render('login', {
|
||||||
title: 'Login',
|
title: 'Login',
|
||||||
user: req.user,
|
user: req.user,
|
||||||
@ -48,6 +52,10 @@ exports.postLogin = function(req, res, next) {
|
|||||||
* GET /signup
|
* GET /signup
|
||||||
*/
|
*/
|
||||||
exports.getSignup = function(req, res) {
|
exports.getSignup = function(req, res) {
|
||||||
|
if (req.user) {
|
||||||
|
return res.redirect('back');
|
||||||
|
}
|
||||||
|
|
||||||
res.render('signup', {
|
res.render('signup', {
|
||||||
title: 'Create Account',
|
title: 'Create Account',
|
||||||
user: req.user,
|
user: req.user,
|
||||||
|
@ -6,3 +6,4 @@ body {
|
|||||||
padding-top: 60px;
|
padding-top: 60px;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -176,12 +176,12 @@ a {
|
|||||||
}
|
}
|
||||||
|
|
||||||
.github {
|
.github {
|
||||||
background-color: #000;
|
background-color: #666;
|
||||||
border-color: #000;
|
border-color: #666;
|
||||||
&:focus,
|
&:focus,
|
||||||
&:hover {
|
&:hover {
|
||||||
background-color: transparent;
|
background-color: transparent;
|
||||||
color: #000;
|
color: #666;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1,6 +1,7 @@
|
|||||||
extends layout
|
extends layout
|
||||||
|
|
||||||
block content
|
block content
|
||||||
|
.login-wrapper
|
||||||
.login-container
|
.login-container
|
||||||
h3.text-center
|
h3.text-center
|
||||||
span.text-primary PROJECT
|
span.text-primary PROJECT
|
||||||
@ -37,7 +38,7 @@ block content
|
|||||||
i.fa.fa-github
|
i.fa.fa-github
|
||||||
| GitHub
|
| GitHub
|
||||||
p Don't have an account yet?
|
p Don't have an account yet?
|
||||||
a(href='signup1.html') Sign up now
|
a(href='/signup') Sign up now
|
||||||
|
|
||||||
|
|
||||||
if messages.length
|
if messages.length
|
||||||
|
Reference in New Issue
Block a user