-
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.
Chapter 9 upgraded to RC.1. References to angular-upgrade remvoed
- Loading branch information
Showing
20 changed files
with
85 additions
and
51 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 |
---|---|---|
@@ -1,5 +1,6 @@ | ||
import 'rxjs/add/operator/map'; | ||
import { bootstrap } from 'angular2/platform/browser'; | ||
|
||
import { bootstrap } from '@angular/platform-browser-dynamic'; | ||
import AppComponent from './app.component'; | ||
|
||
bootstrap(AppComponent, []) |
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
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 |
---|---|---|
@@ -1,10 +1,12 @@ | ||
import { Injectable, EventEmitter } from 'angular2/core'; | ||
import { Injectable, EventEmitter } from '@angular/core'; | ||
import { Http, Response, Headers, RequestOptions } from '@angular/http'; | ||
import 'rxjs/add/operator/map'; | ||
|
||
@Injectable() | ||
export default class AuthenticationService { | ||
userIsloggedIn: EventEmitter<boolean>; | ||
|
||
constructor() { | ||
constructor(public http: Http) { | ||
this.userIsloggedIn = new EventEmitter(); | ||
} | ||
|
||
|
@@ -15,6 +17,7 @@ export default class AuthenticationService { | |
// @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 | ||
// Please refer to {@link httpLogin()}. | ||
if (username === '[email protected]' && | ||
password === 'letmein') { | ||
validCredentials = true; | ||
|
@@ -26,6 +29,32 @@ export default class AuthenticationService { | |
}); | ||
} | ||
|
||
httpLogin(credentials): Promise<boolean> { | ||
return new Promise(resolve => { | ||
|
||
const url = '/api/authentication'; // Or your own API Auth url | ||
const body = JSON.stringify(credentials); | ||
const headers = new Headers({ 'Content-Type': 'application/json' }); | ||
const options = new RequestOptions({ headers: headers }); | ||
|
||
this.http.post(url, body, options) | ||
.map(response => response.json()) | ||
.subscribe(authResponse => { | ||
let validCredentials: boolean = false; | ||
|
||
if(authResponse && authResponse.token) { | ||
validCredentials = true; | ||
window.sessionStorage.setItem('token', authResponse.token); | ||
} | ||
|
||
this.userIsloggedIn.emit(validCredentials); | ||
resolve(validCredentials); | ||
}, | ||
error => console.log(error) | ||
); | ||
}); | ||
} | ||
|
||
logout(): Promise<boolean> { | ||
return new Promise(resolve => { | ||
window.sessionStorage.removeItem('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
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
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
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 |
---|---|---|
@@ -1,5 +1,5 @@ | ||
{ | ||
"ambientDependencies": { | ||
"es6-shim": "github:DefinitelyTyped/DefinitelyTyped/es6-shim/es6-shim.d.ts#4de74cb527395c13ba20b438c3a7a419ad931f1c" | ||
"es6-shim": "registry:dt/es6-shim#0.31.2+20160317120654" | ||
} | ||
} |
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