Newer
Older
import { Component, OnDestroy, OnInit } from '@angular/core';
import { FormControl, FormGroup, Validators } from '@angular/forms';
import { CustomtextService } from 'iqb-components';
import { ActivatedRoute, Router } from '@angular/router';
import { Subscription } from 'rxjs';
import { MainDataService } from '../../maindata.service';
import { AuthData } from '../../app.interfaces';
import { BackendService } from '../../backend.service';

mechtelm
committed
@Component({
templateUrl: './login.component.html',
styles: [

mechtelm
committed
'mat-card {margin: 10px;}',
'.mat-card-gray {background-color: lightgray}'

mechtelm
committed
]
})

mechtelm
committed
static oldLoginName = '';

mechtelm
committed
returnTo = '';

mechtelm
committed
loginForm = new FormGroup({
name: new FormControl(LoginComponent.oldLoginName, [Validators.required, Validators.minLength(3)]),
pw: new FormControl('')
});
systemAnnouncement: string;

mechtelm
committed
constructor(
public mds: MainDataService,
public cts: CustomtextService,
private bs: BackendService,

mechtelm
committed
private router: Router,
private route: ActivatedRoute
) { }
ngOnInit(): void {

mechtelm
committed
this.routingSubscription = this.route.params.subscribe(params => {
setTimeout(() => { // the timeout is avery temporary fix.- after upgrading to iqb-components 3, it can be removed
this.systemAnnouncement = this.cts.getCustomText('system_announcement', '-');
}, 500);

mechtelm
committed
}

mechtelm
committed
const loginData = this.loginForm.value;
this.problemText = '';
if (typeof authData === 'number') {
const errCode = authData as number;
if (errCode === 400) {

mechtelm
committed
this.problemText = 'Anmeldedaten sind nicht gültig. Bitte nocheinmal versuchen!';
} else if (errCode === 202 || errCode === 204) {
this.problemText = 'Anmeldedaten sind gültig, aber es sind keine Arbeitsbereiche oder Tests freigegeben.';
} else {
this.problemText = 'Problem bei der Anmeldung.';
// app.interceptor will show error message
const authDataTyped = authData as AuthData;
this.mds.setAuthData(authDataTyped);
if (this.returnTo) {
this.router.navigateByUrl(this.returnTo).then(navOk => {
if (!navOk) {
this.router.navigate(['/r']);
}
});

mechtelm
committed
}