argos/dmp-frontend/src/app/ui/auth/admin-login/admin-login.component.ts

56 lines
1.9 KiB
TypeScript

import { Component, OnInit } from '@angular/core';
import { Router } from '@angular/router';
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';
import { TranslateService } from '@ngx-translate/core';
import { takeUntil } from 'rxjs/operators';
@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;
public credential: Credential;
constructor(
private authService: AuthService,
private uiNotificationService: UiNotificationService,
private language: TranslateService,
private cultureService: CultureService,
private router: Router
) { super(); }
ngOnInit() {
this.credential = {
username: null,
secret: null
}
}
public nativeLogin() {
this.authService.nativeLogin(this.credential)
.pipe(takeUntil(this._destroyed))
.subscribe(
res => this.onLogInSuccess(res),
error => this.onLogInError(error)
);
}
public onLogInSuccess(loginResponse: any) {
this.uiNotificationService.snackBarNotification(this.language.instant('GENERAL.SNACK-BAR.SUCCESSFUL-LOGIN'), SnackBarNotificationLevel.Success);
if (this.authService.current().culture) { this.cultureService.cultureSelected(this.authService.current().culture); }
this.router.navigate(['/']);
}
public onLogInError(errorMessage: string) {
this.uiNotificationService.snackBarNotification(this.language.instant('GENERAL.SNACK-BAR.UNSUCCESSFUL-LOGIN'), SnackBarNotificationLevel.Error);
}
}