Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- login(username: string, password: string): Observable<boolean> {
- var headers = new Headers({
- "Content-Type": "application/json",
- "Accept": "application/json"
- });
- let postData = {
- grant_type: "password",
- client_id: 2,
- client_secret: "RGNmOzt7WQ8SdNiCcJKKDoYrsFqI2tudopFjOJU3",
- username: "albanafmeti@gmail.com",
- password: "password",
- scope: ""
- }
- return this.http.post('http://localhost:8000/oauth/token', JSON.stringify(postData), {
- headers: headers
- })
- .map((response: Response) => {
- // login successful if there's a jwt token in the response
- let token = response.json() && response.json().token;
- if (token) {
- // set token property
- this.token = token;
- // store username and jwt token in local storage to keep user logged in between page refreshes
- localStorage.setItem('currentUser', JSON.stringify({ username: username, token: token }));
- // return true to indicate successful login
- return true;
- } else {
- // return false to indicate failed login
- return false;
- }
- });
- }
Add Comment
Please, Sign In to add comment