1 import { Component, OnInit } from '@angular/core'
2 import { FormGroup } from '@angular/forms'
3 import { ActivatedRoute } from '@angular/router'
4 import { AuthService } from '@app/core'
5 import { HooksService } from '@app/core/plugins/hooks.service'
6 import { InstanceAboutAccordionComponent } from '@app/shared/shared-instance'
7 import { UserSignupService } from '@app/shared/shared-users'
8 import { NgbAccordion } from '@ng-bootstrap/ng-bootstrap'
9 import { UserRegister } from '@shared/models'
10 import { ServerConfig } from '@shared/models/server'
13 selector: 'my-register',
14 templateUrl: './register.component.html',
15 styleUrls: [ './register.component.scss' ]
17 export class RegisterComponent implements OnInit {
18 accordion: NgbAccordion
21 success: string = null
24 videoUploadDisabled: boolean
26 formStepTerms: FormGroup
27 formStepUser: FormGroup
28 formStepChannel: FormGroup
34 instanceInformationPanels = {
37 administrators: false,
42 defaultPreviousStepButtonLabel = $localize`:Button on the registration form to go to the previous step:Back`
43 defaultNextStepButtonLabel = $localize`:Button on the registration form to go to the previous step:Next`
44 stepUserButtonLabel = this.defaultNextStepButtonLabel
46 signupDisabled = false
48 private serverConfig: ServerConfig
51 private route: ActivatedRoute,
52 private authService: AuthService,
53 private userSignupService: UserSignupService,
54 private hooks: HooksService
57 get requiresEmailVerification () {
58 return this.serverConfig.signup.requiresEmailVerification
62 return this.serverConfig.signup.minimumAge
66 this.serverConfig = this.route.snapshot.data.serverConfig
68 if (this.serverConfig.signup.allowed === false || this.serverConfig.signup.allowedForCurrentIP === false) {
69 this.signupDisabled = true
73 this.videoUploadDisabled = this.serverConfig.user.videoQuota === 0
74 this.stepUserButtonLabel = this.videoUploadDisabled
75 ? $localize`:Button on the registration form to finalize the account and channel creation:Signup`
76 : this.defaultNextStepButtonLabel
78 this.hooks.runAction('action:signup.register.init', 'signup')
82 hasSameChannelAndAccountNames () {
83 return this.getUsername() === this.getChannelName()
87 if (!this.formStepUser) return undefined
89 return this.formStepUser.value['username']
93 if (!this.formStepChannel) return undefined
95 return this.formStepChannel.value['name']
98 onTermsFormBuilt (form: FormGroup) {
99 this.formStepTerms = form
102 onUserFormBuilt (form: FormGroup) {
103 this.formStepUser = form
106 onChannelFormBuilt (form: FormGroup) {
107 this.formStepChannel = form
111 if (this.accordion) this.accordion.toggle('terms')
114 onCodeOfConductClick () {
115 if (this.accordion) this.accordion.toggle('code-of-conduct')
118 onInstanceAboutAccordionInit (instanceAboutAccordion: InstanceAboutAccordionComponent) {
119 this.accordion = instanceAboutAccordion.accordion
120 this.aboutHtml = instanceAboutAccordion.aboutHtml
126 const body: UserRegister = await this.hooks.wrapObject(
127 Object.assign(this.formStepUser.value, { channel: this.videoUploadDisabled ? undefined : this.formStepChannel.value }),
129 'filter:api.signup.registration.create.params'
132 this.userSignupService.signup(body).subscribe({
134 this.signupDone = true
136 if (this.requiresEmailVerification) {
137 this.info = $localize`Now please check your emails to verify your account and complete signup.`
142 this.authService.login(body.username, body.password)
145 this.success = $localize`You are now logged in as ${body.username}!`
149 this.error = err.message
155 this.error = err.message