UNPKG

6.35 kBJavaScriptView Raw
1/**
2 * @license
3 * Copyright Akveo. All Rights Reserved.
4 * Licensed under the MIT License. See License.txt in the project root for license information.
5 */
6import { ChangeDetectionStrategy, ChangeDetectorRef, Component, Inject } from '@angular/core';
7import { Router } from '@angular/router';
8import { NB_AUTH_OPTIONS } from '../../auth.options';
9import { getDeepFromObject } from '../../helpers';
10import { NbAuthService } from '../../services/auth.service';
11export class NbResetPasswordComponent {
12 constructor(service, options = {}, cd, router) {
13 this.service = service;
14 this.options = options;
15 this.cd = cd;
16 this.router = router;
17 this.redirectDelay = 0;
18 this.showMessages = {};
19 this.strategy = '';
20 this.submitted = false;
21 this.errors = [];
22 this.messages = [];
23 this.user = {};
24 this.redirectDelay = this.getConfigValue('forms.resetPassword.redirectDelay');
25 this.showMessages = this.getConfigValue('forms.resetPassword.showMessages');
26 this.strategy = this.getConfigValue('forms.resetPassword.strategy');
27 }
28 resetPass() {
29 this.errors = this.messages = [];
30 this.submitted = true;
31 this.service.resetPassword(this.strategy, this.user).subscribe((result) => {
32 this.submitted = false;
33 if (result.isSuccess()) {
34 this.messages = result.getMessages();
35 }
36 else {
37 this.errors = result.getErrors();
38 }
39 const redirect = result.getRedirect();
40 if (redirect) {
41 setTimeout(() => {
42 return this.router.navigateByUrl(redirect);
43 }, this.redirectDelay);
44 }
45 this.cd.detectChanges();
46 });
47 }
48 getConfigValue(key) {
49 return getDeepFromObject(this.options, key, null);
50 }
51}
52NbResetPasswordComponent.decorators = [
53 { type: Component, args: [{
54 selector: 'nb-reset-password-page',
55 template: "<h1 id=\"title\" class=\"title\">Change password</h1>\n<p class=\"sub-title\">Please set a new password</p>\n\n<nb-alert *ngIf=\"showMessages.error && errors?.length && !submitted\" outline=\"danger\" role=\"alert\">\n <p class=\"alert-title\"><b>Oh snap!</b></p>\n <ul class=\"alert-message-list\">\n <li *ngFor=\"let error of errors\" class=\"alert-message\">{{ error }}</li>\n </ul>\n</nb-alert>\n\n<nb-alert *ngIf=\"showMessages.success && messages?.length && !submitted\" outline=\"success\" role=\"alert\">\n <p class=\"alert-title\"><b>Hooray!</b></p>\n <ul class=\"alert-message-list\">\n <li *ngFor=\"let message of messages\" class=\"alert-message\">{{ message }}</li>\n </ul>\n</nb-alert>\n\n<form (ngSubmit)=\"resetPass()\" #resetPassForm=\"ngForm\" aria-labelledby=\"title\">\n\n <div class=\"form-control-group\">\n <label class=\"label\" for=\"input-password\">New Password:</label>\n <input nbInput\n [(ngModel)]=\"user.password\"\n #password=\"ngModel\"\n type=\"password\"\n id=\"input-password\"\n name=\"password\"\n class=\"first\"\n placeholder=\"New Password\"\n autofocus\n fullWidth\n fieldSize=\"large\"\n [status]=\"password.dirty ? (password.invalid ? 'danger' : 'success') : 'basic'\"\n [required]=\"getConfigValue('forms.validation.password.required')\"\n [minlength]=\"getConfigValue('forms.validation.password.minLength')\"\n [maxlength]=\"getConfigValue('forms.validation.password.maxLength')\"\n [attr.aria-invalid]=\"password.invalid && password.touched ? true : null\">\n <ng-container *ngIf=\"password.invalid && password.touched\">\n <p class=\"caption status-danger\" *ngIf=\"password.errors?.required\">\n Password is required!\n </p>\n <p class=\"caption status-danger\" *ngIf=\"password.errors?.minlength || password.errors?.maxlength\">\n Password should contains\n from {{getConfigValue('forms.validation.password.minLength')}}\n to {{getConfigValue('forms.validation.password.maxLength')}}\n characters\n </p>\n </ng-container>\n </div>\n\n <div class=\"form-group\">\n <label class=\"label\" for=\"input-re-password\">Confirm Password:</label>\n <input nbInput\n [(ngModel)]=\"user.confirmPassword\"\n #rePass=\"ngModel\"\n id=\"input-re-password\"\n name=\"rePass\"\n type=\"password\"\n class=\"last\"\n placeholder=\"Confirm Password\"\n fullWidth\n fieldSize=\"large\"\n [status]=\"rePass.touched\n ? (rePass.invalid || password.value != rePass.value ? 'danger' : 'success')\n : 'basic'\"\n [required]=\"getConfigValue('forms.validation.password.required')\"\n [attr.aria-invalid]=\"rePass.invalid && rePass.touched ? true : null\">\n <ng-container *ngIf=\"rePass.touched\">\n <p class=\"caption status-danger\" *ngIf=\"rePass.invalid && rePass.errors?.required\">\n Password confirmation is required!\n </p>\n <p class=\"caption status-danger\" *ngIf=\"password.value != rePass.value && !rePass.errors?.required\">\n Password does not match the confirm password.\n </p>\n </ng-container>\n </div>\n\n <button nbButton\n status=\"primary\"\n fullWidth\n size=\"large\"\n [disabled]=\"submitted || !resetPassForm.valid\"\n [class.btn-pulse]=\"submitted\">\n Change password\n </button>\n</form>\n\n<section class=\"sign-in-or-up\" aria-label=\"Sign in or sign up\">\n <p><a class=\"text-link\" routerLink=\"../login\">Back to Log In</a></p>\n <p><a class=\"text-link\" routerLink=\"../register\">Register</a></p>\n</section>\n",
56 changeDetection: ChangeDetectionStrategy.OnPush,
57 styles: [":host .form-group:last-of-type{margin-bottom:3rem}\n"]
58 },] }
59];
60NbResetPasswordComponent.ctorParameters = () => [
61 { type: NbAuthService },
62 { type: undefined, decorators: [{ type: Inject, args: [NB_AUTH_OPTIONS,] }] },
63 { type: ChangeDetectorRef },
64 { type: Router }
65];
66//# sourceMappingURL=reset-password.component.js.map
\No newline at end of file