Advertisement
Guest User

Untitled

a guest
Aug 11th, 2016
78
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.96 KB | None | 0 0
  1. import {Component} from "@angular/core";
  2. import {LoginService} from "./login.service";
  3. import {Router} from "@angular/router";
  4.  
  5. @Component({
  6. selector: 'login',
  7. templateUrl: 'app/user/login.component.html'
  8. })
  9. export class LoginComponent {
  10.  
  11. username: string = 'admin';
  12. password: string = 'admin';
  13.  
  14. constructor(private userService: LoginService, private router: Router) { }
  15.  
  16. onLogin() {
  17. this.userService.login(this.username, this.password).subscribe((result) => {
  18. console.log("LOGIN: " +result);
  19. if(result) {
  20. console.log("YESI");
  21. this.router.navigate(['home']);
  22. }
  23. })
  24. }
  25.  
  26. onLogout() {
  27. this.userService.logout().subscribe((result) => {
  28. console.log("LOGOUT: " +result);
  29. if(!result) {
  30. console.log("YESO");
  31. this.router.navigate(['home']);
  32. }
  33. })
  34. }
  35.  
  36. isAuthenticated() {
  37. return !!this.userService.isLoggedIn();
  38. }
  39. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement