Skip to content
Permalink
Browse files

Redirect signin if authenticated

closes #3147
- added beforeModel redirect
- added test
  • Loading branch information...
sebgie committed Jul 1, 2014
1 parent 9214f25 commit ace2cc1673a602e90efef8d732dc7398705ca07b
Showing with 39 additions and 0 deletions.
  1. +5 −0 core/client/routes/signin.js
  2. +5 −0 core/test/functional/base.js
  3. +29 −0 core/test/functional/client/signin_test.js
@@ -3,6 +3,11 @@ import loadingIndicator from 'ghost/mixins/loading-indicator';

var SigninRoute = Ember.Route.extend(styleBody, loadingIndicator, {
classNames: ['ghost-login'],
beforeModel: function () {
if (this.get('session').isAuthenticated) {
this.transitionTo(Ember.SimpleAuth.routeAfterAuthentication);
}
},
actions: {
sessionAuthenticationFailed: function (error) {
this.notifications.showError(error.message);
@@ -87,6 +87,11 @@ screens = {
url: 'ghost/signin/',
selector: '.button-save'
},
'signin-authenticated': {
url: 'ghost/signin/',
//signin with authenticated user redirects to posts
selector: '#main-menu .content.active'
},
'signout': {
url: 'ghost/signout/',
linkSelector: '#user-menu li.usermenu-signout a',
@@ -146,6 +146,35 @@ CasperTest.begin('Can login to Ghost', 5, function suite(test) {
});
}, true);

CasperTest.begin('Authenticated user is redirected', 8, function suite(test) {
casper.thenOpenAndWaitForPageLoad('signin', function testTitleAndUrl() {
test.assertTitle('Ghost Admin', 'Ghost admin has no title');
test.assertUrlMatch(/ghost\/signin\/$/, 'Landed on the correct URL');
});

casper.waitForOpaque('.login-box', function then() {
this.fillAndSave('#login', user);
});

casper.wait(2000);

casper.waitForResource(/posts/, function testForDashboard() {
test.assertUrlMatch(/ghost\/\d+\/$/, 'Landed on the correct URL');
test.assertExists('#global-header', 'Global admin header is present');
test.assertExists('.manage', 'We\'re now on content');
}, function onTimeOut() {
test.fail('Failed to signin');
});

casper.thenOpenAndWaitForPageLoad('signin-authenticated', function testTitleAndUrl() {
test.assertUrlMatch(/ghost\/\d+\/$/, 'Landed on the correct URL');
test.assertExists('#global-header', 'Global admin header is present');
test.assertExists('.manage', 'We\'re now on content');
}, function onTimeOut() {
test.fail('Failed to redirect');
});
}, true);

// TODO: please uncomment when the validation problem is fixed (https://github.com/TryGhost/Ghost/issues/3120)
// CasperTest.begin('Ensure email field form validation', 3, function suite(test) {
// casper.thenOpenAndWaitForPageLoad('signin', function testTitleAndUrl() {

0 comments on commit ace2cc1

Please sign in to comment.
You can’t perform that action at this time.