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