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 { HooksService } from '@app/core/plugins/hooks.service'
10 import { NgbAccordion } from '@ng-bootstrap/ng-bootstrap'
13 selector: 'my-register',
14 templateUrl: './register.component.html',
15 styleUrls: [ './register.component.scss' ]
17 export class RegisterComponent implements OnInit {
18 @ViewChild('accordion', { static: true }) accordion: NgbAccordion
22 success: string = null
30 moderationInformation: '',
34 formStepUser: FormGroup
35 formStepChannel: FormGroup
38 private authService: AuthService,
39 private userValidatorsService: UserValidatorsService,
40 private notifier: Notifier,
41 private userService: UserService,
42 private serverService: ServerService,
43 private redirectService: RedirectService,
44 private instanceService: InstanceService,
45 private hooks: HooksService,
50 get requiresEmailVerification () {
51 return this.serverService.getConfig().signup.requiresEmailVerification
55 this.instanceService.getAbout()
60 this.aboutHtml = await this.instanceService.buildHtml(about)
63 err => this.notifier.error(err.message)
66 this.hooks.runAction('action:signup.register.init', 'signup')
69 hasSameChannelAndAccountNames () {
70 return this.getUsername() === this.getChannelName()
74 if (!this.formStepUser) return undefined
76 return this.formStepUser.value['username']
80 if (!this.formStepChannel) return undefined
82 return this.formStepChannel.value['name']
85 onUserFormBuilt (form: FormGroup) {
86 this.formStepUser = form
89 onChannelFormBuilt (form: FormGroup) {
90 this.formStepChannel = form
94 if (this.accordion) this.accordion.toggle('terms')
97 onCodeOfConductClick () {
98 if (this.accordion) this.accordion.toggle('code-of-conduct')
104 const body: UserRegister = await this.hooks.wrapObject(
105 Object.assign(this.formStepUser.value, { channel: this.formStepChannel.value }),
106 'filter:api.signup.registration.create.params'
109 this.userService.signup(body).subscribe(
111 this.signupDone = true
113 if (this.requiresEmailVerification) {
114 this.info = this.i18n('Now please check your emails to verify your account and complete signup.')
119 this.authService.login(body.username, body.password)
122 this.success = this.i18n('You are now logged in as {{username}}!', { username: body.username })
125 err => this.error = err.message
129 err => this.error = err.message