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