psychobunny 11 years ago
parent ca7f35dd5e
commit a6089ba4aa

@ -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) {

@ -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) {

Loading…
Cancel
Save