packages/data/src/lib/auth/password-reset/password-reset.component.ts
Form to send password reset request.
selector | ec-password-reset |
templateUrl | password-reset.component.html |
Properties |
|
Methods |
Inputs |
Outputs |
constructor(auth: AuthService, notifications: NotificationsService)
|
|||||||||
Parameters :
|
api | |
Type : PublicAPI
|
|
Optional api to be used (if not using sdk.api instance) |
placeholder | |
Default value : 'E-Mail Adresse...'
|
|
Custom placeholder for email field |
success | |
Type : EventEmitter<any>
|
|
Event after request was successful |
reset |
reset()
|
Sends request through AuthService and shows notifications + loader.
Returns :
void
|
Public auth |
Type : AuthService
|
Type : string
|
The user email |
loader |
Decorators :
@ViewChild(LoaderComponent, {static: true})
|
The loader |
lockForm |
Type : boolean
|
To ensure the user only sends one request, the form is locked after the request has been sent |
Public notifications |
Type : NotificationsService
|
import { Component, EventEmitter, Input, Output, ViewChild } from '@angular/core';
import PublicAPI from 'ec.sdk/lib/PublicAPI';
import { LoaderComponent, NotificationsService, WithLoader } from '@ec.components/ui';
import { AuthService } from '../auth.service';
/** Form to send password reset request.
* <example-url>https://components.entrecode.de/auth/password-reset?e=1</example-url>
*
*/
@Component({
selector: 'ec-password-reset',
templateUrl: 'password-reset.component.html',
})
export class PasswordResetComponent implements WithLoader {
/** To ensure the user only sends one request, the form is locked after the request has been sent */
lockForm: boolean;
/** The user email */
email: string;
/** Optional api to be used (if not using sdk.api instance) */
@Input() api: PublicAPI;
/** Custom placeholder for email field */
@Input() placeholder = 'E-Mail Adresse...';
/** Event after request was successful */
@Output() success: EventEmitter<any> = new EventEmitter();
/** The loader */
@ViewChild(LoaderComponent, { static: true }) loader;
constructor(public auth: AuthService, public notifications: NotificationsService) {}
/** Sends request through AuthService and shows notifications + loader. */
reset() {
const reset = this.auth
.resetPassword(this.email, this.api)
.then(() => {
this.notifications.emit({
type: 'success',
title: 'Mail versendet',
message: 'Sie haben soeben eine Mail mit weiteren Anweisungen erhalten',
sticky: true,
});
this.lockForm = true;
this.success.emit();
})
.catch((error) => {
this.notifications.emit({
title: 'Fehler beim Passwort zurücksetzen',
error,
sticky: true,
});
console.log('could not reset password', error);
});
this.loader.wait(reset);
}
}
<ec-loader class="ec-loader loader is-global"></ec-loader>
<div *ngIf="!lockForm" class="ec-auth ec-auth_reset">
<div class="field-group ec-auth__email">
<input class="input" type="email" [(ngModel)]="email" [placeholder]="placeholder" #emailInput />
</div>
<a class="btn ec-auth__btn" [class.is-disabled]="!emailInput.value" (click)="emailInput.value && reset()">
{{ 'passwordReset.button' | symbol }}
</a>
</div>