Started implementing user settings -> security -> password management

This commit is contained in:
2026-04-18 15:24:37 +02:00
parent 8afd4a81b0
commit 4eaaacac2c
20 changed files with 575 additions and 7 deletions

View File

@@ -0,0 +1,91 @@
import {Component, inject, signal} from '@angular/core';
import {ServiceManager} from '../../../../service-manager';
import {
AbstractControl,
FormControl,
FormGroup,
FormsModule,
ReactiveFormsModule,
ValidationErrors,
Validators
} from '@angular/forms';
import {TranslatePipe} from '@ngx-translate/core';
import {TuiBadge, TuiButtonLoading} from '@taiga-ui/kit';
import {
TuiButton,
TuiDialog,
TuiErrorComponent,
TuiIcon,
TuiInputDirective,
TuiLabel,
TuiTextfieldComponent
} from '@taiga-ui/core';
@Component({
selector: 'user-settings-security-password',
imports: [
FormsModule,
ReactiveFormsModule,
TranslatePipe,
TuiBadge,
TuiButton,
TuiButtonLoading,
TuiDialog,
TuiErrorComponent,
TuiIcon,
TuiInputDirective,
TuiLabel,
TuiTextfieldComponent
],
templateUrl: './password.html',
styleUrl: './password.scss',
})
export class Password {
serviceManager = inject(ServiceManager)
changePasswordDialogOpen = signal(false)
changePasswordRemoveMode = signal(false)
changePasswordPending = signal(false)
changePasswordForm = new FormGroup({
currentPassword: new FormControl(""),
newPassword: new FormControl(""),
newPasswordRepeat: new FormControl("")
}, {
validators: [(group) => this.chkPassMatch(group)]
})
openChangePasswordDialog(modeRemove: boolean) {
this.changePasswordDialogOpen.set(true)
this.changePasswordRemoveMode.set(modeRemove)
this.changePasswordForm.controls["currentPassword"].clearValidators()
this.changePasswordForm.controls["newPassword"].clearValidators()
this.changePasswordForm.controls["newPasswordRepeat"].clearValidators()
if (!modeRemove) {
this.changePasswordForm.controls["newPassword"].setValidators([Validators.required])
this.changePasswordForm.controls["newPasswordRepeat"].setValidators([Validators.required])
this.changePasswordForm.controls["newPassword"].updateValueAndValidity()
this.changePasswordForm.controls["newPasswordRepeat"].updateValueAndValidity()
}
this.changePasswordForm.controls["currentPassword"].setValidators([Validators.required])
this.changePasswordForm.controls["currentPassword"].updateValueAndValidity()
}
async changePassword(currentPassword: string | null, newPassword: string | null) {
this.changePasswordPending.set(true)
const service = this.serviceManager.currentSessionHandler
if (service) {
try {
await service.changePassword(newPassword ?? "", currentPassword ?? "")
} catch (e) {
this.changePasswordForm.controls["currentPassword"].setErrors({incorrect: true})
}
}
}
chkPassMatch(group: AbstractControl): ValidationErrors | null {
return this.changePasswordRemoveMode() ? null : group.value.newPassword == group.value.newPasswordRepeat
? null : {passMatchError: true};
}
}