]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blame - client/src/app/account/account.component.ts
Tags directory in gitignore
[github/Chocobozzz/PeerTube.git] / client / src / app / account / account.component.ts
CommitLineData
0f6da32b 1import { Validators } from '@angular/common';
629d8d6f 2import { Component, OnInit } from '@angular/core';
0f6da32b 3import { FormControl, FormGroup, REACTIVE_FORM_DIRECTIVES } from '@angular/forms';
629d8d6f
C
4import { Router } from '@angular/router';
5
6import { AccountService } from './account.service';
7
8@Component({
9 selector: 'my-account',
10 template: require('./account.component.html'),
0f6da32b
C
11 providers: [ AccountService ],
12 directives: [ REACTIVE_FORM_DIRECTIVES ]
629d8d6f
C
13})
14
15export class AccountComponent implements OnInit {
0f6da32b
C
16 newPassword = '';
17 newConfirmedPassword = '';
18 changePasswordForm: FormGroup;
629d8d6f
C
19 information: string = null;
20 error: string = null;
21
22 constructor(
23 private accountService: AccountService,
24 private router: Router
25 ) {}
26
27 ngOnInit() {
0f6da32b
C
28 this.changePasswordForm = new FormGroup({
29 'new-password': new FormControl('', [ <any>Validators.required, <any>Validators.minLength(6) ]),
30 'new-confirmed-password': new FormControl('', [ <any>Validators.required, <any>Validators.minLength(6) ]),
629d8d6f
C
31 });
32 }
33
0f6da32b 34 changePassword() {
629d8d6f
C
35 this.information = null;
36 this.error = null;
37
0f6da32b 38 if (this.newPassword !== this.newConfirmedPassword) {
629d8d6f
C
39 this.error = 'The new password and the confirmed password do not correspond.';
40 return;
41 }
42
0f6da32b 43 this.accountService.changePassword(this.newPassword).subscribe(
629d8d6f
C
44 ok => this.information = 'Password updated.',
45
46 err => this.error = err
47 );
48 }
49}