Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import { Component, OnInit } from '@angular/core';
- import { UserService } from './../user.service';
- import { CanActivate, Router, ActivatedRouteSnapshot, RouterStateSnapshot } from '@angular/router';
- import { HttpClient } from '@angular/common/http';
- @Component({
- selector: 'app-login',
- templateUrl: './login.component.html',
- styleUrls: ['./login.component.css']
- })
- export class LoginComponent implements OnInit {
- username: string = '';
- password: string = '';
- results: object;
- constructor(private userService: UserService, private router: Router, private http: HttpClient) { }
- ngOnInit() {
- if(this.userService.isValid()) {
- this.router.navigate(['home']);
- return;
- }
- }
- login() {
- var body = {
- email : this.username,
- password: this.password
- };
- console.log(body);
- this.http.post('http://127.0.0.1:8000/api/login', body).subscribe(data => {
- this.results = data;
- console.log(data);
- });
- // if(this.username=='admin' && this.password=='admin') {
- // window.localStorage.setItem("token", "123");
- // if(this.userService.isValid()) {
- // this.router.navigate(['home']);
- // } else {
- // this.router.navigate(['login']);
- // }
- // }
- // return;
- }
- }
- {
- "success":
- {
- "data":
- {
- "id":6,"name":"nthny20",
- "email":"nthny20@hotmail.com",
- "user_role_id":"1",
- "created_at":"2018-01-20 19:51:40",
- "updated_at":"2018-01-20 19:51:40",
- "token":"Bearer eyJ0eXAiOiJKV1Qi"
- }
- }
- }
Add Comment
Please, Sign In to add comment