]>
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' |
d9eaee39 | 5 | import { 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, |
e309822b | 21 | private userValidatorsService: UserValidatorsService, |
a184c71b | 22 | private notificationsService: NotificationsService, |
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 C |
61 | |
62 | this.notificationsService.success( | |
63 | this.i18n('Success'), | |
64 | this.i18n('Registration for {{username}} complete.', { username: userCreate.username }) | |
65 | ) | |
b1d40cff | 66 | this.redirectService.redirectToHomepage() |
a184c71b C |
67 | }, |
68 | ||
f7354483 | 69 | err => this.error = err.message |
df98563e | 70 | ) |
a184c71b C |
71 | } |
72 | } |