Guest User

Untitled

a guest
Dec 11th, 2017
132
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.10 KB | None | 0 0
  1. export class LoginComponent{
  2. title = 'Login';
  3. email = '';
  4. password = '';
  5. credentials = '';
  6. basic = '';
  7. constructor(private http:HttpClient){
  8.  
  9. }
  10.  
  11. createAuthorizationHeader(headers:Headers,basic){
  12. headers.append('Authorization',basic);
  13. }
  14.  
  15. login(event){
  16. this.email = (<HTMLInputElement>document.getElementById("email")).value;
  17. this.password = (<HTMLInputElement>document.getElementById("password")).value;
  18. this.credentials = this.email + ":" + this.password;
  19. this.basic = "Basic " + btoa(this.credentials);
  20. console.log(this.basic);
  21. let headers = new Headers();
  22. headers.append('Content-Type','application/json');
  23. headers.append('Authorization',this.basic);
  24. let options = new RequestOptions({headers:headers});
  25. console.log(headers);
  26. return this.http.post('http://localhost:8000/api/v1/authenticate',options)
  27. .subscribe(
  28. res =>{
  29. console.log(res);
  30. },
  31. err => {
  32. console.log(err.message);
  33. }
  34. )
  35. }
  36. }
Add Comment
Please, Sign In to add comment