]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blob - client/src/app/account/account.component.ts
Dirty update to Angular RC6
[github/Chocobozzz/PeerTube.git] / client / src / app / account / account.component.ts
1 import { } from '@angular/common';
2 import { Component, OnInit } from '@angular/core';
3 import { FormControl, FormGroup, Validators } 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 })
12
13 export class AccountComponent implements OnInit {
14 newPassword = '';
15 newConfirmedPassword = '';
16 changePasswordForm: FormGroup;
17 information: string = null;
18 error: string = null;
19
20 constructor(
21 private accountService: AccountService,
22 private router: Router
23 ) {}
24
25 ngOnInit() {
26 this.changePasswordForm = new FormGroup({
27 'new-password': new FormControl('', [ <any>Validators.required, <any>Validators.minLength(6) ]),
28 'new-confirmed-password': new FormControl('', [ <any>Validators.required, <any>Validators.minLength(6) ]),
29 });
30 }
31
32 changePassword() {
33 this.information = null;
34 this.error = null;
35
36 if (this.newPassword !== this.newConfirmedPassword) {
37 this.error = 'The new password and the confirmed password do not correspond.';
38 return;
39 }
40
41 this.accountService.changePassword(this.newPassword).subscribe(
42 ok => this.information = 'Password updated.',
43
44 err => this.error = err
45 );
46 }
47 }