bug fixing
This commit is contained in:
@@ -22,6 +22,7 @@ export class JwtInterceptor implements HttpInterceptor {
|
||||
|
||||
const token = this.store.selectSnapshot<string>(AppState.getToken);
|
||||
|
||||
console.info("using token: ", token);
|
||||
if (token) {
|
||||
// clone the incoming request and add JWT token in the cloned request's Authorization Header
|
||||
request = request.clone({
|
||||
|
||||
@@ -22,6 +22,11 @@ export const RegistrationErrors ={
|
||||
MAX_SEAT_COUNT_EXCEEDED : 8,
|
||||
EVENT_UNAVAILABLE : 9,
|
||||
ALREADY_REGISTERED : 10,
|
||||
EVENT_START_DATE_IN_PAST : 11,
|
||||
EVENT_NOT_FOUND: 12,
|
||||
ALREADY_CANCELLED: 13,
|
||||
ALREADY_DELETED: 14,
|
||||
CANCEL_TIME_LIMIT_REACHED: 15
|
||||
}
|
||||
|
||||
export interface TimeTableFilter {
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
<fit-navigation></fit-navigation>
|
||||
<div class="container " >
|
||||
<div class="row ">
|
||||
<div class="col-12">Bejelentkezve: {{username | async}}</div>
|
||||
<div class="col-12">Bejelentkezve: {{(user | async).username}} ({{(user | async).card}})</div>
|
||||
</div>
|
||||
<router-outlet></router-outlet>
|
||||
</div>
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
import { Component, OnInit } from '@angular/core';
|
||||
import {Select} from "@ngxs/store";
|
||||
import {AppState} from "../../state/app.state";
|
||||
import {AppState, Identity} from "../../state/app.state";
|
||||
import {Observable} from "rxjs";
|
||||
|
||||
@Component({
|
||||
@@ -9,7 +9,7 @@ import {Observable} from "rxjs";
|
||||
styleUrls: ['./secured-layout.component.scss']
|
||||
})
|
||||
export class SecuredLayoutComponent implements OnInit {
|
||||
@Select(AppState.getUsername) public username: Observable<string>;
|
||||
@Select(AppState.getUser) public user: Observable<Identity>;
|
||||
|
||||
constructor() { }
|
||||
|
||||
|
||||
@@ -89,11 +89,15 @@ export class EventDetailsComponent implements OnInit {
|
||||
break;
|
||||
case RegistrationErrors.MAX_SEAT_COUNT_EXCEEDED:
|
||||
case RegistrationErrors.TICKET_INSUFFICIENT:
|
||||
case RegistrationErrors.TICKET_NOT_FOUND:
|
||||
message = "Nem rendelkezik megfelelő bérlettel!"
|
||||
break;
|
||||
case RegistrationErrors.NO_FREE_SEATS:
|
||||
message = "Nincs több szabad hely!"
|
||||
break;
|
||||
case RegistrationErrors.EVENT_START_DATE_IN_PAST:
|
||||
message = "Nem lehet regisztrálni! Az esemény már elkezdődött!"
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -109,8 +113,18 @@ export class EventDetailsComponent implements OnInit {
|
||||
this.toastr.success("Sikeres lemondás", "Lemondás")
|
||||
this.goBack();
|
||||
},
|
||||
() => {
|
||||
this.toastr.error("Hiba történt", "Lemondás")
|
||||
(error) => {
|
||||
let status = error.status;
|
||||
let code = error?.error?.code;
|
||||
let message = "Hiba történt";
|
||||
if (status == 400) {
|
||||
switch (code) {
|
||||
case RegistrationErrors.CANCEL_TIME_LIMIT_REACHED:
|
||||
message = "Már nem lehet lemondani a regisztrációt!";
|
||||
break;
|
||||
}
|
||||
}
|
||||
this.toastr.error(message, "Lemondás")
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
@@ -11,11 +11,11 @@
|
||||
</div>
|
||||
<div class="row">
|
||||
<div class="col-lg-3 col-sm-12 app-font-weight-bold"><span class="title">Edzés kezdési időpontja</span></div>
|
||||
<div class="col-lg-9 col-sm-12"><span>{{registration.event.start * 1000 | date:'yyyy.MM.dd HH:mm'}}</span></div>
|
||||
<div class="col-lg-9 col-sm-12"><span>{{registration.event.start | eventDate:'datetime'}}</span></div>
|
||||
</div>
|
||||
<div class="row">
|
||||
<div class="col-lg-3 col-sm-12 app-font-weight-bold"><span class="title">Edzés vége</span></div>
|
||||
<div class="col-lg-9 col-sm-12"><span>{{registration.event.end * 1000 | date:'yyyy.MM.dd HH:mm'}}</span></div>
|
||||
<div class="col-lg-9 col-sm-12"><span>{{registration.event.end | eventDate:'datetime'}}</span></div>
|
||||
</div>
|
||||
<div class="row">
|
||||
<div class="col-lg-3 col-sm-12 app-font-weight-bold"><span class="title">Férőhelyek száma</span></div>
|
||||
|
||||
@@ -6,9 +6,12 @@ import {
|
||||
import {TimeTableFilter} from "../app.types";
|
||||
import jwtDecode, {JwtPayload} from "jwt-decode";
|
||||
|
||||
|
||||
export interface AppStateModel {
|
||||
export interface Identity{
|
||||
username: string;
|
||||
card: string;
|
||||
}
|
||||
export interface AppStateModel {
|
||||
user: Identity
|
||||
token: string;
|
||||
filterTimeTable: FilterTimeTableAction;
|
||||
}
|
||||
@@ -17,7 +20,7 @@ export interface AppStateModel {
|
||||
@State<AppStateModel>({
|
||||
name: "app",
|
||||
defaults: {
|
||||
username: null,
|
||||
user: null,
|
||||
token: null,
|
||||
filterTimeTable: {
|
||||
idTrainer: -1,
|
||||
@@ -37,8 +40,8 @@ export class AppState {
|
||||
}
|
||||
|
||||
@Selector()
|
||||
public static getUsername(state: AppStateModel): string {
|
||||
return state.username;
|
||||
public static getUser(state: AppStateModel): Identity {
|
||||
return state.user;
|
||||
}
|
||||
|
||||
@Selector()
|
||||
@@ -60,18 +63,22 @@ export class AppState {
|
||||
@Action(LoginAction)
|
||||
dispatchLogin(ctx: StateContext<AppStateModel>, {token}: LoginAction): void {
|
||||
let username = null;
|
||||
let card = null;
|
||||
|
||||
try {
|
||||
const decoded = jwtDecode<JwtPayload & { username: string }>(token);
|
||||
const decoded = jwtDecode<JwtPayload & { username: string , card: string}>(token);
|
||||
username = decoded?.username;
|
||||
card = decoded?.card;
|
||||
} catch (e) {
|
||||
// user not logged in
|
||||
token = null;
|
||||
username = null;
|
||||
card = null;
|
||||
}
|
||||
|
||||
|
||||
ctx.patchState({
|
||||
username: username,
|
||||
user: (username && card) ? {username: username, card: card } : null,
|
||||
token: token
|
||||
});
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user