1 import { Component, OnInit, ViewChild } 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'
7 import { About } from '@shared/models/server'
8 import { InstanceService } from '@app/shared/instance/instance.service'
9 import { NgbAccordion } from '@ng-bootstrap/ng-bootstrap'
12 selector: 'my-register',
13 templateUrl: './register.component.html',
14 styleUrls: [ './register.component.scss' ]
16 export class RegisterComponent implements OnInit {
17 @ViewChild('accordion', { static: true }) accordion: NgbAccordion
21 success: string = null
29 moderationInformation: '',
33 formStepUser: FormGroup
34 formStepChannel: FormGroup
37 private authService: AuthService,
38 private userValidatorsService: UserValidatorsService,
39 private notifier: Notifier,
40 private userService: UserService,
41 private serverService: ServerService,
42 private redirectService: RedirectService,
43 private instanceService: InstanceService,
48 get requiresEmailVerification () {
49 return this.serverService.getConfig().signup.requiresEmailVerification
53 this.instanceService.getAbout()
58 this.aboutHtml = await this.instanceService.buildHtml(about)
61 err => this.notifier.error(err.message)
65 hasSameChannelAndAccountNames () {
66 return this.getUsername() === this.getChannelName()
70 if (!this.formStepUser) return undefined
72 return this.formStepUser.value['username']
76 if (!this.formStepChannel) return undefined
78 return this.formStepChannel.value['name']
81 onUserFormBuilt (form: FormGroup) {
82 this.formStepUser = form
85 onChannelFormBuilt (form: FormGroup) {
86 this.formStepChannel = form
90 if (this.accordion) this.accordion.toggle('terms')
93 onCodeOfConductClick () {
94 if (this.accordion) this.accordion.toggle('code-of-conduct')
100 const body: UserRegister = Object.assign(this.formStepUser.value, { channel: this.formStepChannel.value })
102 this.userService.signup(body).subscribe(
104 this.signupDone = true
106 if (this.requiresEmailVerification) {
107 this.info = this.i18n('Now please check your emails to verify your account and complete signup.')
112 this.authService.login(body.username, body.password)
115 this.success = this.i18n('You are now logged in as {{username}}!', { username: body.username })
118 err => this.error = err.message
122 err => this.error = err.message