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