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 videoUploadDisabled: boolean
35 formStepUser: FormGroup
36 formStepChannel: FormGroup
38 private serverConfig: ServerConfig
41 private route: ActivatedRoute,
42 private authService: AuthService,
43 private notifier: Notifier,
44 private userService: UserService,
45 private instanceService: InstanceService,
46 private hooks: HooksService
50 get requiresEmailVerification () {
51 return this.serverConfig.signup.requiresEmailVerification
55 this.serverConfig = this.route.snapshot.data.serverConfig
57 this.videoUploadDisabled = this.serverConfig.user.videoQuota === 0
59 this.instanceService.getAbout()
64 this.aboutHtml = await this.instanceService.buildHtml(about)
67 err => this.notifier.error(err.message)
70 this.hooks.runAction('action:signup.register.init', 'signup')
73 hasSameChannelAndAccountNames () {
74 return this.getUsername() === this.getChannelName()
78 if (!this.formStepUser) return undefined
80 return this.formStepUser.value['username']
84 if (!this.formStepChannel) return undefined
86 return this.formStepChannel.value['name']
89 onUserFormBuilt (form: FormGroup) {
90 this.formStepUser = form
93 onChannelFormBuilt (form: FormGroup) {
94 this.formStepChannel = form
98 if (this.accordion) this.accordion.toggle('terms')
101 onCodeOfConductClick () {
102 if (this.accordion) this.accordion.toggle('code-of-conduct')
108 const body: UserRegister = await this.hooks.wrapObject(
109 Object.assign(this.formStepUser.value, { channel: this.videoUploadDisabled ? undefined : this.formStepChannel.value }),
111 'filter:api.signup.registration.create.params'
114 this.userService.signup(body).subscribe(
116 this.signupDone = true
118 if (this.requiresEmailVerification) {
119 this.info = $localize`Now please check your emails to verify your account and complete signup.`
124 this.authService.login(body.username, body.password)
127 this.success = $localize`You are now logged in as ${body.username}!`
130 err => this.error = err.message
134 err => this.error = err.message