import { Component, OnInit } from '@angular/core' import { FormControl, FormGroup, Validators } from '@angular/forms' import { Router } from '@angular/router' import { UikitAuthService } from '@bit/dapi.lib-uikit-auth.uikit-auth/dist/uikit-auth' import { PasswordService } from 'src/app/services/password/password.service' import { environment } from '../../../environments/environment' @Component({ selector: 'app-recovery-password', templateUrl: './recovery-password.component.html', styleUrls: ['./recovery-password.component.scss'], }) export class RecoveryPasswordComponent implements OnInit { recoverForm = new FormGroup({ user: new FormControl('', [ Validators.required, Validators.pattern('^[^\\s@]+@[^\\s@]+\\.[^\\s@]{2,}$'), ]), }) errorMessage = false constructor( private passwordService: PasswordService, private snackBarService: UikitAuthService, private router: Router, ) {} ngOnInit() {} recoverPass() { this.passwordService .resetPassword(this.recoverForm.controls.user.value) .then((response: string) => { this.snackBarService.openSnackBar( 'We have sent a link to your email to recovery your password.', ) this.router.navigate([''], { queryParams: { redirect_uri: environment.adminUrl }, }) }) .catch((err) => { this.snackBarService.openSnackBar( 'error' in err ? err.error : 'Error restoring the password.', ) }) } }