Skip to content

Commit 68a6e68

Browse files
committed
Merge branch 'develop'
2 parents 5252289 + 8ed639a commit 68a6e68

File tree

7 files changed

+59
-8
lines changed

7 files changed

+59
-8
lines changed

bower.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
"authors": [
55
"Volodymyr Lavrynovych <volodyalavrynovych@gmail.com>"
66
],
7-
"version": "0.7.0",
7+
"version": "0.7.1",
88
"description": "Provides ability to easily handle most of the logic related to the authentication process and page load for the AngularJS SPA",
99
"main": "dist/angular-spa-auth.min.js",
1010
"keywords": [

dist/angular-spa-auth.js

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -151,8 +151,12 @@
151151
}
152152

153153
function goTo(route) {
154-
$location.path(route);
155-
info('Redirected to the ' + route);
154+
if(route == config.uiRoutes.login && service.isAuthenticated()) {
155+
$location.path(getHome());
156+
} else {
157+
$location.path(route);
158+
info('Redirected to the ' + route);
159+
}
156160
}
157161

158162
function isAuthenticated() {

dist/angular-spa-auth.min.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/angular-spa-auth.min.js.map

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "angular-spa-auth",
33
"title": "Angular SPA Auth",
4-
"version": "0.7.0",
4+
"version": "0.7.1",
55
"author": "Volodymyr Lavrynovych <volodyalavrynovych@gmail.com>",
66
"contributors": [
77
"Volodymyr Lavrynovych <volodyalavrynovych@gmail.com>"

src/angular-spa-auth.js

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -151,8 +151,12 @@
151151
}
152152

153153
function goTo(route) {
154-
$location.path(route);
155-
info('Redirected to the ' + route);
154+
if(route == config.uiRoutes.login && service.isAuthenticated()) {
155+
$location.path(getHome());
156+
} else {
157+
$location.path(route);
158+
info('Redirected to the ' + route);
159+
}
156160
}
157161

158162
function isAuthenticated() {

test/test.app.js

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ describe('angular-spa-auth', function () {
3131
it('User is not logged in on start', function () {
3232
//given:
3333
expect($rootScope.currentUser).toBeUndefined();
34+
events = [];
3435

3536
$rootScope.$on("$routeChangeStart", function(e) {
3637
e.path = $location.path();
@@ -118,6 +119,48 @@ describe('angular-spa-auth', function () {
118119
checkEvent(true);
119120
});
120121

122+
123+
it('Refresh when you are on the login page and login', function () {
124+
//given:
125+
expect($rootScope.currentUser).toBeUndefined();
126+
events = [];
127+
AuthService.config.uiRoutes.target = AuthService.config.uiRoutes.login;
128+
129+
$rootScope.$on("$routeChangeStart", function(e) {
130+
e.path = $location.path();
131+
e.i = events.length;
132+
events.push(e);
133+
});
134+
135+
//when: isAuthenticated method is triggered but we still do not know status of user
136+
changeRoute(AuthService.config.uiRoutes.login);
137+
138+
//then: login page is available
139+
expect($location.path()).toEqual(AuthService.config.uiRoutes.login);
140+
expect($rootScope.currentUser).toBeUndefined();
141+
checkEvent(false);
142+
143+
//when: trigger after init
144+
$httpBackend.flush();
145+
146+
//then: we are on login page and user is set to false, because we checked his authentication status
147+
expect($location.path()).toEqual(AuthService.config.uiRoutes.login);
148+
expect($rootScope.currentUser).toEqual(false);
149+
150+
//when: try to login using some credentials
151+
AuthService.login(credentials);
152+
$httpBackend.flush();
153+
154+
//then: successfully authenticated and redirected to the home page EVEN if the target is login
155+
expect($location.path()).toEqual(AuthService.config.uiRoutes.home);
156+
157+
//when: try again to go to the login page
158+
changeRoute(AuthService.config.uiRoutes.login);
159+
160+
//then: successfully authenticated and redirected to the home page EVEN if the target is login
161+
expect($location.path()).toEqual(AuthService.config.uiRoutes.home);
162+
});
163+
121164
function changeRoute(path) {
122165
$location.path(path);
123166
$rootScope.$broadcast("$routeChangeStart", {

0 commit comments

Comments
 (0)