Guest User

Untitled

a guest
Apr 28th, 2019
50
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.80 KB | None | 0 0
  1. public apiURL :string="http://localhost:56119";
  2. ValidateUser(userprofile: any)
  3.  
  4. {
  5. var reqHeader = new HttpHeaders({
  6. 'Content-Type': 'application/x-www-form-urlencoded',
  7. });
  8. var userData = "username=" + userprofile.Email + "&password=" + userprofile.Password + "&grant_type=password";
  9.  
  10. return this.httpClient.post(this.apiURL+'/token', userData, {
  11. headers: reqHeader
  12. })
  13. .pipe(
  14. map(res => res),catchError(this.errorHandler)
  15. );
  16. }
  17.  
  18. errorHandler(error: Response) {
  19. console.log(error);
  20. return throwError(error);
  21. }
  22. public isAuthenticated():boolean{
  23. return this.getToken()!==null;
  24. }
  25.  
  26. storeToken(token:string){
  27. localStorage.setItem('token',token);
  28. }
  29. getToken(){
  30. return localStorage.getItem('token');
  31. }
  32. removeToken(){
  33. return localStorage.removeItem('token');
  34. }
Add Comment
Please, Sign In to add comment