1 import { Component } from '@angular/core'
2 import { AuthService, Notifier, RedirectService, ServerService } from '@app/core'
3 import { UserService, UserValidatorsService } from '@app/shared'
4 import { I18n } from '@ngx-translate/i18n-polyfill'
5 import { UserRegister } from '@shared/models/users/user-register.model'
6 import { FormGroup } from '@angular/forms'
9 selector: 'my-register',
10 templateUrl: './register.component.html',
11 styleUrls: [ './register.component.scss' ]
13 export class RegisterComponent {
16 success: string = null
19 formStepUser: FormGroup
20 formStepChannel: FormGroup
23 private authService: AuthService,
24 private userValidatorsService: UserValidatorsService,
25 private notifier: Notifier,
26 private userService: UserService,
27 private serverService: ServerService,
28 private redirectService: RedirectService,
33 get requiresEmailVerification () {
34 return this.serverService.getConfig().signup.requiresEmailVerification
37 hasSameChannelAndAccountNames () {
38 return this.getUsername() === this.getChannelName()
42 if (!this.formStepUser) return undefined
44 return this.formStepUser.value['username']
48 if (!this.formStepChannel) return undefined
50 return this.formStepChannel.value['name']
53 onUserFormBuilt (form: FormGroup) {
54 this.formStepUser = form
57 onChannelFormBuilt (form: FormGroup) {
58 this.formStepChannel = form
64 const body: UserRegister = Object.assign(this.formStepUser.value, { channel: this.formStepChannel.value })
66 this.userService.signup(body).subscribe(
68 this.signupDone = true
70 if (this.requiresEmailVerification) {
71 this.info = this.i18n('Now please check your emails to verify your account and complete signup.')
76 this.authService.login(body.username, body.password)
79 this.success = this.i18n('You are now logged in as {{username}}!', { username: body.username })
82 err => this.error = err.message
86 err => this.error = err.message