From ace2cc1673a602e90efef8d732dc7398705ca07b Mon Sep 17 00:00:00 2001 From: Sebastian Gierlinger Date: Tue, 1 Jul 2014 11:21:05 +0200 Subject: [PATCH] Redirect signin if authenticated closes #3147 - added beforeModel redirect - added test --- core/client/routes/signin.js | 5 ++++ core/test/functional/base.js | 5 ++++ core/test/functional/client/signin_test.js | 29 ++++++++++++++++++++++ 3 files changed, 39 insertions(+) diff --git a/core/client/routes/signin.js b/core/client/routes/signin.js index 535927e638..c06ffdf9b5 100644 --- a/core/client/routes/signin.js +++ b/core/client/routes/signin.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); diff --git a/core/test/functional/base.js b/core/test/functional/base.js index 1cc4009fe7..0fa8435992 100644 --- a/core/test/functional/base.js +++ b/core/test/functional/base.js @@ -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', diff --git a/core/test/functional/client/signin_test.js b/core/test/functional/client/signin_test.js index 8d2f4f9e72..687263ec4f 100644 --- a/core/test/functional/client/signin_test.js +++ b/core/test/functional/client/signin_test.js @@ -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() {