import { Component, OnInit, ViewChild } from '@angular/core'; import { AuthenticationService } from 'src/app/shared/services/authentication.service'; import { AuthService } from 'src/app/shared/services/auth.service'; import { FeedbackPanelComponent } from 'src/app/shared/components/feedback-panel/feedback-panel.component'; import { LoginSuccessResult, ImportedArdaConUser } from 'tournee.businesslogic'; @Component({ selector: 'app-login-form', templateUrl: './login-form.component.html', styleUrls: ['./login-form.component.css'], providers: [AuthenticationService] }) export class LoginFormComponent implements OnInit { isWorking: boolean = false; @ViewChild('FeedbackPanel') FeedbackPanel:FeedbackPanelComponent; primary_email: string; password: string; Imported: ImportedArdaConUser; constructor(private _authentication: AuthenticationService, private _auth: AuthService) { } ngOnInit() { } login() { if (this.isWorking) { return; } this.isWorking = true; this.FeedbackPanel.reset(); this._authentication.login(this.primary_email, this.password) .then((result) => { let loginResult = new LoginSuccessResult(result.result); if (loginResult.user && loginResult.token) { this._auth.loginSuccess(loginResult); } else { this._auth.importing(loginResult.imported); } }) .catch((err) => { this.isWorking = false; this.FeedbackPanel.triggerError(err); }); }; trigger_forgotten_password() { if (this.isWorking) { return; } if (!this.primary_email) { return; } this.isWorking = true; this._authentication.trigger_forgotten_password(this.primary_email) .then(() => { this.isWorking = false; this.FeedbackPanel.triggerSuccess("Check your emails for a reset password prompt", false); }) .catch((err) => { this.isWorking = false; this.FeedbackPanel.triggerError(err); }); } Header() { if (this.Imported) { return "Importing from ArdaCon 2018"; } return "Login"; } }