Skip to content

Commit 9b46aa5

Browse files
committed
Redirect to previous state after signup
1 parent a9af061 commit 9b46aa5

File tree

2 files changed

+15
-3
lines changed

2 files changed

+15
-3
lines changed

client/app/js/app.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -126,6 +126,12 @@ app.run(function(AuthService, annotationService, AUTH_EVENTS, $rootScope,
126126
}
127127
});
128128

129+
$rootScope.$on('$stateChangeSuccess', function(event, to, toParams, from, fromParams) {
130+
//save the previous state in a rootScope variable so that it's accessible from everywhere
131+
$rootScope.previousState = from;
132+
$rootScope.previousState.params = fromParams;
133+
});
134+
129135
//Check for 403 Errors ( Forbidden )
130136
$rootScope.$on(AUTH_EVENTS.notAuthorized, function () {
131137
growl.error('You are not authorized to view that page');

client/app/js/controllers/signupPageController.js

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
angular.module('madisonApp.controllers')
22
.controller('SignupPageController', ['$scope', '$state', 'AuthService',
3-
'growl', 'growlMessages', '$translate', 'pageService', 'SITE',
3+
'growl', 'growlMessages', '$translate', 'pageService', 'SITE', '$rootScope',
44
function ($scope, $state, AuthService, growl, growlMessages, $translate,
5-
pageService, SITE) {
5+
pageService, SITE, $rootScope) {
66
$translate('content.signup.title', {title: SITE.name}).then(function(translation) {
77
pageService.setTitle(translation);
88
});
@@ -15,7 +15,13 @@ angular.module('madisonApp.controllers')
1515
signup.success(function () {
1616
$scope.credentials = {fname: "", lname: "", email: "", password: ""};
1717
AuthService.getUser();
18-
$state.go('index');
18+
19+
if ($rootScope.previousState && $rootScope.previousState.name !== '') {
20+
$state.go($rootScope.previousState.name, $rootScope.previousState.params);
21+
} else {
22+
$state.go('index')
23+
}
24+
1925
growl.success($translate.instant('form.signup.success'));
2026
})
2127
.error(function (response) {

0 commit comments

Comments
 (0)