]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blob - client/src/app/+admin/users/user-edit/user-password.component.ts
provide specific engine boundaries for nodejs and yarn
[github/Chocobozzz/PeerTube.git] / client / src / app / +admin / users / user-edit / user-password.component.ts
1 import { Component, Input, OnInit } from '@angular/core'
2 import { ActivatedRoute, Router } from '@angular/router'
3 import { UserService } from '@app/shared/users/user.service'
4 import { Notifier } from '../../../core'
5 import { User, UserUpdate } from '../../../../../../shared'
6 import { I18n } from '@ngx-translate/i18n-polyfill'
7 import { FormValidatorService } from '@app/shared/forms/form-validators/form-validator.service'
8 import { UserValidatorsService } from '@app/shared/forms/form-validators/user-validators.service'
9 import { FormReactive } from '../../../shared'
10
11 @Component({
12 selector: 'my-user-password',
13 templateUrl: './user-password.component.html',
14 styleUrls: [ './user-password.component.scss' ]
15 })
16 export class UserPasswordComponent extends FormReactive implements OnInit {
17 error: string
18 username: string
19 showPassword = false
20
21 @Input() userId: number
22
23 constructor (
24 protected formValidatorService: FormValidatorService,
25 private userValidatorsService: UserValidatorsService,
26 private notifier: Notifier,
27 private userService: UserService,
28 private i18n: I18n
29 ) {
30 super()
31 }
32
33 ngOnInit () {
34 this.buildForm({
35 password: this.userValidatorsService.USER_PASSWORD
36 })
37 }
38
39 formValidated () {
40 this.error = undefined
41
42 const userUpdate: UserUpdate = this.form.value
43
44 this.userService.updateUser(this.userId, userUpdate).subscribe(
45 () => {
46 this.notifier.success(
47 this.i18n('Password changed for user {{username}}.', { username: this.username })
48 )
49 },
50
51 err => this.error = err.message
52 )
53 }
54
55 togglePasswordVisibility () {
56 this.showPassword = !this.showPassword
57 }
58
59 getFormButtonTitle () {
60 return this.i18n('Update user password')
61 }
62 }