-
Notifications
You must be signed in to change notification settings - Fork 59
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
better code formatting and indenting for chapter 8
- Loading branch information
Showing
5 changed files
with
101 additions
and
102 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
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 |
---|---|---|
|
@@ -2,39 +2,39 @@ import { Injectable, EventEmitter } from 'angular2/core'; | |
|
||
@Injectable() | ||
export default class AuthenticationService { | ||
userLoggedInStatus: EventEmitter<boolean>; | ||
userLoggedInStatus: EventEmitter<boolean>; | ||
|
||
constructor() { | ||
this.userLoggedInStatus = new EventEmitter(); | ||
} | ||
constructor() { | ||
this.userLoggedInStatus = new EventEmitter(); | ||
} | ||
|
||
login({ username, password }): Promise<boolean> { | ||
return new Promise(resolve => { | ||
let validCredentials: boolean = false; | ||
login({ username, password }): Promise<boolean> { | ||
return new Promise(resolve => { | ||
let validCredentials: boolean = false; | ||
|
||
// @NOTE: In a normal case scenario this check should | ||
// be performed against a web service, which would return | ||
// the session token upon validating the user successfully | ||
if (username === '[email protected]' && | ||
password === 'letmein') { | ||
validCredentials = true; | ||
window.sessionStorage.setItem('token', 'eyJhbGciOi'); | ||
} | ||
// @NOTE: In a normal case scenario this check should | ||
// be performed against a web service, which would return | ||
// the session token upon validating the user successfully | ||
if (username === '[email protected]' && | ||
password === 'letmein') { | ||
validCredentials = true; | ||
window.sessionStorage.setItem('token', 'eyJhbGciOi'); | ||
} | ||
|
||
this.userLoggedInStatus.emit(validCredentials); | ||
resolve(validCredentials); | ||
}); | ||
} | ||
this.userLoggedInStatus.emit(validCredentials); | ||
resolve(validCredentials); | ||
}); | ||
} | ||
|
||
logout(): Promise<boolean> { | ||
return new Promise(resolve => { | ||
window.sessionStorage.removeItem('token'); | ||
this.userLoggedInStatus.emit(false); | ||
resolve(true); | ||
}); | ||
} | ||
logout(): Promise<boolean> { | ||
return new Promise(resolve => { | ||
window.sessionStorage.removeItem('token'); | ||
this.userLoggedInStatus.emit(false); | ||
resolve(true); | ||
}); | ||
} | ||
|
||
static grantAccess(): boolean { | ||
return !!window.sessionStorage.getItem('token'); | ||
} | ||
static grantAccess(): boolean { | ||
return !!window.sessionStorage.getItem('token'); | ||
} | ||
} |
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