source: Farmatiko/ClientApp/src/app/login/login.component.ts@ 993189e

Last change on this file since 993189e was 993189e, checked in by Mile Jankuloski <mile.jankuloski@…>, 3 years ago

Auth guards and services, refactored components

  • Property mode set to 100644
File size: 1.2 KB
RevLine 
[785b8bd]1import { Component, OnInit } from '@angular/core';
[ee137aa]2import { FormGroup, FormControl, Validators } from '@angular/forms';
3import { Router, ActivatedRoute } from '@angular/router';
[993189e]4import { first } from 'rxjs/operators';
5import { AuthService } from '../shared/auth.service';
[785b8bd]6
7@Component({
8 selector: 'app-login',
9 templateUrl: './login.component.html',
10 styleUrls: ['./login.component.css']
11})
12export class LoginComponent implements OnInit {
13 loginForm: FormGroup;
[ee137aa]14 email: string;
15 passwd: string;
16 errorMessage: string;
[785b8bd]17
[993189e]18 constructor(private authService: AuthService,private router: Router, private route: ActivatedRoute) {
[785b8bd]19 this.loginForm = new FormGroup({
20 email: new FormControl('', [Validators.required, Validators.email]),
21 password: new FormControl('', [Validators.required])
22 });
23 }
24
25 ngOnInit(): void {
26 }
27
[ee137aa]28 loginPharmacyHead() {
[993189e]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();
[ee137aa]39 }
[785b8bd]40}
Note: See TracBrowser for help on using the repository browser.