aboutsummaryrefslogtreecommitdiffhomepage
path: root/client/src/app/signup/signup.component.ts
diff options
context:
space:
mode:
authorChocobozzz <me@florianbigard.com>2019-05-29 11:03:01 +0200
committerChocobozzz <me@florianbigard.com>2019-05-29 11:19:54 +0200
commit1d5342abc43df02cf0bd69b1e865c0f179182eef (patch)
treef008b43ca8189ee5856e39e5b9d4800bf37f9575 /client/src/app/signup/signup.component.ts
parente590b4a512617bbf63595b684386f68abea7d8b8 (diff)
downloadPeerTube-1d5342abc43df02cf0bd69b1e865c0f179182eef.tar.gz
PeerTube-1d5342abc43df02cf0bd69b1e865c0f179182eef.tar.zst
PeerTube-1d5342abc43df02cf0bd69b1e865c0f179182eef.zip
Multi step registration
Diffstat (limited to 'client/src/app/signup/signup.component.ts')
-rw-r--r--client/src/app/signup/signup.component.ts61
1 files changed, 36 insertions, 25 deletions
diff --git a/client/src/app/signup/signup.component.ts b/client/src/app/signup/signup.component.ts
index 13941ec79..11eaa8521 100644
--- a/client/src/app/signup/signup.component.ts
+++ b/client/src/app/signup/signup.component.ts
@@ -1,22 +1,25 @@
1import { Component, OnInit } from '@angular/core' 1import { Component } from '@angular/core'
2import { AuthService, Notifier, RedirectService, ServerService } from '@app/core' 2import { AuthService, Notifier, RedirectService, ServerService } from '@app/core'
3import { UserCreate } from '../../../../shared' 3import { UserService, UserValidatorsService } from '../shared'
4import { FormReactive, UserService, UserValidatorsService } from '../shared'
5import { I18n } from '@ngx-translate/i18n-polyfill' 4import { I18n } from '@ngx-translate/i18n-polyfill'
6import { FormValidatorService } from '@app/shared/forms/form-validators/form-validator.service' 5import { UserRegister } from '@shared/models/users/user-register.model'
6import { FormGroup } from '@angular/forms'
7 7
8@Component({ 8@Component({
9 selector: 'my-signup', 9 selector: 'my-signup',
10 templateUrl: './signup.component.html', 10 templateUrl: './signup.component.html',
11 styleUrls: [ './signup.component.scss' ] 11 styleUrls: [ './signup.component.scss' ]
12}) 12})
13export class SignupComponent extends FormReactive implements OnInit { 13export class SignupComponent {
14 info: string = null 14 info: string = null
15 error: string = null 15 error: string = null
16 success: string = null
16 signupDone = false 17 signupDone = false
17 18
19 formStepUser: FormGroup
20 formStepChannel: FormGroup
21
18 constructor ( 22 constructor (
19 protected formValidatorService: FormValidatorService,
20 private authService: AuthService, 23 private authService: AuthService,
21 private userValidatorsService: UserValidatorsService, 24 private userValidatorsService: UserValidatorsService,
22 private notifier: Notifier, 25 private notifier: Notifier,
@@ -25,47 +28,55 @@ export class SignupComponent extends FormReactive implements OnInit {
25 private redirectService: RedirectService, 28 private redirectService: RedirectService,
26 private i18n: I18n 29 private i18n: I18n
27 ) { 30 ) {
28 super()
29 }
30
31 get instanceHost () {
32 return window.location.host
33 } 31 }
34 32
35 get requiresEmailVerification () { 33 get requiresEmailVerification () {
36 return this.serverService.getConfig().signup.requiresEmailVerification 34 return this.serverService.getConfig().signup.requiresEmailVerification
37 } 35 }
38 36
39 ngOnInit () { 37 hasSameChannelAndAccountNames () {
40 this.buildForm({ 38 return this.getUsername() === this.getChannelName()
41 username: this.userValidatorsService.USER_USERNAME, 39 }
42 password: this.userValidatorsService.USER_PASSWORD, 40
43 email: this.userValidatorsService.USER_EMAIL, 41 getUsername () {
44 terms: this.userValidatorsService.USER_TERMS 42 if (!this.formStepUser) return undefined
45 }) 43
44 return this.formStepUser.value['username']
45 }
46
47 getChannelName () {
48 if (!this.formStepChannel) return undefined
49
50 return this.formStepChannel.value['name']
51 }
52
53 onUserFormBuilt (form: FormGroup) {
54 this.formStepUser = form
55 }
56
57 onChannelFormBuilt (form: FormGroup) {
58 this.formStepChannel = form
46 } 59 }
47 60
48 signup () { 61 signup () {
49 this.error = null 62 this.error = null
50 63
51 const userCreate: UserCreate = this.form.value 64 const body: UserRegister = Object.assign(this.formStepUser.value, this.formStepChannel.value)
52 65
53 this.userService.signup(userCreate).subscribe( 66 this.userService.signup(body).subscribe(
54 () => { 67 () => {
55 this.signupDone = true 68 this.signupDone = true
56 69
57 if (this.requiresEmailVerification) { 70 if (this.requiresEmailVerification) {
58 this.info = this.i18n('Welcome! Now please check your emails to verify your account and complete signup.') 71 this.info = this.i18n('Now please check your emails to verify your account and complete signup.')
59 return 72 return
60 } 73 }
61 74
62 // Auto login 75 // Auto login
63 this.authService.login(userCreate.username, userCreate.password) 76 this.authService.login(body.username, body.password)
64 .subscribe( 77 .subscribe(
65 () => { 78 () => {
66 this.notifier.success(this.i18n('You are now logged in as {{username}}!', { username: userCreate.username })) 79 this.success = this.i18n('You are now logged in as {{username}}!', { username: body.username })
67
68 this.redirectService.redirectToHomepage()
69 }, 80 },
70 81
71 err => this.error = err.message 82 err => this.error = err.message