Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- return this.http.post('http://151.80.40.137:1199/login',
- JSON.stringify({ user_login: username, user_password: password }))
- .map((response: Response) =>
- {
- // login successful if there's a jwt token in the response
- let token = response.json() && response.json().jwt.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
- this.router.navigate(this.redirectUrl ? [this.redirectUrl] : ['/home']);
- return true;
- } else {
- // return false to indicate failed login
- return false;
- }
- })
- .catch(err => {
- if (err.status === 401) {
- return "Unauthorized";
- }
- if (err.status === 404) {
- return "Service not working";
- });}
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement