Guest User

Untitled

a guest
Mar 28th, 2018
84
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.25 KB | None | 0 0
  1. loginUser() {
  2. if(this.username == 'test' && this.password == 'test'){
  3. this.service.login().subscribe(userIsLoggedIn =>
  4. this.router.navigate(['admin/overview']));
  5. }
  6. }
  7.  
  8. {
  9. path: 'admin',
  10. component: AdminLoginComponent,
  11. data: {title: 'Admin'}
  12. },
  13. {
  14. path: 'admin/overview',
  15. component: AdminOverviewComponent,
  16. canActivate: [AuthGuard],
  17. data: {title: 'Overview'}
  18. }
  19.  
  20. @Injectable()
  21. export class AuthService {
  22. user: Observable<firebase.User>;
  23. constructor(private firebaseAuth: AngularFireAuth){
  24. this.user = firebaseAuth.authState;
  25. }
  26. isLoggedIn = false;
  27.  
  28. login(email: string, password: string): Observable<boolean> {
  29. this.firebaseAuth
  30. .auth
  31. .signInWithEmailAndPassword(email, password)
  32. .then(value => {
  33. return Observable.of(true).delay(1000).do(val => this.isLoggedIn = true);
  34. })
  35. .catch(err => {
  36. console.log('Something went wrong:',err.message);
  37. });
  38. return Observable.of(false).delay(1000).do(val => this.isLoggedIn = false);
  39. }
  40. }
  41.  
  42. constructor(private router: Router, private service: AuthService){}
  43. loginUser() {
  44. this.service.login(this.email, this.password).subscribe(userIsLoggedIn =>
  45. this.router.navigate(['admin/overview']));
  46. this.email = this.password = '';
  47. console.log('test');
  48. }
Add Comment
Please, Sign In to add comment