Files
cbsnexora/src/app/login/login.component.ts
T
Abhay ChawlaandGitHub 72020e21d4 feat: update UI for Login Component (#96)
Update UI for Login Component using angular material.

Fixes #95
2018-07-05 20:43:38 +05:30

72 lines
1.8 KiB
TypeScript

import { Component, OnInit } from '@angular/core';
import { Router } from '@angular/router';
import { FormGroup, FormBuilder, Validators } from '@angular/forms';
import { finalize } from 'rxjs/operators';
import { environment } from '../../environments/environment';
import { Logger, I18nService, AuthenticationService } from '../core';
const log = new Logger('Login');
@Component({
selector: 'mifosx-login',
templateUrl: './login.component.html',
styleUrls: ['./login.component.scss']
})
export class LoginComponent implements OnInit {
version: string = environment.version;
error: string;
loginForm: FormGroup;
isLoading = false;
languages = ['en-US', 'fr'];
language = this.languages[0];
constructor(private router: Router,
private formBuilder: FormBuilder,
private i18nService: I18nService,
private authenticationService: AuthenticationService) {
this.createForm();
}
ngOnInit() { }
login() {
this.isLoading = true;
this.authenticationService.login(this.loginForm.value)
.pipe(finalize(() => {
this.loginForm.markAsPristine();
this.isLoading = false;
}))
.subscribe(credentials => {
log.debug(`${credentials.username} successfully logged in`);
this.router.navigate(['/'], { replaceUrl: true });
}, error => {
log.debug(`Login error: ${error}`);
this.error = error;
});
}
setLanguage(language: string) {
this.i18nService.language = language;
}
get currentLanguage(): string {
return this.i18nService.language;
}
// get languages(): string[] {
// return this.i18nService.supportedLanguages;
// }
private createForm() {
this.loginForm = this.formBuilder.group({
username: ['', Validators.required],
password: ['', Validators.required],
remember: true
});
}
}