1 import { Component, Input, OnInit } from '@angular/core'
2 import { ActivatedRoute, Router } from '@angular/router'
3 import { UserService } from '@app/shared/users/user.service'
4 import { Notifier } from '../../../core'
5 import { User, UserUpdate } from '../../../../../../shared'
6 import { I18n } from '@ngx-translate/i18n-polyfill'
7 import { FormValidatorService } from '@app/shared/forms/form-validators/form-validator.service'
8 import { UserValidatorsService } from '@app/shared/forms/form-validators/user-validators.service'
9 import { FormReactive } from '../../../shared'
12 selector: 'my-user-password',
13 templateUrl: './user-password.component.html',
14 styleUrls: [ './user-password.component.scss' ]
16 export class UserPasswordComponent extends FormReactive implements OnInit {
21 @Input() userId: number
24 protected formValidatorService: FormValidatorService,
25 private userValidatorsService: UserValidatorsService,
26 private route: ActivatedRoute,
27 private router: Router,
28 private notifier: Notifier,
29 private userService: UserService,
37 password: this.userValidatorsService.USER_PASSWORD
42 this.error = undefined
44 const userUpdate: UserUpdate = this.form.value
46 this.userService.updateUser(this.userId, userUpdate).subscribe(
48 this.notifier.success(
49 this.i18n('Password changed for user {{username}}.', { username: this.username })
53 err => this.error = err.message
57 togglePasswordVisibility () {
58 this.showPassword = !this.showPassword
61 getFormButtonTitle () {
62 return this.i18n('Update user password')