61 lines
1.9 KiB
TypeScript
61 lines
1.9 KiB
TypeScript
import { Component, ElementRef, OnInit, ViewChild } from '@angular/core';
|
|
import { ActivatedRoute, Router } from '@angular/router';
|
|
|
|
import { environment } from '../../../environments/environment';
|
|
|
|
import { AuthService } from '../../services/auth.service';
|
|
|
|
@Component({
|
|
selector: 'page-login',
|
|
templateUrl: './login.page.html',
|
|
styleUrls: [ './login.page.scss' ]
|
|
})
|
|
export class PageLogin implements OnInit {
|
|
|
|
@ViewChild('loginForm') loginForm: ElementRef;
|
|
internalLogin: boolean;
|
|
loginInvalid: boolean;
|
|
externalLoginInvalid: boolean;
|
|
apiUrl = environment.apiUrl;
|
|
targetRoute: string;
|
|
externals: any[];
|
|
|
|
constructor(
|
|
private authService: AuthService,
|
|
private router: Router,
|
|
private route: ActivatedRoute) { }
|
|
|
|
async ngOnInit() {
|
|
this.route.queryParams.subscribe(params => {
|
|
if (params[ 'all' ] || params[ 'all' ] == '') {
|
|
this.internalLogin = true;
|
|
}
|
|
if (params[ 'target' ]) {
|
|
this.targetRoute = params[ 'target' ];
|
|
this.router.navigate([], { queryParams: { target: null }, queryParamsHandling: 'merge', replaceUrl: true });
|
|
}
|
|
if (params[ 'error' ] || params[ 'error' ] == '') {
|
|
this.loginInvalid = true;
|
|
this.router.navigate([], { queryParams: { error: null }, queryParamsHandling: 'merge', replaceUrl: true });
|
|
}
|
|
if (params[ 'externalError' ] || params[ 'externalError' ] == '') {
|
|
this.externalLoginInvalid = true;
|
|
this.router.navigate([], { queryParams: { externalError: null }, queryParamsHandling: 'merge', replaceUrl: true });
|
|
}
|
|
});
|
|
|
|
this.authService.getExternal().subscribe((data: any[]) => {
|
|
this.externals = data;
|
|
})
|
|
|
|
}
|
|
|
|
ngAfterViewInit(): void {
|
|
if (this.targetRoute) {
|
|
this.loginForm.nativeElement.action = this.loginForm.nativeElement.action + "?forward=" + window.location.origin + encodeURIComponent(this.targetRoute);
|
|
}
|
|
}
|
|
|
|
|
|
}
|