diff options
author | Chocobozzz <me@florianbigard.com> | 2018-01-30 13:27:07 +0100 |
---|---|---|
committer | Chocobozzz <me@florianbigard.com> | 2018-01-30 13:27:07 +0100 |
commit | ecb4e35f4e6c7304cb274593c13cb47fd5078b75 (patch) | |
tree | 1e238002340bc521afde59d52f406e41298a7aac /client/src/app/reset-password | |
parent | 80d1057bfcd3582af0dacf5ccd5a7a93ef95410b (diff) | |
download | PeerTube-ecb4e35f4e6c7304cb274593c13cb47fd5078b75.tar.gz PeerTube-ecb4e35f4e6c7304cb274593c13cb47fd5078b75.tar.zst PeerTube-ecb4e35f4e6c7304cb274593c13cb47fd5078b75.zip |
Add ability to reset our password
Diffstat (limited to 'client/src/app/reset-password')
6 files changed, 176 insertions, 0 deletions
diff --git a/client/src/app/reset-password/index.ts b/client/src/app/reset-password/index.ts new file mode 100644 index 000000000..438dc576a --- /dev/null +++ b/client/src/app/reset-password/index.ts | |||
@@ -0,0 +1,3 @@ | |||
1 | export * from './reset-password-routing.module' | ||
2 | export * from './reset-password.component' | ||
3 | export * from './reset-password.module' | ||
diff --git a/client/src/app/reset-password/reset-password-routing.module.ts b/client/src/app/reset-password/reset-password-routing.module.ts new file mode 100644 index 000000000..b41069568 --- /dev/null +++ b/client/src/app/reset-password/reset-password-routing.module.ts | |||
@@ -0,0 +1,25 @@ | |||
1 | import { NgModule } from '@angular/core' | ||
2 | import { RouterModule, Routes } from '@angular/router' | ||
3 | |||
4 | import { MetaGuard } from '@ngx-meta/core' | ||
5 | |||
6 | import { ResetPasswordComponent } from './reset-password.component' | ||
7 | |||
8 | const resetPasswordRoutes: Routes = [ | ||
9 | { | ||
10 | path: 'reset-password', | ||
11 | component: ResetPasswordComponent, | ||
12 | canActivate: [ MetaGuard ], | ||
13 | data: { | ||
14 | meta: { | ||
15 | title: 'Reset password' | ||
16 | } | ||
17 | } | ||
18 | } | ||
19 | ] | ||
20 | |||
21 | @NgModule({ | ||
22 | imports: [ RouterModule.forChild(resetPasswordRoutes) ], | ||
23 | exports: [ RouterModule ] | ||
24 | }) | ||
25 | export class ResetPasswordRoutingModule {} | ||
diff --git a/client/src/app/reset-password/reset-password.component.html b/client/src/app/reset-password/reset-password.component.html new file mode 100644 index 000000000..d142c523f --- /dev/null +++ b/client/src/app/reset-password/reset-password.component.html | |||
@@ -0,0 +1,33 @@ | |||
1 | <div class="margin-content"> | ||
2 | <div class="title-page title-page-single"> | ||
3 | Reset my password | ||
4 | </div> | ||
5 | |||
6 | <div *ngIf="error" class="alert alert-danger">{{ error }}</div> | ||
7 | |||
8 | <form role="form" (ngSubmit)="resetPassword()" [formGroup]="form"> | ||
9 | <div class="form-group"> | ||
10 | <label for="password">Password</label> | ||
11 | <input | ||
12 | type="password" name="password" id="password" placeholder="Password" required | ||
13 | formControlName="password" [ngClass]="{ 'input-error': formErrors['password'] }" | ||
14 | > | ||
15 | <div *ngIf="formErrors.password" class="form-error"> | ||
16 | {{ formErrors.password }} | ||
17 | </div> | ||
18 | </div> | ||
19 | |||
20 | <div class="form-group"> | ||
21 | <label for="password-confirm">Confirm password</label> | ||
22 | <input | ||
23 | type="password" name="password-confirm" id="password-confirm" placeholder="Confirmed password" required | ||
24 | formControlName="password-confirm" [ngClass]="{ 'input-error': formErrors['password-confirm'] }" | ||
25 | > | ||
26 | <div *ngIf="formErrors['password-confirm']" class="form-error"> | ||
27 | {{ formErrors['password-confirm'] }} | ||
28 | </div> | ||
29 | </div> | ||
30 | |||
31 | <input type="submit" value="Reset my password" [disabled]="!form.valid && isConfirmedPasswordValid()"> | ||
32 | </form> | ||
33 | </div> | ||
diff --git a/client/src/app/reset-password/reset-password.component.scss b/client/src/app/reset-password/reset-password.component.scss new file mode 100644 index 000000000..efec6b706 --- /dev/null +++ b/client/src/app/reset-password/reset-password.component.scss | |||
@@ -0,0 +1,12 @@ | |||
1 | @import '_variables'; | ||
2 | @import '_mixins'; | ||
3 | |||
4 | input:not([type=submit]) { | ||
5 | @include peertube-input-text(340px); | ||
6 | display: block; | ||
7 | } | ||
8 | |||
9 | input[type=submit] { | ||
10 | @include peertube-button; | ||
11 | @include orange-button; | ||
12 | } | ||
diff --git a/client/src/app/reset-password/reset-password.component.ts b/client/src/app/reset-password/reset-password.component.ts new file mode 100644 index 000000000..408374779 --- /dev/null +++ b/client/src/app/reset-password/reset-password.component.ts | |||
@@ -0,0 +1,79 @@ | |||
1 | import { Component, OnInit } from '@angular/core' | ||
2 | import { FormBuilder, FormGroup, Validators } from '@angular/forms' | ||
3 | import { ActivatedRoute, Router } from '@angular/router' | ||
4 | import { USER_PASSWORD, UserService } from '@app/shared' | ||
5 | import { NotificationsService } from 'angular2-notifications' | ||
6 | import { AuthService } from '../core' | ||
7 | import { FormReactive } from '../shared' | ||
8 | |||
9 | @Component({ | ||
10 | selector: 'my-login', | ||
11 | templateUrl: './reset-password.component.html', | ||
12 | styleUrls: [ './reset-password.component.scss' ] | ||
13 | }) | ||
14 | |||
15 | export class ResetPasswordComponent extends FormReactive implements OnInit { | ||
16 | form: FormGroup | ||
17 | formErrors = { | ||
18 | 'password': '', | ||
19 | 'password-confirm': '' | ||
20 | } | ||
21 | validationMessages = { | ||
22 | 'password': USER_PASSWORD.MESSAGES, | ||
23 | 'password-confirm': { | ||
24 | 'required': 'Confirmation of the password is required.' | ||
25 | } | ||
26 | } | ||
27 | |||
28 | private userId: number | ||
29 | private verificationString: string | ||
30 | |||
31 | constructor ( | ||
32 | private authService: AuthService, | ||
33 | private userService: UserService, | ||
34 | private notificationsService: NotificationsService, | ||
35 | private formBuilder: FormBuilder, | ||
36 | private router: Router, | ||
37 | private route: ActivatedRoute | ||
38 | ) { | ||
39 | super() | ||
40 | } | ||
41 | |||
42 | buildForm () { | ||
43 | this.form = this.formBuilder.group({ | ||
44 | password: [ '', USER_PASSWORD.VALIDATORS ], | ||
45 | 'password-confirm': [ '', Validators.required ] | ||
46 | }) | ||
47 | |||
48 | this.form.valueChanges.subscribe(data => this.onValueChanged(data)) | ||
49 | } | ||
50 | |||
51 | ngOnInit () { | ||
52 | this.buildForm() | ||
53 | |||
54 | this.userId = this.route.snapshot.queryParams['userId'] | ||
55 | this.verificationString = this.route.snapshot.queryParams['verificationString'] | ||
56 | |||
57 | if (!this.userId || !this.verificationString) { | ||
58 | this.notificationsService.error('Error', 'Unable to find user id or verification string.') | ||
59 | this.router.navigate([ '/' ]) | ||
60 | } | ||
61 | } | ||
62 | |||
63 | resetPassword () { | ||
64 | this.userService.resetPassword(this.userId, this.verificationString, this.form.value.password) | ||
65 | .subscribe( | ||
66 | () => { | ||
67 | this.notificationsService.success('Success', 'Your password has been successfully reset!') | ||
68 | this.router.navigate([ '/login' ]) | ||
69 | }, | ||
70 | |||
71 | err => this.notificationsService.error('Error', err.message) | ||
72 | ) | ||
73 | } | ||
74 | |||
75 | isConfirmedPasswordValid () { | ||
76 | const values = this.form.value | ||
77 | return values.password === values['password-confirm'] | ||
78 | } | ||
79 | } | ||
diff --git a/client/src/app/reset-password/reset-password.module.ts b/client/src/app/reset-password/reset-password.module.ts new file mode 100644 index 000000000..c2711981a --- /dev/null +++ b/client/src/app/reset-password/reset-password.module.ts | |||
@@ -0,0 +1,24 @@ | |||
1 | import { NgModule } from '@angular/core' | ||
2 | |||
3 | import { ResetPasswordRoutingModule } from './reset-password-routing.module' | ||
4 | import { ResetPasswordComponent } from './reset-password.component' | ||
5 | import { SharedModule } from '../shared' | ||
6 | |||
7 | @NgModule({ | ||
8 | imports: [ | ||
9 | ResetPasswordRoutingModule, | ||
10 | SharedModule | ||
11 | ], | ||
12 | |||
13 | declarations: [ | ||
14 | ResetPasswordComponent | ||
15 | ], | ||
16 | |||
17 | exports: [ | ||
18 | ResetPasswordComponent | ||
19 | ], | ||
20 | |||
21 | providers: [ | ||
22 | ] | ||
23 | }) | ||
24 | export class ResetPasswordModule { } | ||