1 import { CdkStep } from '@angular/cdk/stepper'
2 import { Component, OnInit, ViewChild } from '@angular/core'
3 import { FormGroup } from '@angular/forms'
4 import { ActivatedRoute } from '@angular/router'
5 import { AuthService } from '@app/core'
6 import { HooksService } from '@app/core/plugins/hooks.service'
7 import { InstanceAboutAccordionComponent } from '@app/shared/shared-instance'
8 import { UserSignupService } from '@app/shared/shared-users'
9 import { NgbAccordion } from '@ng-bootstrap/ng-bootstrap'
10 import { UserRegister } from '@shared/models'
11 import { ServerConfig } from '@shared/models/server'
14 selector: 'my-register',
15 templateUrl: './register.component.html',
16 styleUrls: [ './register.component.scss' ]
18 export class RegisterComponent implements OnInit {
19 @ViewChild('lastStep') lastStep: CdkStep
21 accordion: NgbAccordion
26 videoUploadDisabled: boolean
29 formStepTerms: FormGroup
30 formStepUser: FormGroup
31 formStepChannel: FormGroup
37 instanceInformationPanels = {
40 administrators: false,
45 defaultPreviousStepButtonLabel = $localize`Go to the previous step`
46 defaultNextStepButtonLabel = $localize`Go to the next step`
47 stepUserButtonLabel = this.defaultNextStepButtonLabel
49 signupDisabled = false
51 private serverConfig: ServerConfig
54 private route: ActivatedRoute,
55 private authService: AuthService,
56 private userSignupService: UserSignupService,
57 private hooks: HooksService
60 get requiresEmailVerification () {
61 return this.serverConfig.signup.requiresEmailVerification
65 return this.serverConfig.signup.minimumAge
69 return this.serverConfig.instance.name
73 this.serverConfig = this.route.snapshot.data.serverConfig
75 if (this.serverConfig.signup.allowed === false || this.serverConfig.signup.allowedForCurrentIP === false) {
76 this.signupDisabled = true
80 this.videoQuota = this.serverConfig.user.videoQuota
81 this.videoUploadDisabled = this.videoQuota === 0
83 this.stepUserButtonLabel = this.videoUploadDisabled
84 ? $localize`:Button on the registration form to finalize the account and channel creation:Signup`
85 : this.defaultNextStepButtonLabel
87 this.hooks.runAction('action:signup.register.init', 'signup')
91 hasSameChannelAndAccountNames () {
92 return this.getUsername() === this.getChannelName()
96 if (!this.formStepUser) return undefined
98 return this.formStepUser.value['username']
102 if (!this.formStepChannel) return undefined
104 return this.formStepChannel.value['name']
107 onTermsFormBuilt (form: FormGroup) {
108 this.formStepTerms = form
111 onUserFormBuilt (form: FormGroup) {
112 this.formStepUser = form
115 onChannelFormBuilt (form: FormGroup) {
116 this.formStepChannel = form
120 if (this.accordion) this.accordion.toggle('terms')
123 onCodeOfConductClick () {
124 if (this.accordion) this.accordion.toggle('code-of-conduct')
127 onInstanceAboutAccordionInit (instanceAboutAccordion: InstanceAboutAccordionComponent) {
128 this.accordion = instanceAboutAccordion.accordion
129 this.aboutHtml = instanceAboutAccordion.aboutHtml
132 skipChannelCreation () {
133 this.formStepChannel.reset()
134 this.lastStep.select()
139 this.signupError = undefined
141 const body: UserRegister = await this.hooks.wrapObject(
143 ...this.formStepUser.value,
145 channel: this.formStepChannel?.value?.name
146 ? this.formStepChannel.value
150 'filter:api.signup.registration.create.params'
153 this.userSignupService.signup(body).subscribe({
155 if (this.requiresEmailVerification) {
156 this.signupSuccess = true
161 this.authService.login({ username: body.username, password: body.password })
164 this.signupSuccess = true
168 this.signupError = err.message
174 this.signupError = err.message