]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blame - client/src/app/account/account-change-password/account-change-password.component.ts
Add user update for admins
[github/Chocobozzz/PeerTube.git] / client / src / app / account / account-change-password / account-change-password.component.ts
CommitLineData
df98563e
C
1import { Component, OnInit } from '@angular/core'
2import { FormBuilder, FormGroup } from '@angular/forms'
3import { Router } from '@angular/router'
af5e743b 4
df98563e 5import { NotificationsService } from 'angular2-notifications'
af5e743b 6
df98563e 7import { FormReactive, UserService, USER_PASSWORD } from '../../shared'
af5e743b
C
8
9@Component({
10 selector: 'my-account-change-password',
11 templateUrl: './account-change-password.component.html'
12})
13
14export class AccountChangePasswordComponent extends FormReactive implements OnInit {
df98563e 15 error: string = null
af5e743b 16
df98563e 17 form: FormGroup
af5e743b
C
18 formErrors = {
19 'new-password': '',
20 'new-confirmed-password': ''
df98563e 21 }
af5e743b
C
22 validationMessages = {
23 'new-password': USER_PASSWORD.MESSAGES,
24 'new-confirmed-password': USER_PASSWORD.MESSAGES
df98563e 25 }
af5e743b 26
df98563e 27 constructor (
af5e743b 28 private formBuilder: FormBuilder,
af5e743b
C
29 private notificationsService: NotificationsService,
30 private userService: UserService
31 ) {
df98563e 32 super()
af5e743b
C
33 }
34
df98563e 35 buildForm () {
af5e743b
C
36 this.form = this.formBuilder.group({
37 'new-password': [ '', USER_PASSWORD.VALIDATORS ],
df98563e
C
38 'new-confirmed-password': [ '', USER_PASSWORD.VALIDATORS ]
39 })
af5e743b 40
df98563e 41 this.form.valueChanges.subscribe(data => this.onValueChanged(data))
af5e743b
C
42 }
43
df98563e
C
44 ngOnInit () {
45 this.buildForm()
af5e743b
C
46 }
47
df98563e
C
48 changePassword () {
49 const newPassword = this.form.value['new-password']
50 const newConfirmedPassword = this.form.value['new-confirmed-password']
af5e743b 51
df98563e 52 this.error = null
af5e743b
C
53
54 if (newPassword !== newConfirmedPassword) {
df98563e
C
55 this.error = 'The new password and the confirmed password do not correspond.'
56 return
af5e743b
C
57 }
58
59 this.userService.changePassword(newPassword).subscribe(
60 () => this.notificationsService.success('Success', 'Password updated.'),
61
62 err => this.error = err
df98563e 63 )
af5e743b
C
64 }
65}