【发布时间】:2020-02-13 06:58:44
【问题描述】:
我创建了一个表单,我想用它来重置密码。后端部分已经完成,在前端我认为必须发回验证令牌。你能告诉我这是如何工作的吗?
我的代码如下所示:
// login.service.ts
resetPassword(loginUser: Login) {
return this.http.post<any>(`${environment.baseUrl}/set-password`, loginUser, {
headers: new HttpHeaders({
'Content-Type': 'application/json'
})
}).pipe(map(data => data)); }
// reset-password.component.ts
submitNewPassword() {
this.submitted = true;
// stop here if form is invalid
if (this.rpForm.invalid) {
return;
}
const successText = 'Ihr Passwort wurde erfolgreich zurückgesetzt!';
const errorText = 'Ihr Passwort konnte nicht zurückgesetzt werden!';
this.rpAlertType = null;
this.rpMessage = null;
this.loginService.resetPassword(this.rpForm.value)
.subscribe(
data => {
console.log('Password will be set!', data);
this.submitted = false;
if (data.success) {
this.rpAlertType = 'success';
this.rpMessage = successText;
} else {
this.rpAlertType = 'error';
this.rpMessage = errorText;
}
},
error => {
this.submitted = false;
this.alertType = 'error';
this.rpMessage = errorText;
ngOnInit() {
// Reset password form
this.rpForm = this.formBuilder.group( {
password: ['', Validators.pattern('^(?=.*[0-9])(?=.*[!@#$%^&*])[a-zA-Z0-9!@#$%^&*]{8,}$')],
confirm_password: ['', Validators.required]
});
}
【问题讨论】:
标签: angular validation httprequest frontend token