Skip to content
This repository was archived by the owner on Mar 4, 2025. It is now read-only.

Commit d556102

Browse files
author
Parth Shah
committed
#SUP-1225 and adding tests
1 parent ac0b65d commit d556102

File tree

2 files changed

+21
-21
lines changed

2 files changed

+21
-21
lines changed

app/account/login/login.controller.js

Lines changed: 4 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -10,26 +10,12 @@
1010
vm.passwordReset = false;
1111
vm.usernameExists = true;
1212

13-
var redirect = function() {
14-
// check if the user is already logged in
15-
if (TcAuthService.isAuthenticated()) {
16-
// make sure domain is topcoder | dev | qa
17-
var re = /(\w+\.)*topcoder(-\w+)*\.com/;
18-
if (re.test($stateParams.next)) {
19-
$log.debug('Redirecting: ' + $stateParams.next);
20-
window.location.href = decodeURIComponent($stateParams.next);
21-
} else {
22-
$state.go('dashboard');
23-
}
24-
}
25-
};
26-
2713
// Handling social login stuff
2814
if ($stateParams.userJWTToken) {
2915
// user logged in
3016
AuthTokenService.setV3Token($stateParams.userJWTToken);
3117
UserService.setUserIdentity($stateParams.userJWTToken);
32-
redirect();
18+
Helpers.redirectPostLogin($stateParams.next);
3319
}
3420

3521
if ($stateParams.status) {
@@ -48,11 +34,11 @@
4834
AuthTokenService.getTokenFromAuth0Code($stateParams.code).then(
4935
function(v3Token) {
5036
$log.debug('logged in using social');
51-
redirect();
37+
Helpers.redirectPostLogin($stateParams.next);
5238
}
5339
);
5440
}
55-
41+
5642
if ($stateParams.notifyReset) {
5743
NotificationService.inform('Your new password has been set. Please log in. If you have any trouble, please contact [email protected].');
5844
}
@@ -62,7 +48,7 @@
6248
function(data) {
6349
// success
6450
$log.debug('logged in');
65-
redirect();
51+
Helpers.redirectPostLogin($stateParams.next);
6652
},
6753
function(err) {
6854
// handle error

app/services/helpers.service.js

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,9 @@
33

44
angular.module('tc.services').factory('Helpers', Helpers);
55

6-
Helpers.$inject = ['$window', '$location'];
6+
Helpers.$inject = ['$window', '$location', '$state'];
77

8-
function Helpers($window, $location) {
8+
function Helpers($window, $location, $state) {
99
// TODO: Separate helpers by submodule
1010

1111
var service = {
@@ -16,7 +16,8 @@
1616
countCompleted: countCompleted,
1717
getParameterByName: getParameterByName,
1818
getPageTitle: getPageTitle,
19-
isEmail: isEmail
19+
isEmail: isEmail,
20+
redirectPostLogin: redirectPostLogin
2021
};
2122
return service;
2223

@@ -161,5 +162,18 @@
161162
var re = /^(([^<>()[\]\.,;:\s@\"]+(\.[^<>()[\]\.,;:\s@\"]+)*)|(\".+\"))@(([^<>()[\]\.,;:\s@\"]+\.)+[^<>()[\]\.,;:\s@\"]{2,})$/i;
162163
return re.test(value);
163164
}
165+
166+
function redirectPostLogin(nextParam) {
167+
// make sure domain is topcoder | dev | qa
168+
var re1 = /^(\w+\.)*topcoder(-\w+)*\.com/,
169+
re2 = /^\/\w+/;
170+
if (re1.test(nextParam)) {
171+
$window.location.href = decodeURIComponent(nextParam);
172+
} else if (re2.test(nextParam)) {
173+
$location.url(nextParam);
174+
} else {
175+
$state.go('dashboard');
176+
}
177+
}
164178
}
165179
})();

0 commit comments

Comments
 (0)