-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add parameter to login method to allow dynamic redirect
An extra parameter on the `$auth.login` method allows redirect URLs to be determined in runtime.
- Loading branch information
1 parent
7385b25
commit 4f5d88f
Showing
6 changed files
with
138 additions
and
16 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -137,6 +137,29 @@ describe('$auth', function() { | |
// expect(angular.isFunction($auth.login)).toBe(true); | ||
}); | ||
|
||
it('should be able to call loign with a redirect parameter', function() { | ||
var token = 'eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJ1c2VyIjp7Il9pZCI6IjUzZjYxZTEwNmZjNjFhNmMxM2I1Mjc4ZCIsImVtYWlsIjoic2FoYXQ_QG1lLmNvbSIsIl9fdiI6MH0sImlhdCI6MTQwODgyMTA5MTY3NiwiZXhwIjoxNDA5NDI1ODkxNjc2fQ.0l-ql-ZVjHiILMcMegNb3bNqapt3TZwjHy_ieduioiQ'; | ||
var user = { | ||
email: '[email protected]', | ||
password: '1234' | ||
}; | ||
var redirect = '/new/path'; | ||
this.config.tokenRoot = 'tokenRoot'; | ||
this.config.loginUrl = '/auth/login'; | ||
var response = { | ||
tokenRoot: { | ||
token: token | ||
} | ||
}; | ||
|
||
this.$httpBackend.expectPOST('/auth/login').respond(response); | ||
|
||
this.$auth.login(user, redirect); | ||
|
||
this.$httpBackend.flush(); | ||
|
||
expect(this.$location.path()).toBe(redirect); | ||
}); | ||
}); | ||
|
||
describe('signup()', function() { | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -41,6 +41,30 @@ describe('satellizer.local', function() { | |
// }); | ||
// }); | ||
|
||
it('should redirect to the redirect parameter on successful login', function() { | ||
var token = 'eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJ1c2VyIjp7Il9pZCI6IjUzZjYxZTEwNmZjNjFhNmMxM2I1Mjc4ZCIsImVtYWlsIjoic2FoYXQ_QG1lLmNvbSIsIl9fdiI6MH0sImlhdCI6MTQwODgyMTA5MTY3NiwiZXhwIjoxNDA5NDI1ODkxNjc2fQ.0l-ql-ZVjHiILMcMegNb3bNqapt3TZwjHy_ieduioiQ'; | ||
var user = { | ||
email: '[email protected]', | ||
password: '1234' | ||
}; | ||
var redirect = '/new/path'; | ||
this.config.tokenRoot = 'tokenRoot'; | ||
this.config.loginUrl = '/auth/login'; | ||
var response = { | ||
tokenRoot: { | ||
access_token: token | ||
} | ||
}; | ||
|
||
this.$httpBackend.expectPOST('/auth/login').respond(response); | ||
|
||
this.local.login(user, redirect); | ||
|
||
this.$httpBackend.flush(); | ||
|
||
expect(this.$location.path()).toBe(redirect); | ||
}); | ||
|
||
it('should fail login with incorrect credentials', function() { | ||
var result = null; | ||
var user = { | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters