2021-07-03 21:48:27 +00:00
|
|
|
import { Component, OnInit, AfterViewInit, ElementRef, ViewChild } from '@angular/core';
|
|
|
|
import { FormBuilder, Validators } from '@angular/forms';
|
|
|
|
import { ActivatedRoute } from '@angular/router';
|
|
|
|
|
|
|
|
import { PasswordResetFinishService } from './password-reset-finish.service';
|
|
|
|
|
|
|
|
@Component({
|
|
|
|
selector: 'jhi-password-reset-finish',
|
|
|
|
templateUrl: './password-reset-finish.component.html',
|
|
|
|
})
|
|
|
|
export class PasswordResetFinishComponent implements OnInit, AfterViewInit {
|
|
|
|
@ViewChild('newPassword', { static: false })
|
|
|
|
newPassword?: ElementRef;
|
|
|
|
|
|
|
|
initialized = false;
|
|
|
|
doNotMatch = false;
|
|
|
|
error = false;
|
|
|
|
success = false;
|
|
|
|
key = '';
|
|
|
|
|
|
|
|
passwordForm = this.fb.group({
|
2021-07-16 10:52:02 +00:00
|
|
|
newPassword: ['', [Validators.required, Validators.minLength(8), Validators.maxLength(50)]],
|
|
|
|
confirmPassword: ['', [Validators.required, Validators.minLength(8), Validators.maxLength(50)]],
|
2021-07-03 21:48:27 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
constructor(private passwordResetFinishService: PasswordResetFinishService, private route: ActivatedRoute, private fb: FormBuilder) {}
|
|
|
|
|
|
|
|
ngOnInit(): void {
|
|
|
|
this.route.queryParams.subscribe(params => {
|
|
|
|
if (params['key']) {
|
|
|
|
this.key = params['key'];
|
|
|
|
}
|
|
|
|
this.initialized = true;
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
ngAfterViewInit(): void {
|
|
|
|
if (this.newPassword) {
|
|
|
|
this.newPassword.nativeElement.focus();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
finishReset(): void {
|
|
|
|
this.doNotMatch = false;
|
|
|
|
this.error = false;
|
|
|
|
|
|
|
|
const newPassword = this.passwordForm.get(['newPassword'])!.value;
|
|
|
|
const confirmPassword = this.passwordForm.get(['confirmPassword'])!.value;
|
|
|
|
|
|
|
|
if (newPassword !== confirmPassword) {
|
|
|
|
this.doNotMatch = true;
|
|
|
|
} else {
|
|
|
|
this.passwordResetFinishService.save(this.key, newPassword).subscribe(
|
|
|
|
() => (this.success = true),
|
|
|
|
() => (this.error = true)
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|