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 { AuthService, 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 authService: AuthService,
22 private userValidatorsService: UserValidatorsService,
23 private notificationsService: NotificationsService,
24 private userService: UserService,
25 private serverService: ServerService,
26 private redirectService: RedirectService,
33 return window.location.host
36 get requiresEmailVerification () {
37 return this.serverService.getConfig().signup.requiresEmailVerification
42 username: this.userValidatorsService.USER_USERNAME,
43 password: this.userValidatorsService.USER_PASSWORD,
44 email: this.userValidatorsService.USER_EMAIL,
45 terms: this.userValidatorsService.USER_TERMS
52 const userCreate: UserCreate = this.form.value
54 this.userService.signup(userCreate).subscribe(
56 this.signupDone = true
58 if (this.requiresEmailVerification) {
59 this.info = this.i18n('Welcome! Now please check your emails to verify your account and complete signup.')
64 this.authService.login(userCreate.username, userCreate.password)
67 this.notificationsService.success(
69 this.i18n('You are now logged in as {{username}}!', { username: userCreate.username })
72 this.redirectService.redirectToHomepage()
75 err => this.error = err.message
79 err => this.error = err.message