This commit is contained in:
psychobunny
2014-09-17 00:41:19 -04:00
parent ca7f35dd5e
commit a6089ba4aa
2 changed files with 11 additions and 2 deletions

View File

@@ -77,6 +77,15 @@ middleware.redirectToAccountIfLoggedIn = function(req, res, next) {
}
};
middleware.redirectToLoginIfGuest = function(req, res, next) {
if (!req.user || parseInt(req.user.uid, 10) === 0) {
req.session.returnTo = req.url;
return res.redirect('/login');
} else {
next();
}
};
middleware.addSlug = function(req, res, next) {
function redirect(method, id, name) {
method(id, 'slug', function(err, slug) {

View File

@@ -117,8 +117,8 @@ function accountRoutes(app, middleware, controllers) {
app.get('/notifications', middleware.buildHeader, middleware.authenticate, controllers.accounts.getNotifications);
app.get('/api/notifications', middleware.authenticate, controllers.accounts.getNotifications);
app.get('/chats/:userslug?', middleware.buildHeader, middleware.authenticate, controllers.accounts.getChats);
app.get('/api/chats/:userslug?', middleware.authenticate, controllers.accounts.getChats);
app.get('/chats/:userslug?', middleware.buildHeader, middleware.redirectToLoginIfGuest, controllers.accounts.getChats);
app.get('/api/chats/:userslug?', middleware.redirectToLoginIfGuest, controllers.accounts.getChats);
}
function userRoutes(app, middleware, controllers) {