Ignore:
Timestamp:
10/30/20 02:04:06 (4 years ago)
Author:
Mile Jankuloski <mile.jankuloski@…>
Branches:
master
Children:
1f4846d
Parents:
6f203af
Message:

Auth guards and services, refactored components

File:
1 edited

Legend:

Unmodified
Added
Removed
  • Farmatiko/ClientApp/src/app/login/login.component.ts

    r6f203af r993189e  
    22import { FormGroup, FormControl, Validators } from '@angular/forms';
    33import { Router, ActivatedRoute } from '@angular/router';
    4 import { DataService } from '../shared/data.service';
     4import { first } from 'rxjs/operators';
     5import { AuthService } from '../shared/auth.service';
    56
    67@Component({
     
    1516  errorMessage: string;
    1617
    17   constructor(private dataService: DataService,private router: Router, private route: ActivatedRoute) {
     18  constructor(private authService: AuthService,private router: Router, private route: ActivatedRoute) {
    1819    this.loginForm = new FormGroup({
    1920      email: new FormControl('', [Validators.required, Validators.email]),
     
    2627
    2728  loginPharmacyHead() {
    28     this.dataService.loginPharmacyHead(this.email, this.passwd)
    29                 .subscribe((id: Number) => {
    30                   if(id) {
    31                     this.router.navigate(['/dashboard/' + id]);
    32                   }
    33                   else {
    34                     this.errorMessage = 'There was a problem signing in!';
    35                     console.log(this.errorMessage);
    36                   }
    37                 },
    38                 (err: any) => console.log(err));
     29    this.authService.login(this.email,this.passwd)
     30        .pipe(first())
     31        .subscribe((data) => {
     32            if(data) {
     33              this.router.navigate(['/dashboard']);
     34            }},
     35            (err: any) => {
     36                this.errorMessage = err.toString();
     37            });
     38    this.loginForm.reset();
    3939  }
    4040}
Note: See TracChangeset for help on using the changeset viewer.