1 import { Component, OnInit, ViewChild } from '@angular/core'
2 import { FormGroup } from '@angular/forms'
3 import { ActivatedRoute } from '@angular/router'
4 import { AuthService, Notifier, UserService } from '@app/core'
5 import { HooksService } from '@app/core/plugins/hooks.service'
6 import { InstanceService } from '@app/shared/shared-instance'
7 import { NgbAccordion } from '@ng-bootstrap/ng-bootstrap'
8 import { UserRegister } from '@shared/models'
9 import { About, ServerConfig } from '@shared/models/server'
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
36 private serverConfig: ServerConfig
39 private route: ActivatedRoute,
40 private authService: AuthService,
41 private notifier: Notifier,
42 private userService: UserService,
43 private instanceService: InstanceService,
44 private hooks: HooksService
48 get requiresEmailVerification () {
49 return this.serverConfig.signup.requiresEmailVerification
53 this.serverConfig = this.route.snapshot.data.serverConfig
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 }),
107 'filter:api.signup.registration.create.params'
110 this.userService.signup(body).subscribe(
112 this.signupDone = true
114 if (this.requiresEmailVerification) {
115 this.info = $localize`Now please check your emails to verify your account and complete signup.`
120 this.authService.login(body.username, body.password)
123 this.success = $localize`You are now logged in as ${body.username}!`
126 err => this.error = err.message
130 err => this.error = err.message