]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blame - client/src/app/+signup/+register/register.component.ts
Fix i18n generation script
[github/Chocobozzz/PeerTube.git] / client / src / app / +signup / +register / register.component.ts
CommitLineData
421d935d 1import { Component, OnInit, ViewChild } from '@angular/core'
f8b2c1b4 2import { AuthService, Notifier, RedirectService, ServerService } from '@app/core'
b247a132 3import { UserService, UserValidatorsService } from '@app/shared'
b1d40cff 4import { I18n } from '@ngx-translate/i18n-polyfill'
1d5342ab
C
5import { UserRegister } from '@shared/models/users/user-register.model'
6import { FormGroup } from '@angular/forms'
421d935d
C
7import { About } from '@shared/models/server'
8import { InstanceService } from '@app/shared/instance/instance.service'
9import { NgbAccordion } from '@ng-bootstrap/ng-bootstrap'
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
1d5342ab
C
33 formStepUser: FormGroup
34 formStepChannel: FormGroup
35
df98563e 36 constructor (
43e9d2af 37 private authService: AuthService,
e309822b 38 private userValidatorsService: UserValidatorsService,
f8b2c1b4 39 private notifier: Notifier,
5afdd0a5 40 private userService: UserService,
d9eaee39 41 private serverService: ServerService,
b1d40cff 42 private redirectService: RedirectService,
421d935d 43 private instanceService: InstanceService,
b1d40cff 44 private i18n: I18n
a184c71b 45 ) {
8a19bee1
C
46 }
47
d9eaee39
JM
48 get requiresEmailVerification () {
49 return this.serverService.getConfig().signup.requiresEmailVerification
50 }
51
421d935d
C
52 ngOnInit (): void {
53 this.instanceService.getAbout()
54 .subscribe(
55 async about => {
56 this.about = about
57
58 this.aboutHtml = await this.instanceService.buildHtml(about)
59 },
60
61 err => this.notifier.error(err.message)
62 )
63 }
64
1d5342ab
C
65 hasSameChannelAndAccountNames () {
66 return this.getUsername() === this.getChannelName()
67 }
68
69 getUsername () {
70 if (!this.formStepUser) return undefined
71
72 return this.formStepUser.value['username']
73 }
74
75 getChannelName () {
76 if (!this.formStepChannel) return undefined
77
78 return this.formStepChannel.value['name']
79 }
80
81 onUserFormBuilt (form: FormGroup) {
82 this.formStepUser = form
83 }
84
85 onChannelFormBuilt (form: FormGroup) {
86 this.formStepChannel = form
a184c71b
C
87 }
88
421d935d
C
89 onTermsClick () {
90 if (this.accordion) this.accordion.toggle('terms')
91 }
92
93 onCodeOfConductClick () {
94 if (this.accordion) this.accordion.toggle('code-of-conduct')
95 }
96
df98563e
C
97 signup () {
98 this.error = null
a184c71b 99
b247a132 100 const body: UserRegister = Object.assign(this.formStepUser.value, { channel: this.formStepChannel.value })
a184c71b 101
1d5342ab 102 this.userService.signup(body).subscribe(
a184c71b 103 () => {
d8c9996c
C
104 this.signupDone = true
105
d9eaee39 106 if (this.requiresEmailVerification) {
1d5342ab 107 this.info = this.i18n('Now please check your emails to verify your account and complete signup.')
d8c9996c 108 return
d9eaee39 109 }
d8c9996c 110
43e9d2af 111 // Auto login
1d5342ab 112 this.authService.login(body.username, body.password)
43e9d2af
C
113 .subscribe(
114 () => {
1d5342ab 115 this.success = this.i18n('You are now logged in as {{username}}!', { username: body.username })
43e9d2af
C
116 },
117
118 err => this.error = err.message
119 )
a184c71b
C
120 },
121
f7354483 122 err => this.error = err.message
df98563e 123 )
a184c71b
C
124 }
125}