import { Component, OnInit } from '@angular/core'; import {FormBuilder, FormGroup, Validators} from '@angular/forms'; import {HRMNotificationService} from './app.notification.service'; import {AuthService} from './_services/auth/auth.service'; import {Router} from '@angular/router'; @Component({ selector: 'app-forgot-password', templateUrl: './forgot-password.component.html', styleUrls: ['./forgot-password.component.css'] }) export class ForgotPasswordComponent implements OnInit { forgotPasswordForm: FormGroup; employeeId = ''; emailAddress = ''; constructor(public notificationService: HRMNotificationService, public authService: AuthService, public router: Router) { } ngOnInit() { this.loadForm(); } loadForm() { this.forgotPasswordForm = new FormBuilder().group({ employeeId: ['', Validators.required], emailAddress: ['', Validators.required], }); } onSubmit() { if (!this.forgotPasswordForm.valid) { this.notificationService.showError('Please fill up the forms properly'); return; } const data = { employeeId: this.employeeId, emailAddress: this.emailAddress }; this.authService.forgotPassword(data).subscribe( () => {}, (err) => { console.log(err.error); this.notificationService.showError(err.error); }, () => { this.notificationService.showSuccess('Successfully sent password to your email address.'); localStorage.removeItem('forgotpass'); this.router.navigate(['/login']); } ); } onGoBack() { localStorage.removeItem('forgotpass'); this.router.navigate(['/login']); } }