1 import { Component, OnInit } from '@angular/core'
2 import { NotificationsService } from 'angular2-notifications'
3 import { UserCreate } from '../../../../shared'
4 import { FormReactive, UserService, UserValidatorsService } from '../shared'
5 import { RedirectService, ServerService } from '@app/core'
6 import { I18n } from '@ngx-translate/i18n-polyfill'
7 import { FormValidatorService } from '@app/shared/forms/form-validators/form-validator.service'
10 selector: 'my-signup',
11 templateUrl: './signup.component.html',
12 styleUrls: [ './signup.component.scss' ]
14 export class SignupComponent extends FormReactive implements OnInit {
18 protected formValidatorService: FormValidatorService,
19 private userValidatorsService: UserValidatorsService,
20 private notificationsService: NotificationsService,
21 private userService: UserService,
22 private serverService: ServerService,
23 private redirectService: RedirectService,
30 return window.location.host
33 get requiresEmailVerification () {
34 return this.serverService.getConfig().signup.requiresEmailVerification
39 username: this.userValidatorsService.USER_USERNAME,
40 password: this.userValidatorsService.USER_PASSWORD,
41 email: this.userValidatorsService.USER_EMAIL,
42 terms: this.userValidatorsService.USER_TERMS
49 const userCreate: UserCreate = this.form.value
51 this.userService.signup(userCreate).subscribe(
53 if (this.requiresEmailVerification) {
54 this.notificationsService.alert(
56 this.i18n('Please check your email to verify your account and complete signup.')
59 this.notificationsService.success(
61 this.i18n('Registration for {{username}} complete.', { username: userCreate.username })
64 this.redirectService.redirectToHomepage()
67 err => this.error = err.message