]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blob - client/src/app/+admin/users/user-edit/user-password.component.ts
Migrate client to eslint
[github/Chocobozzz/PeerTube.git] / client / src / app / +admin / users / user-edit / user-password.component.ts
1 import { Component, Input, OnInit } from '@angular/core'
2 import { Notifier, UserService } from '@app/core'
3 import { USER_PASSWORD_VALIDATOR } from '@app/shared/form-validators/user-validators'
4 import { FormReactive, FormValidatorService } from '@app/shared/shared-forms'
5 import { UserUpdate } from '@shared/models'
6
7 @Component({
8 selector: 'my-user-password',
9 templateUrl: './user-password.component.html',
10 styleUrls: [ './user-password.component.scss' ]
11 })
12 export class UserPasswordComponent extends FormReactive implements OnInit {
13 error: string
14 username: string
15 showPassword = false
16
17 @Input() userId: number
18
19 constructor (
20 protected formValidatorService: FormValidatorService,
21 private notifier: Notifier,
22 private userService: UserService
23 ) {
24 super()
25 }
26
27 ngOnInit () {
28 this.buildForm({
29 password: USER_PASSWORD_VALIDATOR
30 })
31 }
32
33 formValidated () {
34 this.error = undefined
35
36 const userUpdate: UserUpdate = this.form.value
37
38 this.userService.updateUser(this.userId, userUpdate)
39 .subscribe({
40 next: () => this.notifier.success($localize`Password changed for user ${this.username}.`),
41
42 error: err => {
43 this.error = err.message
44 }
45 })
46 }
47
48 togglePasswordVisibility () {
49 this.showPassword = !this.showPassword
50 }
51
52 getFormButtonTitle () {
53 return $localize`Update user password`
54 }
55 }