]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blame - client/src/app/+admin/users/user-edit/user-password.component.ts
Reorganize shared models
[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'
328c78bc 4import { I18n } from '@ngx-translate/i18n-polyfill'
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,
328c78bc 21 private userValidatorsService: UserValidatorsService,
b426edd4 22 private notifier: Notifier,
328c78bc
RK
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 })
328c78bc
RK
33 }
34
328c78bc
RK
35 formValidated () {
36 this.error = undefined
37
38 const userUpdate: UserUpdate = this.form.value
39
40 this.userService.updateUser(this.userId, userUpdate).subscribe(
41 () => {
b426edd4 42 this.notifier.success(
328c78bc
RK
43 this.i18n('Password changed for user {{username}}.', { username: this.username })
44 )
45 },
46
47 err => this.error = err.message
48 )
49 }
50
328c78bc
RK
51 togglePasswordVisibility () {
52 this.showPassword = !this.showPassword
53 }
54
55 getFormButtonTitle () {
56 return this.i18n('Update user password')
57 }
328c78bc 58}