Skip to content

Commit

Permalink
Redirects to signup if there is no user
Browse files Browse the repository at this point in the history
closes TryGhost#653

- adds redirectToSignup function
- if there is no user then /ghost/ and /ghost/signin/ redirect to /ghost/signup/
  • Loading branch information
cobbspur committed Sep 12, 2013
1 parent 762dcb2 commit 9d6f2b8
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 3 deletions.
2 changes: 1 addition & 1 deletion core/test/functional/admin/01_login_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 () {
Expand Down
14 changes: 12 additions & 2 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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);
Expand All @@ -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 */
Expand Down

0 comments on commit 9d6f2b8

Please sign in to comment.