Advertisement
Guest User

Untitled

a guest
Jun 12th, 2017
84
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. return this.http.post('http://151.80.40.137:1199/login',
  2.   JSON.stringify({ user_login: username, user_password: password }))
  3.         .map((response: Response) =>
  4.         {
  5.             // login successful if there's a jwt token in the response
  6.             let token = response.json() && response.json().jwt.token;
  7.             if (token) {
  8.                 // set token property
  9.                 this.token = token;
  10.  
  11.                 // store username and jwt token in local storage to keep user logged in between page refreshes
  12.                 localStorage.setItem('currentUser', JSON.stringify({ username: username, token: token }));
  13.  
  14.                 // return true to indicate successful login
  15.  
  16.                 this.router.navigate(this.redirectUrl ? [this.redirectUrl] : ['/home']);
  17.                 return true;
  18.  
  19.             } else {
  20.                 // return false to indicate failed login
  21.  
  22.                 return  false;
  23.             }
  24.         })
  25.         .catch(err => {
  26.          if (err.status === 401) {
  27.              return "Unauthorized";
  28.            }
  29.            if (err.status === 404) {
  30.                return "Service not working";
  31.              
  32.       });}
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement