]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blame - client/src/app/+admin/users/user-edit/user-password.component.ts
Merge branch 'release/3.2.0' into develop
[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
C
22 private userService: UserService
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
38 this.userService.updateUser(this.userId, userUpdate).subscribe(
39 () => {
66357162 40 this.notifier.success($localize`Password changed for user ${this.username}.`)
328c78bc
RK
41 },
42
43 err => this.error = err.message
44 )
45 }
46
328c78bc
RK
47 togglePasswordVisibility () {
48 this.showPassword = !this.showPassword
49 }
50
51 getFormButtonTitle () {
66357162 52 return $localize`Update user password`
328c78bc 53 }
328c78bc 54}