From 9d6f2b81858d39767905a486877828e147ffd6da Mon Sep 17 00:00:00 2001 From: cobbspur Date: Thu, 12 Sep 2013 22:17:46 +0100 Subject: [PATCH] Redirects to signup if there is no user closes #653 - adds redirectToSignup function - if there is no user then /ghost/ and /ghost/signin/ redirect to /ghost/signup/ --- core/test/functional/admin/01_login_test.js | 2 +- index.js | 14 ++++++++++++-- 2 files changed, 13 insertions(+), 3 deletions(-) diff --git a/core/test/functional/admin/01_login_test.js b/core/test/functional/admin/01_login_test.js index 6975f65e7c..620d3b79e2 100644 --- a/core/test/functional/admin/01_login_test.js +++ b/core/test/functional/admin/01_login_test.js @@ -4,7 +4,7 @@ casper.test.begin('Ensure Session is Killed', 1, function suite(test) { test.filename = 'login_logout_test.png'; casper.start(url + 'logout/', function (response) { - test.assertUrlMatch(/ghost\/signin/, 'We got redirected to signin page'); + test.assertUrlMatch(/ghost\/sign/, 'We got redirected to signin or signup page'); }); casper.run(function () { diff --git a/index.js b/index.js index 240f501db8..42770aaca4 100644 --- a/index.js +++ b/index.js @@ -64,6 +64,16 @@ function redirectToIndex(req, res, next) { next(); } +function redirectToSignup(req, res, next) { + api.users.browse().then(function (users) { + if (users.length === 0) { + return res.redirect('/ghost/signup/'); + } + }); + + next(); +} + // While we're here, let's clean up on aisle 5 // That being ghost.notifications, and let's remove the passives from there // plus the local messages, as they have already been added at this point @@ -212,7 +222,7 @@ when.all([ghost.init(), helpers.loadCoreHelpers(ghost)]).then(function () { ghost.app().get('/ghost/login/', function redirect(req, res) { res.redirect(301, '/ghost/signin/'); }); - ghost.app().get('/ghost/signin/', redirectToIndex, admin.login); + ghost.app().get('/ghost/signin/', redirectToSignup, redirectToIndex, admin.login); ghost.app().get('/ghost/signup/', redirectToIndex, admin.signup); ghost.app().get('/ghost/forgotten/', redirectToIndex, admin.forgotten); ghost.app().post('/ghost/forgotten/', admin.resetPassword); @@ -231,7 +241,7 @@ when.all([ghost.init(), helpers.loadCoreHelpers(ghost)]).then(function () { ghost.app().get(/^\/(ghost$|(ghost-admin|admin|wp-admin|dashboard|signin)\/?)/, auth, function (req, res) { res.redirect('/ghost/'); }); - ghost.app().get('/ghost/', auth, admin.index); + ghost.app().get('/ghost/', redirectToSignup, auth, admin.index); // ### Frontend routes /* TODO: dynamic routing, homepage generator, filters ETC ETC */