allow limiting video-comments rss feeds to an account or video channel
[oweals/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 { FormReactive, FormValidatorService, UserValidatorsService } from '@app/shared/shared-forms'
4 import { I18n } from '@ngx-translate/i18n-polyfill'
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 userValidatorsService: UserValidatorsService,
22     private notifier: Notifier,
23     private userService: UserService,
24     private i18n: I18n
25   ) {
26     super()
27   }
28
29   ngOnInit () {
30     this.buildForm({
31       password: this.userValidatorsService.USER_PASSWORD
32     })
33   }
34
35   formValidated () {
36     this.error = undefined
37
38     const userUpdate: UserUpdate = this.form.value
39
40     this.userService.updateUser(this.userId, userUpdate).subscribe(
41       () => {
42         this.notifier.success(
43           this.i18n('Password changed for user {{username}}.', { username: this.username })
44         )
45       },
46
47       err => this.error = err.message
48     )
49   }
50
51   togglePasswordVisibility () {
52     this.showPassword = !this.showPassword
53   }
54
55   getFormButtonTitle () {
56     return this.i18n('Update user password')
57   }
58 }