1 import { Component, OnInit } from '@angular/core'
2 import { FormGroup } from '@angular/forms'
3 import { ActivatedRoute } from '@angular/router'
4 import { AuthService, UserService } from '@app/core'
5 import { HooksService } from '@app/core/plugins/hooks.service'
6 import { NgbAccordion } from '@ng-bootstrap/ng-bootstrap'
7 import { UserRegister } from '@shared/models'
8 import { ServerConfig } from '@shared/models/server'
9 import { InstanceAboutAccordionComponent } from '@app/shared/shared-instance'
12 selector: 'my-register',
13 templateUrl: './register.component.html',
14 styleUrls: [ './register.component.scss' ]
16 export class RegisterComponent implements OnInit {
17 accordion: NgbAccordion
20 success: string = null
23 videoUploadDisabled: boolean
25 formStepTerms: FormGroup
26 formStepUser: FormGroup
27 formStepChannel: FormGroup
33 instanceInformationPanels = {
36 administrators: false,
41 defaultPreviousStepButtonLabel = $localize`:Button on the registration form to go to the previous step:Back`
42 defaultNextStepButtonLabel = $localize`:Button on the registration form to go to the previous step:Next`
43 stepUserButtonLabel = this.defaultNextStepButtonLabel
45 private serverConfig: ServerConfig
48 private route: ActivatedRoute,
49 private authService: AuthService,
50 private userService: UserService,
51 private hooks: HooksService
55 get requiresEmailVerification () {
56 return this.serverConfig.signup.requiresEmailVerification
60 this.serverConfig = this.route.snapshot.data.serverConfig
62 this.videoUploadDisabled = this.serverConfig.user.videoQuota === 0
63 this.stepUserButtonLabel = this.videoUploadDisabled
64 ? $localize`:Button on the registration form to finalize the account and channel creation:Signup`
65 : this.defaultNextStepButtonLabel
67 this.hooks.runAction('action:signup.register.init', 'signup')
71 hasSameChannelAndAccountNames () {
72 return this.getUsername() === this.getChannelName()
76 if (!this.formStepUser) return undefined
78 return this.formStepUser.value['username']
82 if (!this.formStepChannel) return undefined
84 return this.formStepChannel.value['name']
87 onTermsFormBuilt (form: FormGroup) {
88 this.formStepTerms = form
91 onUserFormBuilt (form: FormGroup) {
92 this.formStepUser = form
95 onChannelFormBuilt (form: FormGroup) {
96 this.formStepChannel = form
100 if (this.accordion) this.accordion.toggle('terms')
103 onCodeOfConductClick () {
104 if (this.accordion) this.accordion.toggle('code-of-conduct')
107 onInstanceAboutAccordionInit (instanceAboutAccordion: InstanceAboutAccordionComponent) {
108 this.accordion = instanceAboutAccordion.accordion
109 this.aboutHtml = instanceAboutAccordion.aboutHtml
115 const body: UserRegister = await this.hooks.wrapObject(
116 Object.assign(this.formStepUser.value, { channel: this.videoUploadDisabled ? undefined : this.formStepChannel.value }),
118 'filter:api.signup.registration.create.params'
121 this.userService.signup(body).subscribe(
123 this.signupDone = true
125 if (this.requiresEmailVerification) {
126 this.info = $localize`Now please check your emails to verify your account and complete signup.`
131 this.authService.login(body.username, body.password)
134 this.success = $localize`You are now logged in as ${body.username}!`
137 err => this.error = err.message
141 err => this.error = err.message