pw reset
This commit is contained in:
76
idp_client/src/app/auth/reset-pw/reset-pw.component.ts
Normal file
76
idp_client/src/app/auth/reset-pw/reset-pw.component.ts
Normal file
@@ -0,0 +1,76 @@
|
||||
import { HttpClient } from '@angular/common/http';
|
||||
import { Component, inject } from '@angular/core';
|
||||
import { FormControl, FormGroup, FormsModule, ReactiveFormsModule, Validators } from '@angular/forms';
|
||||
import { ActivatedRoute, Router } from '@angular/router';
|
||||
import { HotToastService } from '@ngxpert/hot-toast';
|
||||
|
||||
@Component({
|
||||
selector: 'app-reset-pw',
|
||||
standalone: true,
|
||||
imports: [FormsModule, ReactiveFormsModule],
|
||||
templateUrl: './reset-pw.component.html',
|
||||
styleUrl: '../auth.scss'
|
||||
})
|
||||
export class ResetPwComponent {
|
||||
private router = inject(Router);
|
||||
private http = inject(HttpClient);
|
||||
private route = inject(ActivatedRoute);
|
||||
private toast = inject(HotToastService);
|
||||
|
||||
isLoading = false;
|
||||
|
||||
resetCode;
|
||||
|
||||
resetPw = new FormGroup({
|
||||
username: new FormControl('', [Validators.required, Validators.email])
|
||||
})
|
||||
|
||||
setNewPwForm = new FormGroup({
|
||||
password: new FormControl(null, [Validators.required, Validators.minLength(4), Validators.maxLength(100)]),
|
||||
repeatPassword: new FormControl(null, [Validators.required, Validators.minLength(4), Validators.maxLength(100)]),
|
||||
code: new FormControl(null)
|
||||
})
|
||||
|
||||
ngOnInit(): void {
|
||||
this.resetCode = this.route.snapshot.queryParams["resetcode"];
|
||||
this.setNewPwForm.patchValue({code: this.resetCode});
|
||||
}
|
||||
|
||||
|
||||
resetPassword() {
|
||||
this.http.post('api/auth/reset', this.resetPw.value).subscribe({
|
||||
next: res => {
|
||||
console.log(res);
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
setNewPassword() {
|
||||
const val = this.setNewPwForm.value;
|
||||
if (val.password != val.repeatPassword) {
|
||||
this.toast.error('Die Passwörter stimmen nicht überein');
|
||||
return;
|
||||
}
|
||||
this.http.post('api/auth/reset', this.setNewPwForm.value)
|
||||
.pipe(
|
||||
this.toast.observe({
|
||||
loading: 'Setze neues Passwort',
|
||||
success: 'Passwort gespeichert',
|
||||
error: 'Passwort konnte nicht gespeichert werden!'
|
||||
})
|
||||
)
|
||||
.subscribe({
|
||||
next: res => {
|
||||
console.log(res);
|
||||
},
|
||||
complete: () => {
|
||||
this.router.navigateByUrl('/login');
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
toLogin() {
|
||||
this.router.navigateByUrl("/login");
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user