Skip to content

Commit ace2cc1

Browse files
committed
Redirect signin if authenticated
closes #3147 - added beforeModel redirect - added test
1 parent 9214f25 commit ace2cc1

File tree

3 files changed

+39
-0
lines changed

3 files changed

+39
-0
lines changed

core/client/routes/signin.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,11 @@ import loadingIndicator from 'ghost/mixins/loading-indicator';
33

44
var SigninRoute = Ember.Route.extend(styleBody, loadingIndicator, {
55
classNames: ['ghost-login'],
6+
beforeModel: function () {
7+
if (this.get('session').isAuthenticated) {
8+
this.transitionTo(Ember.SimpleAuth.routeAfterAuthentication);
9+
}
10+
},
611
actions: {
712
sessionAuthenticationFailed: function (error) {
813
this.notifications.showError(error.message);

core/test/functional/base.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,11 @@ screens = {
8787
url: 'ghost/signin/',
8888
selector: '.button-save'
8989
},
90+
'signin-authenticated': {
91+
url: 'ghost/signin/',
92+
//signin with authenticated user redirects to posts
93+
selector: '#main-menu .content.active'
94+
},
9095
'signout': {
9196
url: 'ghost/signout/',
9297
linkSelector: '#user-menu li.usermenu-signout a',

core/test/functional/client/signin_test.js

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -146,6 +146,35 @@ CasperTest.begin('Can login to Ghost', 5, function suite(test) {
146146
});
147147
}, true);
148148

149+
CasperTest.begin('Authenticated user is redirected', 8, function suite(test) {
150+
casper.thenOpenAndWaitForPageLoad('signin', function testTitleAndUrl() {
151+
test.assertTitle('Ghost Admin', 'Ghost admin has no title');
152+
test.assertUrlMatch(/ghost\/signin\/$/, 'Landed on the correct URL');
153+
});
154+
155+
casper.waitForOpaque('.login-box', function then() {
156+
this.fillAndSave('#login', user);
157+
});
158+
159+
casper.wait(2000);
160+
161+
casper.waitForResource(/posts/, function testForDashboard() {
162+
test.assertUrlMatch(/ghost\/\d+\/$/, 'Landed on the correct URL');
163+
test.assertExists('#global-header', 'Global admin header is present');
164+
test.assertExists('.manage', 'We\'re now on content');
165+
}, function onTimeOut() {
166+
test.fail('Failed to signin');
167+
});
168+
169+
casper.thenOpenAndWaitForPageLoad('signin-authenticated', function testTitleAndUrl() {
170+
test.assertUrlMatch(/ghost\/\d+\/$/, 'Landed on the correct URL');
171+
test.assertExists('#global-header', 'Global admin header is present');
172+
test.assertExists('.manage', 'We\'re now on content');
173+
}, function onTimeOut() {
174+
test.fail('Failed to redirect');
175+
});
176+
}, true);
177+
149178
// TODO: please uncomment when the validation problem is fixed (https://github.com/TryGhost/Ghost/issues/3120)
150179
// CasperTest.begin('Ensure email field form validation', 3, function suite(test) {
151180
// casper.thenOpenAndWaitForPageLoad('signin', function testTitleAndUrl() {

0 commit comments

Comments
 (0)