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 {
20 protected formValidatorService: FormValidatorService,
21 private userValidatorsService: UserValidatorsService,
22 private notificationsService: NotificationsService,
23 private userService: UserService,
24 private serverService: ServerService,
25 private redirectService: RedirectService,
32 return window.location.host
35 get requiresEmailVerification () {
36 return this.serverService.getConfig().signup.requiresEmailVerification
41 username: this.userValidatorsService.USER_USERNAME,
42 password: this.userValidatorsService.USER_PASSWORD,
43 email: this.userValidatorsService.USER_EMAIL,
44 terms: this.userValidatorsService.USER_TERMS
51 const userCreate: UserCreate = this.form.value
53 this.userService.signup(userCreate).subscribe(
55 this.signupDone = true
57 if (this.requiresEmailVerification) {
58 this.info = this.i18n('Welcome! Now please check your emails to verify your account and complete signup.')
62 this.notificationsService.success(
64 this.i18n('Registration for {{username}} complete.', { username: userCreate.username })
66 this.redirectService.redirectToHomepage()
69 err => this.error = err.message