]>
Commit | Line | Data |
---|---|---|
df98563e | 1 | import { Component, OnInit } from '@angular/core' |
f8b2c1b4 | 2 | import { AuthService, Notifier, RedirectService, ServerService } from '@app/core' |
4771e000 | 3 | import { UserCreate } from '../../../../shared' |
e309822b | 4 | import { FormReactive, UserService, UserValidatorsService } from '../shared' |
b1d40cff | 5 | import { I18n } from '@ngx-translate/i18n-polyfill' |
d18d6478 | 6 | import { FormValidatorService } from '@app/shared/forms/form-validators/form-validator.service' |
a184c71b C |
7 | |
8 | @Component({ | |
9 | selector: 'my-signup', | |
d235f6b0 C |
10 | templateUrl: './signup.component.html', |
11 | styleUrls: [ './signup.component.scss' ] | |
a184c71b C |
12 | }) |
13 | export class SignupComponent extends FormReactive implements OnInit { | |
d8c9996c | 14 | info: string = null |
df98563e | 15 | error: string = null |
d8c9996c | 16 | signupDone = false |
a184c71b | 17 | |
df98563e | 18 | constructor ( |
d18d6478 | 19 | protected formValidatorService: FormValidatorService, |
43e9d2af | 20 | private authService: AuthService, |
e309822b | 21 | private userValidatorsService: UserValidatorsService, |
f8b2c1b4 | 22 | private notifier: Notifier, |
5afdd0a5 | 23 | private userService: UserService, |
d9eaee39 | 24 | private serverService: ServerService, |
b1d40cff | 25 | private redirectService: RedirectService, |
b1d40cff | 26 | private i18n: I18n |
a184c71b | 27 | ) { |
df98563e | 28 | super() |
a184c71b C |
29 | } |
30 | ||
8a19bee1 C |
31 | get instanceHost () { |
32 | return window.location.host | |
33 | } | |
34 | ||
d9eaee39 JM |
35 | get requiresEmailVerification () { |
36 | return this.serverService.getConfig().signup.requiresEmailVerification | |
37 | } | |
38 | ||
df98563e | 39 | ngOnInit () { |
d18d6478 | 40 | this.buildForm({ |
e309822b C |
41 | username: this.userValidatorsService.USER_USERNAME, |
42 | password: this.userValidatorsService.USER_PASSWORD, | |
b4a929ac C |
43 | email: this.userValidatorsService.USER_EMAIL, |
44 | terms: this.userValidatorsService.USER_TERMS | |
d18d6478 | 45 | }) |
a184c71b C |
46 | } |
47 | ||
df98563e C |
48 | signup () { |
49 | this.error = null | |
a184c71b | 50 | |
4771e000 | 51 | const userCreate: UserCreate = this.form.value |
a184c71b | 52 | |
4771e000 | 53 | this.userService.signup(userCreate).subscribe( |
a184c71b | 54 | () => { |
d8c9996c C |
55 | this.signupDone = true |
56 | ||
d9eaee39 | 57 | if (this.requiresEmailVerification) { |
d8c9996c C |
58 | this.info = this.i18n('Welcome! Now please check your emails to verify your account and complete signup.') |
59 | return | |
d9eaee39 | 60 | } |
d8c9996c | 61 | |
43e9d2af C |
62 | // Auto login |
63 | this.authService.login(userCreate.username, userCreate.password) | |
64 | .subscribe( | |
65 | () => { | |
f8b2c1b4 | 66 | this.notifier.success(this.i18n('You are now logged in as {{username}}!', { username: userCreate.username })) |
43e9d2af C |
67 | |
68 | this.redirectService.redirectToHomepage() | |
69 | }, | |
70 | ||
71 | err => this.error = err.message | |
72 | ) | |
a184c71b C |
73 | }, |
74 | ||
f7354483 | 75 | err => this.error = err.message |
df98563e | 76 | ) |
a184c71b C |
77 | } |
78 | } |