]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blame - client/src/app/account/account.component.ts
Server: assert remoteId and host pair is unique
[github/Chocobozzz/PeerTube.git] / client / src / app / account / account.component.ts
CommitLineData
ab32b0fc 1import { } from '@angular/common';
629d8d6f 2import { Component, OnInit } from '@angular/core';
4b2f33f3 3import { FormBuilder, FormGroup } from '@angular/forms';
629d8d6f
C
4import { Router } from '@angular/router';
5
6import { AccountService } from './account.service';
4b2f33f3 7import { FormReactive, USER_PASSWORD } from '../shared';
629d8d6f
C
8
9@Component({
10 selector: 'my-account',
ec8d8440 11 templateUrl: './account.component.html'
629d8d6f
C
12})
13
4b2f33f3 14export class AccountComponent extends FormReactive implements OnInit {
629d8d6f
C
15 information: string = null;
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
C
28 constructor(
29 private accountService: AccountService,
4b2f33f3 30 private formBuilder: FormBuilder,
629d8d6f 31 private router: Router
4b2f33f3
C
32 ) {
33 super();
34 }
629d8d6f 35
4b2f33f3
C
36 buildForm() {
37 this.form = this.formBuilder.group({
38 'new-password': [ '', USER_PASSWORD.VALIDATORS ],
39 'new-confirmed-password': [ '', USER_PASSWORD.VALIDATORS ],
629d8d6f 40 });
4b2f33f3
C
41
42 this.form.valueChanges.subscribe(data => this.onValueChanged(data));
43 }
44
45 ngOnInit() {
46 this.buildForm();
629d8d6f
C
47 }
48
0f6da32b 49 changePassword() {
4b2f33f3
C
50 const newPassword = this.form.value['new-password'];
51 const newConfirmedPassword = this.form.value['new-confirmed-password'];
52
629d8d6f
C
53 this.information = null;
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(
629d8d6f
C
62 ok => this.information = 'Password updated.',
63
64 err => this.error = err
65 );
66 }
67}