]>
Commit | Line | Data |
---|---|---|
1 | import { Component, OnInit } from '@angular/core' | |
2 | import { I18n } from '@ngx-translate/i18n-polyfill' | |
3 | import { NotificationsService } from 'angular2-notifications' | |
4 | import { ServerService } from '@app/core/server' | |
5 | import { RedirectService } from '@app/core' | |
6 | import { UserService, FormReactive } from '@app/shared' | |
7 | import { FormValidatorService } from '@app/shared/forms/form-validators/form-validator.service' | |
8 | import { UserValidatorsService } from '@app/shared/forms/form-validators/user-validators.service' | |
9 | ||
10 | @Component({ | |
11 | selector: 'my-verify-account-ask-send-email', | |
12 | templateUrl: './verify-account-ask-send-email.component.html', | |
13 | styleUrls: [ './verify-account-ask-send-email.component.scss' ] | |
14 | }) | |
15 | ||
16 | export class VerifyAccountAskSendEmailComponent extends FormReactive implements OnInit { | |
17 | ||
18 | constructor ( | |
19 | protected formValidatorService: FormValidatorService, | |
20 | private userValidatorsService: UserValidatorsService, | |
21 | private userService: UserService, | |
22 | private serverService: ServerService, | |
23 | private notificationsService: NotificationsService, | |
24 | private redirectService: RedirectService, | |
25 | private i18n: I18n | |
26 | ) { | |
27 | super() | |
28 | } | |
29 | ||
30 | get requiresEmailVerification () { | |
31 | return this.serverService.getConfig().signup.requiresEmailVerification | |
32 | } | |
33 | ||
34 | ngOnInit () { | |
35 | this.buildForm({ | |
36 | 'verify-email-email': this.userValidatorsService.USER_EMAIL | |
37 | }) | |
38 | } | |
39 | ||
40 | askSendVerifyEmail () { | |
41 | const email = this.form.value['verify-email-email'] | |
42 | this.userService.askSendVerifyEmail(email) | |
43 | .subscribe( | |
44 | () => { | |
45 | const message = this.i18n( | |
46 | 'An email with verification link will be sent to {{email}}.', | |
47 | { email } | |
48 | ) | |
49 | this.notificationsService.success(this.i18n('Success'), message) | |
50 | this.redirectService.redirectToHomepage() | |
51 | }, | |
52 | ||
53 | err => { | |
54 | this.notificationsService.error(this.i18n('Error'), err.message) | |
55 | } | |
56 | ) | |
57 | } | |
58 | } |