Newer
Older
import {Component, AfterViewInit, Renderer, ElementRef, OnInit} from '@angular/core';
import { NgbActiveModal } from '@ng-bootstrap/ng-bootstrap';
import { Router } from '@angular/router';
import { JhiEventManager } from 'ng-jhipster';
import { LoginService } from './login.service';
import { StateStorageService } from '../auth/state-storage.service';
import {
AbstractControl,
FormBuilder,
FormGroup,
Validators
} from '@angular/forms';
import {EmitService} from "../event/eventEmitter";
@Component({
selector: 'jhi-login-modal',
templateUrl: './login.component.html'
})
export class JhiLoginModalComponent implements AfterViewInit,OnInit {
validateForm: FormGroup;
authenticationError: boolean;
password: string;
rememberMe: boolean;
username: string;
credentials: any;
constructor(
private fb: FormBuilder,
private eventManager: JhiEventManager,
private loginService: LoginService,
private stateStorageService: StateStorageService,
private elementRef: ElementRef,
private renderer: Renderer,
private router: Router,
public activeModal: NgbActiveModal,
public emitService:EmitService
) {
this.credentials = {};
this.emitService.eventEmit.subscribe((value: any) => {
if(value == "logout") {
this.router.navigate(['app/login']);
}else{
// this.token = false;
}
});
}
submitForm(): void {
this.validateForm.controls[ i ].markAsDirty();
this.validateForm.controls[ i ].updateValueAndValidity();
}
}
ngOnInit(): void {
this.validateForm = this.fb.group({
userName: [ null, [ Validators.required ] ],
password: [ null, [ Validators.required ] ],
remember: [ true ]
});
}
ngAfterViewInit() {
// this.renderer.invokeElementMethod(this.elementRef.nativeElement.querySelector('#username'), 'focus', []);
}
cancel() {
this.credentials = {
username: null,
password: null,
rememberMe: true
};
this.authenticationError = false;
this.activeModal.dismiss('cancel');
}
login() {
this.loginService.login({
loginName: this.username,
password: this.password,
rememberMe: true
}).then(() => {
this.isSpinning = false;
this.router.navigate(['app/main/basic']);
// this.authenticationError = false;
// this.activeModal.dismiss('login success');
// if (this.router.url === '/register' || (/^\/activate\//.test(this.router.url)) ||
// (/^\/reset\//.test(this.router.url))) {
// this.router.navigate(['app/main/basic']);
// }