Merge pull request #712 from cobbspur/redirecttosignup

Redirects to signup if there is no user
This commit is contained in:
Hannah Wolfe 2013-09-12 15:07:08 -07:00
commit c82ebb15d8
2 changed files with 13 additions and 3 deletions

View File

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

View File

@ -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 */