Projekt

Obecné

Profil

« Předchozí | Další » 

Revize 2c5da396

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

Re #8469 - Improvment security - implementace

  • authGuard and roleGuard final version
    + usage of localStorage for fields
    + loading properties form cookies to state

Zobrazit rozdíly:

src/app/login/components/login.component.ts
4 4
import {of, Subscription} from 'rxjs';
5 5
import {AuthService} from '../../auth/services/auth.service';
6 6
import {Router} from '@angular/router';
7
import {UserState} from '../../auth/states/user.state';
8 7

  
9 8
@Component({
10 9
  selector: 'app-login',
......
19 18
  constructor(
20 19
    private formBuilder: FormBuilder,
21 20
    private authService: AuthService,
22
    private router: Router,
23
    private userState: UserState
21
    private router: Router
24 22
  ) {
25 23
  }
26 24

  
......
29 27
      username: ['', [Validators.required]],
30 28
      password: ['', Validators.required]
31 29
    });
30
    this.userRedirect();
32 31
  }
33 32

  
34 33
  doLogin(): void {
......
39 38
      })
40 39
        .pipe(
41 40
          switchMap(res => {
41
            console.log(res);
42 42
            if (res) {
43
              console.log('Login getUserState');
43 44
              return this.authService.getUserState();
44 45
            } else {
45 46
              return of(false);
......
47 48
          })
48 49
        ).subscribe(
49 50
          res => {
51
            console.log(res);
50 52
            if (res) {
51
              console.log(res);
52
              this.userState.setLoggedIn(true);
53 53
              this.subscription[2].unsubscribe();
54 54
              this.router.navigate(['/dashboard'])
55 55
            }
......
57 57
        );
58 58
    }
59 59
  }
60

  
61
  userRedirect(): void {
62
    console.log('Login redirect');
63
    if (this.authService.getUser()){
64
      console.log('Redirect to dashboard!');
65
      this.router.navigate(['/dashboard']);
66
    }
67
  }
60 68
}

Také k dispozici: Unified diff