]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blame - client/src/app/+signup/+register/register.component.ts
Hide generic channel display name and avatar on watch view (#2988)
[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 { I18n } from '@ngx-translate/i18n-polyfill'
9import { UserRegister } from '@shared/models'
10import { About, ServerConfig } from '@shared/models/server'
a184c71b
C
11
12@Component({
b247a132
C
13 selector: 'my-register',
14 templateUrl: './register.component.html',
15 styleUrls: [ './register.component.scss' ]
a184c71b 16})
421d935d
C
17export class RegisterComponent implements OnInit {
18 @ViewChild('accordion', { static: true }) accordion: NgbAccordion
19
d8c9996c 20 info: string = null
df98563e 21 error: string = null
1d5342ab 22 success: string = null
d8c9996c 23 signupDone = false
a184c71b 24
421d935d
C
25 about: About
26 aboutHtml = {
27 description: '',
28 terms: '',
29 codeOfConduct: '',
30 moderationInformation: '',
31 administrator: ''
32 }
33
1d5342ab
C
34 formStepUser: FormGroup
35 formStepChannel: FormGroup
36
ba430d75
C
37 private serverConfig: ServerConfig
38
df98563e 39 constructor (
ba430d75 40 private route: ActivatedRoute,
43e9d2af 41 private authService: AuthService,
f8b2c1b4 42 private notifier: Notifier,
5afdd0a5 43 private userService: UserService,
421d935d 44 private instanceService: InstanceService,
ba7b7e57 45 private hooks: HooksService,
b1d40cff 46 private i18n: I18n
a184c71b 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
421d935d
C
57 this.instanceService.getAbout()
58 .subscribe(
59 async about => {
60 this.about = about
61
62 this.aboutHtml = await this.instanceService.buildHtml(about)
63 },
64
65 err => this.notifier.error(err.message)
66 )
ba7b7e57
RK
67
68 this.hooks.runAction('action:signup.register.init', 'signup')
421d935d
C
69 }
70
1d5342ab
C
71 hasSameChannelAndAccountNames () {
72 return this.getUsername() === this.getChannelName()
73 }
74
75 getUsername () {
76 if (!this.formStepUser) return undefined
77
78 return this.formStepUser.value['username']
79 }
80
81 getChannelName () {
82 if (!this.formStepChannel) return undefined
83
84 return this.formStepChannel.value['name']
85 }
86
87 onUserFormBuilt (form: FormGroup) {
88 this.formStepUser = form
89 }
90
91 onChannelFormBuilt (form: FormGroup) {
92 this.formStepChannel = form
a184c71b
C
93 }
94
421d935d
C
95 onTermsClick () {
96 if (this.accordion) this.accordion.toggle('terms')
97 }
98
99 onCodeOfConductClick () {
100 if (this.accordion) this.accordion.toggle('code-of-conduct')
101 }
102
ba7b7e57 103 async signup () {
df98563e 104 this.error = null
a184c71b 105
ba7b7e57
RK
106 const body: UserRegister = await this.hooks.wrapObject(
107 Object.assign(this.formStepUser.value, { channel: this.formStepChannel.value }),
0912f1b4 108 'signup',
ba7b7e57
RK
109 'filter:api.signup.registration.create.params'
110 )
a184c71b 111
1d5342ab 112 this.userService.signup(body).subscribe(
a184c71b 113 () => {
d8c9996c
C
114 this.signupDone = true
115
d9eaee39 116 if (this.requiresEmailVerification) {
1d5342ab 117 this.info = this.i18n('Now please check your emails to verify your account and complete signup.')
d8c9996c 118 return
d9eaee39 119 }
d8c9996c 120
43e9d2af 121 // Auto login
1d5342ab 122 this.authService.login(body.username, body.password)
43e9d2af
C
123 .subscribe(
124 () => {
1d5342ab 125 this.success = this.i18n('You are now logged in as {{username}}!', { username: body.username })
43e9d2af
C
126 },
127
128 err => this.error = err.message
129 )
a184c71b
C
130 },
131
f7354483 132 err => this.error = err.message
df98563e 133 )
a184c71b
C
134 }
135}