This repository has been archived by the owner on Dec 13, 2018. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 9
/
forgot-password.component.ts
76 lines (71 loc) · 2.54 KB
/
forgot-password.component.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
import { Component, OnInit, TemplateRef, Input } from '@angular/core';
import { Injectable } from '@angular/core';
import { Stormpath, ForgotPasswordFormModel, StormpathErrorResponse } from '../stormpath/stormpath.service';
@Component({
selector: 'forgot-password-form',
template: `<ng-template #defaultTemplate>
<div class="row">
<div class="col-xs-12">
<p *ngIf="sent" class="alert alert-success">
We have sent a password reset link to the email address of the account that you specified.
Please check your email for this message, then click on the link.
</p>
</div>
</div>
<div class="row">
<div class="col-xs-12">
<form class="form-horizontal" *ngIf="!sent" #form="ngForm" (ngSubmit)="onSubmit(form.value)" autocomplete="off">
<div class="form-group">
<label for="spEmail" class="col-sm-3 control-label">Email</label>
<div class="col-sm-9">
<input class="form-control" name="email" type="email" id="spEmail" [(ngModel)]="forgotPasswordFormModel.email"
placeholder="Your Email Address" [disabled]="posting" required>
</div>
</div>
<div class="form-group">
<div class="col-sm-offset-3">
<p class="text-danger" *ngIf="error">{{error}}</p>
<button type="submit" class="btn btn-primary" [disabled]="posting">Request Password Reset</button>
</div>
</div>
</form>
</div>
</div>
</ng-template>
<ng-template
[ngTemplateOutlet]="customTemplate || defaultTemplate">
</ng-template>`
})
@Injectable()
export class ForgotPasswordComponent implements OnInit {
/**
* A reference to a `<ng-template>` tag that if set will override this component's template. Use like so:
* ```
* <ng-template #customTemplate>
* // custom HTML with login form
* </ng-template>
* ```
* Then pass customTemplate to the `forgot-password-form` component like so `[customTemplate]="customTemplate"`
*/
@Input() customTemplate: TemplateRef<any>;
protected forgotPasswordFormModel: ForgotPasswordFormModel;
protected error: string;
protected sent: boolean;
constructor(public stormpath: Stormpath) {
this.sent = false;
}
ngOnInit(): void {
this.forgotPasswordFormModel = {
email: ''
};
}
send(): void {
this.error = null;
this.stormpath.sendPasswordResetEmail(this.forgotPasswordFormModel)
.subscribe(() => this.sent = true,
(error: StormpathErrorResponse) => this.error = error.message);
}
onSubmit(form: any): void {
this.send();
}
}