diff --git a/server/controllers/routes.coffee b/server/controllers/routes.coffee index 08154ba6..dfadda9b 100644 --- a/server/controllers/routes.coffee +++ b/server/controllers/routes.coffee @@ -15,11 +15,11 @@ module.exports = 'routes/reset*': get: index.resetRoutes 'register': - get: auth.registerIndex + get: [utils.isNotAuthenticated, auth.registerIndex] post: [auth.register, utils.authenticate] 'login': - get: auth.loginIndex + get: [utils.isNotAuthenticated, auth.loginIndex] post: utils.authenticate 'login/forgot': post: auth.forgotPassword 'logout': get: [utils.isAuthenticated, auth.logout] diff --git a/server/middlewares/authentication.coffee b/server/middlewares/authentication.coffee index c02f1231..7c01df00 100644 --- a/server/middlewares/authentication.coffee +++ b/server/middlewares/authentication.coffee @@ -38,4 +38,8 @@ module.exports.isAuthenticated = (req, res, next) -> url += "&#{qs.stringify req.query}" if req.query.length res.redirect url - +module.exports.isNotAuthenticated = (req, res, next) -> + if req.isAuthenticated() + res.redirect '/' + else + next()