]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blame - client/src/app/+signup/+register/register.component.ts
register: hide channel step if upload quota is 0
[github/Chocobozzz/PeerTube.git] / client / src / app / +signup / +register / register.component.ts
CommitLineData
421d935d 1import { Component, OnInit, ViewChild } from '@angular/core'
1d5342ab 2import { FormGroup } from '@angular/forms'
67ed6552
C
3import { ActivatedRoute } from '@angular/router'
4import { AuthService, Notifier, UserService } from '@app/core'
ba7b7e57 5import { HooksService } from '@app/core/plugins/hooks.service'
67ed6552 6import { InstanceService } from '@app/shared/shared-instance'
421d935d 7import { NgbAccordion } from '@ng-bootstrap/ng-bootstrap'
67ed6552
C
8import { UserRegister } from '@shared/models'
9import { About, ServerConfig } from '@shared/models/server'
a184c71b
C
10
11@Component({
b247a132
C
12 selector: 'my-register',
13 templateUrl: './register.component.html',
14 styleUrls: [ './register.component.scss' ]
a184c71b 15})
421d935d
C
16export class RegisterComponent implements OnInit {
17 @ViewChild('accordion', { static: true }) accordion: NgbAccordion
18
d8c9996c 19 info: string = null
df98563e 20 error: string = null
1d5342ab 21 success: string = null
d8c9996c 22 signupDone = false
a184c71b 23
421d935d
C
24 about: About
25 aboutHtml = {
26 description: '',
27 terms: '',
28 codeOfConduct: '',
29 moderationInformation: '',
30 administrator: ''
31 }
32
09c55770 33 videoUploadDisabled: boolean
34
1d5342ab
C
35 formStepUser: FormGroup
36 formStepChannel: FormGroup
37
ba430d75
C
38 private serverConfig: ServerConfig
39
df98563e 40 constructor (
ba430d75 41 private route: ActivatedRoute,
43e9d2af 42 private authService: AuthService,
f8b2c1b4 43 private notifier: Notifier,
5afdd0a5 44 private userService: UserService,
421d935d 45 private instanceService: InstanceService,
66357162
C
46 private hooks: HooksService
47 ) {
8a19bee1
C
48 }
49
d9eaee39 50 get requiresEmailVerification () {
ba430d75 51 return this.serverConfig.signup.requiresEmailVerification
d9eaee39
JM
52 }
53
421d935d 54 ngOnInit (): void {
ba430d75
C
55 this.serverConfig = this.route.snapshot.data.serverConfig
56
09c55770 57 this.videoUploadDisabled = this.serverConfig.user.videoQuota === 0
58
421d935d
C
59 this.instanceService.getAbout()
60 .subscribe(
61 async about => {
62 this.about = about
63
64 this.aboutHtml = await this.instanceService.buildHtml(about)
65 },
66
67 err => this.notifier.error(err.message)
68 )
ba7b7e57
RK
69
70 this.hooks.runAction('action:signup.register.init', 'signup')
421d935d
C
71 }
72
1d5342ab
C
73 hasSameChannelAndAccountNames () {
74 return this.getUsername() === this.getChannelName()
75 }
76
77 getUsername () {
78 if (!this.formStepUser) return undefined
79
80 return this.formStepUser.value['username']
81 }
82
83 getChannelName () {
84 if (!this.formStepChannel) return undefined
85
86 return this.formStepChannel.value['name']
87 }
88
89 onUserFormBuilt (form: FormGroup) {
90 this.formStepUser = form
91 }
92
93 onChannelFormBuilt (form: FormGroup) {
94 this.formStepChannel = form
a184c71b
C
95 }
96
421d935d
C
97 onTermsClick () {
98 if (this.accordion) this.accordion.toggle('terms')
99 }
100
101 onCodeOfConductClick () {
102 if (this.accordion) this.accordion.toggle('code-of-conduct')
103 }
104
ba7b7e57 105 async signup () {
df98563e 106 this.error = null
a184c71b 107
ba7b7e57 108 const body: UserRegister = await this.hooks.wrapObject(
09c55770 109 Object.assign(this.formStepUser.value, { channel: this.videoUploadDisabled ? undefined : this.formStepChannel.value }),
0912f1b4 110 'signup',
ba7b7e57
RK
111 'filter:api.signup.registration.create.params'
112 )
a184c71b 113
1d5342ab 114 this.userService.signup(body).subscribe(
a184c71b 115 () => {
d8c9996c
C
116 this.signupDone = true
117
d9eaee39 118 if (this.requiresEmailVerification) {
66357162 119 this.info = $localize`Now please check your emails to verify your account and complete signup.`
d8c9996c 120 return
d9eaee39 121 }
d8c9996c 122
43e9d2af 123 // Auto login
1d5342ab 124 this.authService.login(body.username, body.password)
43e9d2af
C
125 .subscribe(
126 () => {
66357162 127 this.success = $localize`You are now logged in as ${body.username}!`
43e9d2af
C
128 },
129
130 err => this.error = err.message
131 )
a184c71b
C
132 },
133
f7354483 134 err => this.error = err.message
df98563e 135 )
a184c71b
C
136 }
137}