1 import { Component, Input, OnInit } from '@angular/core'
2 import { Notifier } from '@app/core'
3 import { USER_PASSWORD_VALIDATOR } from '@app/shared/form-validators/user-validators'
4 import { FormReactive, FormReactiveService } from '@app/shared/shared-forms'
5 import { UserAdminService } from '@app/shared/shared-users'
6 import { UserUpdate } from '@shared/models'
9 selector: 'my-user-password',
10 templateUrl: './user-password.component.html',
11 styleUrls: [ './user-password.component.scss' ]
13 export class UserPasswordComponent extends FormReactive implements OnInit {
14 @Input() userId: number
15 @Input() username: string
21 protected formReactiveService: FormReactiveService,
22 private notifier: Notifier,
23 private userAdminService: UserAdminService
30 password: USER_PASSWORD_VALIDATOR
35 this.error = undefined
37 const userUpdate: UserUpdate = this.form.value
39 this.userAdminService.updateUser(this.userId, userUpdate)
41 next: () => this.notifier.success($localize`Password changed for user ${this.username}.`),
44 this.error = err.message
49 togglePasswordVisibility () {
50 this.showPassword = !this.showPassword
53 getFormButtonTitle () {
54 return $localize`Update user password`