v1.18.x
barisusakli 11 years ago
parent 3d68c7c6b6
commit 9564b6fda2

@ -183,6 +183,11 @@ Controllers.login = function(req, res, next) {
};
Controllers.register = function(req, res, next) {
if (req.user) {
res.redirect('/');
}
var data = {},
login_strategies = auth.get_login_strategies(),
num_strategies = login_strategies.length;
@ -206,7 +211,7 @@ Controllers.register = function(req, res, next) {
data.maximumUsernameLength = meta.config.maximumUsernameLength;
data.minimumPasswordLength = meta.config.minimumPasswordLength;
data.termsOfUse = meta.config.termsOfUse;
res.render('register', data);
};

@ -22,7 +22,7 @@ var app,
middleware.authenticate = function(req, res, next) {
if(!req.user) {
if (res.locals.isAPI) {
return res.json(403, 'not-allowed');
return res.json(403, 'not-allowed');
} else {
return res.redirect('403');
}
@ -41,6 +41,17 @@ middleware.updateLastOnlineTime = function(req, res, next) {
next();
};
middleware.redirectToAccountIfLoggedIn = function(req, res, next) {
if (req.user) {
user.getUserField(req.user.uid, 'userslug', function (err, userslug) {
res.redirect('/user/' + userslug);
});
} else {
next();
}
}
middleware.prepareAPI = function(req, res, next) {
res.locals.isAPI = true;
next();

@ -28,11 +28,11 @@ module.exports = function(app, middleware) {
app.get('/', middleware.buildHeader, controllers.home);
app.get('/api/home', controllers.home);
app.get('/login', middleware.buildHeader, controllers.login);
app.get('/api/login', controllers.login);
app.get('/login', middleware.redirectToAccountIfLoggedIn, middleware.buildHeader, controllers.login);
app.get('/api/login', middleware.redirectToAccountIfLoggedIn, controllers.login);
app.get('/register', middleware.buildHeader, controllers.register);
app.get('/api/register', controllers.register);
app.get('/register', middleware.redirectToAccountIfLoggedIn, middleware.buildHeader, controllers.register);
app.get('/api/register', middleware.redirectToAccountIfLoggedIn, controllers.register);
app.get('/confirm/:code', middleware.buildHeader, controllers.confirmEmail);
app.get('/api/confirm/:code', controllers.confirmEmail);

Loading…
Cancel
Save