Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import { Component, OnDestroy, OnInit } from '@angular/core';
- import { User } from './user';
- import { SessionService } from '../session-service/session.service';
- import { Subscription } from 'rxjs';
- import { Router } from '@angular/router';
- import { TranslateService } from '@ngx-translate/core';
- import { UserSession } from './user-session';
- const emptyUser: User = {
- username: '',
- password: ''
- };
- @Component({
- selector: 'app-login',
- templateUrl: './login.component.html',
- styleUrls: ['./login.component.scss']
- })
- export class LoginComponent implements OnInit, OnDestroy {
- loginSubscription: Subscription;
- loginFailed = false;
- loginUser: User = emptyUser;
- userSession: UserSession = {};
- constructor(private sessionService: SessionService, private router: Router, public translate: TranslateService) {}
- ngOnDestroy(): void {
- if (this.loginSubscription) {
- this.loginSubscription.unsubscribe();
- }
- }
- ngOnInit() {}
- login(): void {
- this.loginSubscription = this.sessionService.login(this.loginUser).subscribe(
- result => {
- if (result) {
- this.userSession = result;
- this.sessionService.setUser(this.userSession);
- this.router.navigate(['bo/dashboard']);
- }
- },
- error => {
- this.loginFailed = true;
- console.error('error in login', error);
- }
- );
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement