]>
Commit | Line | Data |
---|---|---|
df98563e | 1 | import { Component, OnInit } from '@angular/core' |
df98563e | 2 | import { Router } from '@angular/router' |
df98563e | 3 | import { NotificationsService } from 'angular2-notifications' |
4771e000 | 4 | import { UserCreate } from '../../../../shared' |
e309822b | 5 | import { FormReactive, UserService, UserValidatorsService } from '../shared' |
d9eaee39 | 6 | import { RedirectService, ServerService } from '@app/core' |
b1d40cff | 7 | import { I18n } from '@ngx-translate/i18n-polyfill' |
d18d6478 | 8 | import { FormValidatorService } from '@app/shared/forms/form-validators/form-validator.service' |
a184c71b C |
9 | |
10 | @Component({ | |
11 | selector: 'my-signup', | |
d235f6b0 C |
12 | templateUrl: './signup.component.html', |
13 | styleUrls: [ './signup.component.scss' ] | |
a184c71b C |
14 | }) |
15 | export class SignupComponent extends FormReactive implements OnInit { | |
df98563e | 16 | error: string = null |
a184c71b | 17 | |
df98563e | 18 | constructor ( |
d18d6478 | 19 | protected formValidatorService: FormValidatorService, |
e309822b | 20 | private userValidatorsService: UserValidatorsService, |
a184c71b C |
21 | private router: Router, |
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 | () => { |
d9eaee39 JM |
55 | if (this.requiresEmailVerification) { |
56 | this.notificationsService.alert( | |
57 | this.i18n('Welcome'), | |
58 | this.i18n('Please check your email to verify your account and complete signup.') | |
59 | ) | |
60 | } else { | |
61 | this.notificationsService.success( | |
62 | this.i18n('Success'), | |
63 | this.i18n('Registration for {{username}} complete.', { username: userCreate.username }) | |
64 | ) | |
65 | } | |
b1d40cff | 66 | this.redirectService.redirectToHomepage() |
a184c71b C |
67 | }, |
68 | ||
f7354483 | 69 | err => this.error = err.message |
df98563e | 70 | ) |
a184c71b C |
71 | } |
72 | } |