Guest User

Untitled

a guest
Jan 21st, 2018
589
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.57 KB | None | 0 0
  1. import { Component, OnInit } from '@angular/core';
  2. import { UserService } from './../user.service';
  3. import { CanActivate, Router, ActivatedRouteSnapshot, RouterStateSnapshot } from '@angular/router';
  4. import { HttpClient } from '@angular/common/http';
  5.  
  6.  
  7. @Component({
  8. selector: 'app-login',
  9. templateUrl: './login.component.html',
  10. styleUrls: ['./login.component.css']
  11. })
  12. export class LoginComponent implements OnInit {
  13.  
  14.  
  15. username: string = '';
  16. password: string = '';
  17.  
  18. results: object;
  19.  
  20. constructor(private userService: UserService, private router: Router, private http: HttpClient) { }
  21.  
  22. ngOnInit() {
  23.  
  24. if(this.userService.isValid()) {
  25. this.router.navigate(['home']);
  26. return;
  27. }
  28. }
  29.  
  30. login() {
  31.  
  32. var body = {
  33. email : this.username,
  34. password: this.password
  35. };
  36. console.log(body);
  37.  
  38.  
  39. this.http.post('http://127.0.0.1:8000/api/login', body).subscribe(data => {
  40. this.results = data;
  41.  
  42. console.log(data);
  43.  
  44. });
  45.  
  46.  
  47.  
  48.  
  49. // if(this.username=='admin' && this.password=='admin') {
  50. // window.localStorage.setItem("token", "123");
  51. // if(this.userService.isValid()) {
  52. // this.router.navigate(['home']);
  53.  
  54. // } else {
  55. // this.router.navigate(['login']);
  56. // }
  57. // }
  58. // return;
  59. }
  60.  
  61.  
  62.  
  63. }
  64.  
  65. {
  66. "success":
  67. {
  68. "data":
  69. {
  70. "id":6,"name":"nthny20",
  71. "email":"nthny20@hotmail.com",
  72. "user_role_id":"1",
  73. "created_at":"2018-01-20 19:51:40",
  74. "updated_at":"2018-01-20 19:51:40",
  75. "token":"Bearer eyJ0eXAiOiJKV1Qi"
  76. }
  77. }
  78. }
Add Comment
Please, Sign In to add comment