/** * @license * Copyright Akveo. All Rights Reserved. * Licensed under the MIT License. See License.txt in the project root for license information. */ import { Component, Inject } from '@angular/core'; import { Router } from '@angular/router'; import { NB_AUTH_OPTIONS_TOKEN } from '../../auth.options'; import { getDeepFromObject } from '../../helpers'; import { NbAuthResult, NbAuthService } from '../../services/auth.service'; @Component({ selector: 'nb-login', template: `

Sign In

Hello! Sign in with your username or email
Email is required! Email should be the real one!
Password is required! Password should contains from {{ getConfigValue('forms.validation.password.minLength') }} to {{ getConfigValue('forms.validation.password.maxLength') }} characters
Remember me Forgot Password?
`, }) export class NbLoginComponent { redirectDelay: number = 0; showMessages: any = {}; provider: string = ''; errors: string[] = []; messages: string[] = []; user: any = {}; submitted: boolean = false; constructor(protected service: NbAuthService, @Inject(NB_AUTH_OPTIONS_TOKEN) protected config = {}, protected router: Router) { this.redirectDelay = this.getConfigValue('forms.login.redirectDelay'); this.showMessages = this.getConfigValue('forms.login.showMessages'); this.provider = this.getConfigValue('forms.login.provider'); } login(): void { this.errors = this.messages = []; this.submitted = true; this.service.authenticate(this.provider, this.user).subscribe((result: NbAuthResult) => { this.submitted = false; if (result.isSuccess()) { this.messages = result.getMessages(); } else { this.errors = result.getErrors(); } const redirect = result.getRedirect(); if (redirect) { setTimeout(() => { return this.router.navigateByUrl(redirect); }, this.redirectDelay); } }); } getConfigValue(key: string): any { return getDeepFromObject(this.config, key, null); } }