Projekt

Obecné

Profil

« Předchozí | Další » 

Revize 675bbb8c

Přidáno uživatelem Jakub Hlaváč před téměř 4 roky(ů)

Re #8468 - Implementovat login formulář

  • implementation of login form on separate page
    + new dashboard

Zobrazit rozdíly:

src/app/shared/nav-bar/components/nav-bar.component.ts
1 1
import {Component, OnDestroy, OnInit} from '@angular/core';
2
import {LoginForm} from '../models/login-form';
3 2
import {AuthService} from '../../../auth/services/auth.service';
4 3
import {Router} from '@angular/router';
5 4
import {of, Subscription} from 'rxjs';
......
11 10
  templateUrl: './nav-bar.component.html',
12 11
  styleUrls: ['./nav-bar.component.scss']
13 12
})
14
export class NavBarComponent implements OnInit, OnDestroy {
15

  
16
  showLogin = false;
17
  subscription: Subscription[] = [];
18
  loggedIn = false;
13
export class NavBarComponent implements OnInit {
19 14

  
20 15
  constructor(
21 16
    private authService: AuthService,
......
25 20
  }
26 21

  
27 22
  ngOnInit(): void {
28
    this.userState.getLoggedIn$().subscribe(res => {
29
      this.loggedIn = res;
30
    });
31
  }
32

  
33
  ngOnDestroy(): void {
34
    this.subscription.forEach(subs => subs.unsubscribe());
35
  }
36

  
37
  showLoginFunction(): void {
38
    this.showLogin = true;
39
  }
40

  
41
  completeLogin(loginForm: LoginForm): void {
42
    this.subscription[2] = this.authService.doLogin({
43
      username: loginForm.username,
44
      password: loginForm.password
45
    })
46
      .pipe(
47
        switchMap(res => {
48
          if (res) {
49
            return this.authService.getUserState();
50
          } else {
51
            return of(false);
52
          }
53
        })
54
      ).subscribe(
55
        res => {
56
          if (res) {
57
            console.log(res);
58
            this.showLogin = false;
59
            this.userState.setLoggedIn(true);
60
            this.subscription[2].unsubscribe();
61
          }
62
        }
63
      );
64 23
  }
65 24

  
66 25
  logOut(): void {

Také k dispozici: Unified diff