Files
clients/angular/src/components/hint.component.ts

47 lines
1.8 KiB
TypeScript
Raw Normal View History

2018-04-04 09:47:43 -04:00
import { Router } from '@angular/router';
import { PasswordHintRequest } from 'jslib-common/models/request/passwordHintRequest';
2018-04-04 09:47:43 -04:00
import { ApiService } from 'jslib-common/abstractions/api.service';
import { I18nService } from 'jslib-common/abstractions/i18n.service';
import { LogService } from 'jslib-common/abstractions/log.service';
import { PlatformUtilsService } from 'jslib-common/abstractions/platformUtils.service';
2018-04-04 09:47:43 -04:00
export class HintComponent {
email: string = '';
formPromise: Promise<any>;
protected successRoute = 'login';
2018-10-15 13:02:31 -04:00
protected onSuccessfulSubmit: () => void;
2018-04-04 09:47:43 -04:00
constructor(protected router: Router, protected i18nService: I18nService,
protected apiService: ApiService, protected platformUtilsService: PlatformUtilsService,
private logService: LogService) { }
2018-04-04 09:47:43 -04:00
async submit() {
if (this.email == null || this.email === '') {
2018-10-02 23:09:19 -04:00
this.platformUtilsService.showToast('error', this.i18nService.t('errorOccurred'),
2018-04-04 09:47:43 -04:00
this.i18nService.t('emailRequired'));
return;
}
if (this.email.indexOf('@') === -1) {
2018-10-02 23:09:19 -04:00
this.platformUtilsService.showToast('error', this.i18nService.t('errorOccurred'),
2018-04-04 09:47:43 -04:00
this.i18nService.t('invalidEmail'));
return;
}
try {
this.formPromise = this.apiService.postPasswordHint(new PasswordHintRequest(this.email));
await this.formPromise;
2018-10-02 23:09:19 -04:00
this.platformUtilsService.showToast('success', null, this.i18nService.t('masterPassSent'));
2018-10-15 13:02:31 -04:00
if (this.onSuccessfulSubmit != null) {
this.onSuccessfulSubmit();
} else if (this.router != null) {
this.router.navigate([this.successRoute]);
}
} catch (e) {
this.logService.error(e);
}
2018-04-04 09:47:43 -04:00
}
}