/** * @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-register', styleUrls: ['./register.component.scss'], template: `

Sign Up

Full name is required! Full name should contains from {{getConfigValue('forms.validation.password.minLength')}} to {{getConfigValue('forms.validation.password.maxLength')}} characters
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
Password confirmation is required! Password does not match the confirm password.
`, }) export class NbRegisterComponent { redirectDelay: number = 0; showMessages: any = {}; provider: string = ''; submitted = false; errors: string[] = []; messages: string[] = []; user: any = {}; constructor(protected service: NbAuthService, @Inject(NB_AUTH_OPTIONS_TOKEN) protected config = {}, protected router: Router) { this.redirectDelay = this.getConfigValue('forms.register.redirectDelay'); this.showMessages = this.getConfigValue('forms.register.showMessages'); this.provider = this.getConfigValue('forms.register.provider'); } register(): void { this.errors = this.messages = []; this.submitted = true; this.service.register(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); } }