Skip to content

Commit

Permalink
Made login check for the NgJwtAuthCredentialsFailedException, removed…
Browse files Browse the repository at this point in the history
… the #_=_ facebook return hash
  • Loading branch information
zakhenry committed Aug 4, 2015
1 parent cb1a670 commit c3e724b
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 2 deletions.
2 changes: 1 addition & 1 deletion app/src/app/guest/login/login.spec.ts
Expand Up @@ -11,7 +11,7 @@ describe('Login', () => {

deferredCreds.promise.then(null, null, (creds) => {
if (creds.password == 'fail'){
deferred.notify(new NgJwtAuth.NgJwtAuthException('error'));
deferred.notify(new NgJwtAuth.NgJwtAuthCredentialsFailedException('error'));
}else{
deferred.resolve('success');
deferredCreds.resolve(creds);
Expand Down
4 changes: 3 additions & 1 deletion app/src/app/guest/login/login.ts
Expand Up @@ -103,14 +103,16 @@ module app.guest.login {
(user) => $mdDialog.hide(user), //on success hide the dialog, pass through the returned user object
null,
(err:Error) => {
if (err instanceof NgJwtAuth.NgJwtAuthException){
if (err instanceof NgJwtAuth.NgJwtAuthCredentialsFailedException){
this.$mdToast.show(
(<any>$mdToast).simple() //<any> added so the parent method doesn't throw error, see https://github.com/borisyankov/DefinitelyTyped/issues/4843#issuecomment-124443371
.hideDelay(2000)
.position('top')
.content(err.message)
.parent('#loginDialog')
);
}else{
console.error(err);
}
}
);
Expand Down
13 changes: 13 additions & 0 deletions app/src/common/services/authService.ts
Expand Up @@ -62,8 +62,10 @@ module common.services.auth {

private processQueryToken():ng.IPromise<any> {

this.removeFacebookHash();
let queryParams = this.$location.search();
if (queryParams.jwtAuthToken) {

let queryTokenPromise = this.ngJwtAuthService.processNewToken(queryParams.jwtAuthToken);

this.$location.search('jwtAuthToken', null);
Expand All @@ -75,6 +77,17 @@ module common.services.auth {

}

/**
* Removes the facebook return hash `#_=_`
*/
private removeFacebookHash():void {

if (this.$location.hash() == '_=_'){
this.$location.hash('');
}

}

private processPasswordResetToken():ng.IPromise<any> {

let queryParams = this.$location.search();
Expand Down

0 comments on commit c3e724b

Please sign in to comment.