]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blame - client/src/app/+admin/users/user-edit/user-password.component.ts
Migrate to $localize
[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
C
2import { Notifier, UserService } from '@app/core'
3import { FormReactive, FormValidatorService, UserValidatorsService } from '@app/shared/shared-forms'
67ed6552 4import { UserUpdate } from '@shared/models'
328c78bc
RK
5
6@Component({
7 selector: 'my-user-password',
8 templateUrl: './user-password.component.html',
9 styleUrls: [ './user-password.component.scss' ]
10})
b426edd4 11export class UserPasswordComponent extends FormReactive implements OnInit {
328c78bc 12 error: string
328c78bc
RK
13 username: string
14 showPassword = false
15
2c2baef6
RK
16 @Input() userId: number
17
328c78bc
RK
18 constructor (
19 protected formValidatorService: FormValidatorService,
328c78bc 20 private userValidatorsService: UserValidatorsService,
b426edd4 21 private notifier: Notifier,
66357162
C
22 private userService: UserService
23 ) {
328c78bc
RK
24 super()
25 }
26
27 ngOnInit () {
28 this.buildForm({
29 password: this.userValidatorsService.USER_PASSWORD
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}