2020-01-16 11:32:25 +01:00
|
|
|
import { Component, OnInit, HostListener } from '@angular/core';
|
2019-01-18 18:03:45 +01:00
|
|
|
import { Router } from '@angular/router';
|
2019-12-11 15:51:03 +01:00
|
|
|
import { Credential } from '@app/core/model/auth/credential';
|
|
|
|
import { AuthService } from '@app/core/services/auth/auth.service';
|
|
|
|
import { CultureService } from '@app/core/services/culture/culture-service';
|
|
|
|
import { SnackBarNotificationLevel, UiNotificationService } from '@app/core/services/notification/ui-notification-service';
|
|
|
|
import { BaseComponent } from '@common/base/base.component';
|
2019-01-18 18:03:45 +01:00
|
|
|
import { TranslateService } from '@ngx-translate/core';
|
|
|
|
import { takeUntil } from 'rxjs/operators';
|
2020-01-23 17:35:11 +01:00
|
|
|
import { TranslateServerLoader } from '@app/core/services/language/server.loader';
|
|
|
|
import { LanguageService } from '@app/core/services/language/language.service';
|
2019-01-18 18:03:45 +01:00
|
|
|
@Component({
|
|
|
|
selector: 'app-admin-login',
|
|
|
|
templateUrl: './admin-login.component.html',
|
|
|
|
styleUrls: ['./admin-login.component.scss']
|
|
|
|
})
|
|
|
|
export class AdminLoginComponent extends BaseComponent implements OnInit {
|
|
|
|
|
|
|
|
public auth2: any;
|
2019-02-15 10:18:14 +01:00
|
|
|
public credential: Credential;
|
2019-01-18 18:03:45 +01:00
|
|
|
|
2020-01-16 11:32:25 +01:00
|
|
|
@HostListener('document:keydown.enter', ['$event']) onKeydownHandler() {
|
|
|
|
this.nativeLogin();
|
|
|
|
}
|
|
|
|
|
2019-01-18 18:03:45 +01:00
|
|
|
constructor(
|
|
|
|
private authService: AuthService,
|
|
|
|
private uiNotificationService: UiNotificationService,
|
2020-01-23 17:35:11 +01:00
|
|
|
private translate: TranslateService,
|
2019-01-18 18:03:45 +01:00
|
|
|
private cultureService: CultureService,
|
2020-01-23 17:35:11 +01:00
|
|
|
private router: Router,
|
|
|
|
private language: LanguageService
|
2019-01-18 18:03:45 +01:00
|
|
|
) { super(); }
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
ngOnInit() {
|
2019-02-15 10:18:14 +01:00
|
|
|
this.credential = {
|
|
|
|
username: null,
|
|
|
|
secret: null
|
|
|
|
}
|
2019-01-18 18:03:45 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
public nativeLogin() {
|
|
|
|
this.authService.nativeLogin(this.credential)
|
|
|
|
.pipe(takeUntil(this._destroyed))
|
|
|
|
.subscribe(
|
|
|
|
res => this.onLogInSuccess(res),
|
|
|
|
error => this.onLogInError(error)
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
public onLogInSuccess(loginResponse: any) {
|
2020-01-23 17:35:11 +01:00
|
|
|
this.uiNotificationService.snackBarNotification(this.translate.instant('GENERAL.SNACK-BAR.SUCCESSFUL-LOGIN'), SnackBarNotificationLevel.Success);
|
2019-01-18 18:03:45 +01:00
|
|
|
if (this.authService.current().culture) { this.cultureService.cultureSelected(this.authService.current().culture); }
|
2020-01-23 17:35:11 +01:00
|
|
|
if (this.authService.current().language) { this.language.changeLanguage(this.authService.current().language); }
|
2019-01-18 18:03:45 +01:00
|
|
|
this.router.navigate(['/']);
|
|
|
|
}
|
|
|
|
|
|
|
|
public onLogInError(errorMessage: string) {
|
2020-01-23 17:35:11 +01:00
|
|
|
this.uiNotificationService.snackBarNotification(this.translate.instant('GENERAL.SNACK-BAR.UNSUCCESSFUL-LOGIN'), SnackBarNotificationLevel.Error);
|
2019-01-18 18:03:45 +01:00
|
|
|
}
|
|
|
|
}
|