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