Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- login(usn: string, psw: string): Observable<boolean> {
- let headers = new Headers({ 'Content-Type': 'application/json' });
- let options = new RequestOptions({ headers: headers });
- let body = JSON.stringify({ username: usn, password: psw });
- return this.http.post('http://localhost:5000/auth', body, options)
- .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: usn, token: token }));
- // return true to indicate successful login
- return true;
- } else {
- // return false to indicate failed login
- return false;
- }
- });
- }
- Request URL:http://localhost:5000/auth
- Request Method:OPTIONS
- Status Code:200 OK
- Remote Address:127.0.0.1:5000
- Response Headers
- view source
- Allow:POST, OPTIONS
- Content-Length:0
- Content-Type:text/html; charset=utf-8
- Date:Fri, 30 Dec 2016 22:40:57 GMT
- Server:Werkzeug/0.11.13 Python/3.5.2
- Request Headers
- view source
- Accept:*/*
- Accept-Encoding:gzip, deflate, sdch, br
- Accept-Language:en-US,en;q=0.8,es;q=0.6
- Access-Control-Request-Headers:content-type
- Access-Control-Request-Method:POST
- Connection:keep-alive
- Host:localhost:5000
- Origin:http://localhost:4200
- Referer:http://localhost:4200/
- User-Agent:Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/55.0.2883.87 Safari/537.36
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement