Vérification des droits d'admin pour ajouter
avions/dz/type de sauts
This commit is contained in:
@@ -18,14 +18,10 @@ export class AppComponent implements OnInit {
|
||||
public currentUser: User;
|
||||
public version: string;
|
||||
|
||||
constructor(
|
||||
private router: Router,
|
||||
private authenticationService: AuthenticationService,
|
||||
private serviceComm: ServiceComm
|
||||
) {
|
||||
this.authenticationService.currentUser.subscribe(
|
||||
x => (this.currentUser = x)
|
||||
);
|
||||
constructor(private router: Router,
|
||||
private authenticationService: AuthenticationService,
|
||||
private serviceComm: ServiceComm) {
|
||||
this.authenticationService.currentUser.subscribe(user => { this.currentUser = user; });
|
||||
|
||||
ConfigurationHelper.settings.subscribe(settings =>
|
||||
{
|
||||
|
||||
@@ -68,42 +68,42 @@ const appRoutes: Routes = [
|
||||
{
|
||||
path: "summary",
|
||||
component: SummaryComponent,
|
||||
canActivate: [AuthGuardService],
|
||||
canActivate: [AuthGuardService]
|
||||
},
|
||||
{
|
||||
path: "jumps",
|
||||
component: ListOfJumpsComponent,
|
||||
canActivate: [AuthGuardService],
|
||||
canActivate: [AuthGuardService]
|
||||
},
|
||||
{
|
||||
path: "dzs",
|
||||
component: ListOfDzsComponent,
|
||||
canActivate: [AuthGuardService],
|
||||
canActivate: [AuthGuardService]
|
||||
},
|
||||
{
|
||||
path: "newjump",
|
||||
component: NewJumpComponent,
|
||||
canActivate: [AuthGuardService],
|
||||
canActivate: [AuthGuardService]
|
||||
},
|
||||
{
|
||||
path: "aircrafts",
|
||||
component: ListOfAircraftsComponent,
|
||||
canActivate: [AuthGuardService],
|
||||
canActivate: [AuthGuardService]
|
||||
},
|
||||
{
|
||||
path: "jumpTypes",
|
||||
component: ListOfJumpTypesComponent,
|
||||
canActivate: [AuthGuardService],
|
||||
canActivate: [AuthGuardService]
|
||||
},
|
||||
{
|
||||
path: "gears",
|
||||
component: ListOfGearsComponent,
|
||||
canActivate: [AuthGuardService],
|
||||
canActivate: [AuthGuardService]
|
||||
},
|
||||
{
|
||||
path: "user",
|
||||
component: UserProfileComponent,
|
||||
canActivate: [AuthGuardService],
|
||||
canActivate: [AuthGuardService]
|
||||
},
|
||||
|
||||
{ path: "login", component: LoginComponent },
|
||||
|
||||
@@ -58,7 +58,6 @@ export class CreateUserComponent implements OnInit {
|
||||
this.invalidForm = false;
|
||||
this.submitted = true;
|
||||
|
||||
// stop here if form is invalid
|
||||
if (this.createForm.invalid) {
|
||||
this.invalidForm = true;
|
||||
return;
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
<div class="content">
|
||||
<div *ngIf="dataSourceTable != null else loading">
|
||||
<button mat-raised-button color="accent" (click)="openDialogToAdd()">Add a aircraft</button>
|
||||
<button mat-raised-button color="accent" (click)="openDialogToAdd()" *ngIf="isUserAdmin == true">Add a aircraft</button>
|
||||
|
||||
<table mat-table [dataSource]="dataSourceTable">
|
||||
<ng-container matColumnDef="id">
|
||||
|
||||
@@ -3,11 +3,12 @@ import { MatPaginator } from '@angular/material/paginator';
|
||||
import { MatTableDataSource } from '@angular/material/table';
|
||||
import { MatDialog } from '@angular/material/dialog';
|
||||
|
||||
import { AircraftResp } from '../../models/aircraft';
|
||||
import { AircraftService } from '../../services/aircraft.service';
|
||||
import { ServiceComm } from '../../services/service-comm.service';
|
||||
import { AuthenticationService } from '../../services/authentication.service';
|
||||
import { NewAircraftComponent } from '../new-aircraft/new-aircraft.component';
|
||||
import { AddAction } from '../../models/add-action.enum';
|
||||
import { AircraftResp } from '../../models/aircraft';
|
||||
|
||||
@Component({
|
||||
selector: 'app-list-of-aircrafts',
|
||||
@@ -18,13 +19,15 @@ export class ListOfAircraftsComponent implements OnInit {
|
||||
public displayedColumns: Array<string> = ['id', 'name', 'imageData'];
|
||||
public dataSourceTable: MatTableDataSource<AircraftResp>;
|
||||
public resultsLength = 0;
|
||||
public isUserAdmin: boolean;
|
||||
@ViewChild(MatPaginator, { static: true }) paginator: MatPaginator;
|
||||
|
||||
constructor(
|
||||
private serviceApi: AircraftService,
|
||||
private serviceComm: ServiceComm,
|
||||
public dialog: MatDialog
|
||||
) { }
|
||||
constructor(private serviceApi: AircraftService,
|
||||
private serviceComm: ServiceComm,
|
||||
private authenticationService: AuthenticationService,
|
||||
public dialog: MatDialog) {
|
||||
this.isUserAdmin = this.authenticationService.currentUserValue.IsAdmin;
|
||||
}
|
||||
|
||||
ngOnInit() {
|
||||
this.serviceComm.refreshRequest.subscribe(action => {
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
<div class="content">
|
||||
<div *ngIf="dataSourceTable != null else loading">
|
||||
<button mat-raised-button color="accent" (click)="openDialogToAdd()">Add a drop zone</button>
|
||||
<button mat-raised-button color="accent" (click)="openDialogToAdd()" *ngIf="isUserAdmin == true">Add a drop zone</button>
|
||||
|
||||
<table mat-table [dataSource]="dataSourceTable">
|
||||
<ng-container matColumnDef="isfavorite">
|
||||
|
||||
@@ -7,6 +7,7 @@ import { AddAction } from '../../models/add-action.enum';
|
||||
import { DropZoneResp } from '../../models/dropzone';
|
||||
import { DropzoneService } from '../../services/dropzone.service';
|
||||
import { ServiceComm } from '../../services/service-comm.service';
|
||||
import { AuthenticationService } from '../../services/authentication.service';
|
||||
import { NewDropZoneComponent } from '../new-drop-zone/new-drop-zone.component';
|
||||
|
||||
@Component({
|
||||
@@ -23,14 +24,16 @@ export class ListOfDzsComponent implements OnInit {
|
||||
'type',
|
||||
];
|
||||
public dataSourceTable: MatTableDataSource<DropZoneResp>;
|
||||
public isUserAdmin: boolean;
|
||||
public resultsLength = 0;
|
||||
@ViewChild(MatPaginator, { static: true }) paginator: MatPaginator;
|
||||
|
||||
constructor(
|
||||
private serviceApi: DropzoneService,
|
||||
private serviceComm: ServiceComm,
|
||||
public dialog: MatDialog
|
||||
) { }
|
||||
constructor(private serviceApi: DropzoneService,
|
||||
private serviceComm: ServiceComm,
|
||||
private authenticationService: AuthenticationService,
|
||||
public dialog: MatDialog) {
|
||||
this.isUserAdmin = this.authenticationService.currentUserValue.IsAdmin;
|
||||
}
|
||||
|
||||
ngOnInit() {
|
||||
this.serviceComm.refreshRequest.subscribe((action) => {
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
<div class="content">
|
||||
<div *ngIf="dataSourceTable != null else loading">
|
||||
<button mat-raised-button color="accent" (click)="openDialogToAdd()">Add a jump type</button>
|
||||
<button mat-raised-button color="accent" (click)="openDialogToAdd()" *ngIf="isUserAdmin == true">Add a jump type</button>
|
||||
|
||||
<table mat-table [dataSource]="dataSourceTable">
|
||||
<ng-container matColumnDef="id">
|
||||
|
||||
@@ -7,6 +7,7 @@ import { AddAction } from "../../models/add-action.enum";
|
||||
import { JumpTypeResp } from "../../models/jumpType";
|
||||
import { JumpTypeService } from "../../services/jump-type.service";
|
||||
import { ServiceComm } from "../../services/service-comm.service";
|
||||
import { AuthenticationService } from '../../services/authentication.service';
|
||||
import { NewJumpTypeComponent } from "../new-jump-type/new-jump-type.component";
|
||||
|
||||
@Component({
|
||||
@@ -17,14 +18,16 @@ import { NewJumpTypeComponent } from "../new-jump-type/new-jump-type.component";
|
||||
export class ListOfJumpTypesComponent implements OnInit {
|
||||
public displayedColumns: Array<string> = ["id", "name"];
|
||||
public dataSourceTable: MatTableDataSource<JumpTypeResp>;
|
||||
public isUserAdmin: boolean;
|
||||
public resultsLength = 0;
|
||||
@ViewChild(MatPaginator, { static: true }) paginator: MatPaginator;
|
||||
|
||||
constructor(
|
||||
private serviceApi: JumpTypeService,
|
||||
private serviceComm: ServiceComm,
|
||||
public dialog: MatDialog
|
||||
) {}
|
||||
constructor(private serviceApi: JumpTypeService,
|
||||
private serviceComm: ServiceComm,
|
||||
private authenticationService: AuthenticationService,
|
||||
public dialog: MatDialog) {
|
||||
this.isUserAdmin = this.authenticationService.currentUserValue.IsAdmin;
|
||||
}
|
||||
|
||||
ngOnInit() {
|
||||
this.serviceComm.refreshRequest.subscribe(action => {
|
||||
|
||||
@@ -43,7 +43,7 @@ export class LoginUserComponent implements OnInit, AfterViewInit {
|
||||
password: [
|
||||
'',
|
||||
[
|
||||
Validators.required /*, Validators.pattern("^[A-Za-z0-9_-]{8,15}$")*/
|
||||
Validators.required
|
||||
]
|
||||
]
|
||||
},
|
||||
|
||||
@@ -85,10 +85,8 @@ export class StatsByYearResp {
|
||||
}
|
||||
|
||||
export class StatsForLastYearResp {
|
||||
constructor(
|
||||
dataByDz: Array<StatsByDzResp>,
|
||||
dataByJumpType: Array<StatsByJumpTypeResp>
|
||||
) {
|
||||
constructor(dataByDz: Array<StatsByDzResp>,
|
||||
dataByJumpType: Array<StatsByJumpTypeResp>) {
|
||||
this.byDz = new Array<StatsByDzResp>();
|
||||
this.byJumpType = new Array<StatsByJumpTypeResp>();
|
||||
|
||||
@@ -101,10 +99,8 @@ export class StatsForLastYearResp {
|
||||
}
|
||||
|
||||
export class StatsForLastMonthResp {
|
||||
constructor(
|
||||
dataByDz: Array<StatsByDzResp>,
|
||||
dataByJumpType: Array<StatsByJumpTypeResp>
|
||||
) {
|
||||
constructor(dataByDz: Array<StatsByDzResp>,
|
||||
dataByJumpType: Array<StatsByJumpTypeResp>) {
|
||||
this.byDz = new Array<StatsByDzResp>();
|
||||
this.byJumpType = new Array<StatsByJumpTypeResp>();
|
||||
|
||||
|
||||
@@ -5,6 +5,9 @@ export class User {
|
||||
firstName: string;
|
||||
lastName: string;
|
||||
email: string;
|
||||
roles: string;
|
||||
authdata?: string;
|
||||
token?: string;
|
||||
|
||||
get IsAdmin() { return this.roles === "admin"; }
|
||||
}
|
||||
|
||||
@@ -1,23 +1,14 @@
|
||||
import { Injectable } from "@angular/core";
|
||||
import {
|
||||
CanActivate,
|
||||
Router,
|
||||
ActivatedRouteSnapshot,
|
||||
RouterStateSnapshot
|
||||
} from "@angular/router";
|
||||
import { CanActivate, Router, ActivatedRouteSnapshot, RouterStateSnapshot } from "@angular/router";
|
||||
import { AuthenticationService } from "./authentication.service";
|
||||
|
||||
@Injectable({ providedIn: "root" })
|
||||
export class AuthGuardService implements CanActivate {
|
||||
constructor(
|
||||
private router: Router,
|
||||
private authenticationService: AuthenticationService
|
||||
) {}
|
||||
constructor(private router: Router,
|
||||
private authenticationService: AuthenticationService) {}
|
||||
|
||||
public canActivate(
|
||||
route: ActivatedRouteSnapshot,
|
||||
state: RouterStateSnapshot
|
||||
) {
|
||||
public canActivate(route: ActivatedRouteSnapshot,
|
||||
state: RouterStateSnapshot) {
|
||||
const currentUser = this.authenticationService.currentUserValue;
|
||||
if (currentUser) {
|
||||
// logged in so return true
|
||||
@@ -25,10 +16,9 @@ export class AuthGuardService implements CanActivate {
|
||||
}
|
||||
|
||||
// not logged in so redirect to login page with the return url
|
||||
this.router.navigate(["/login"], {
|
||||
skipLocationChange: true,
|
||||
queryParams: { returnUrl: state.url }
|
||||
});
|
||||
this.router.navigate(["/login"],
|
||||
{skipLocationChange: true, queryParams: { returnUrl: state.url }});
|
||||
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -34,36 +34,31 @@ export class AuthenticationService extends BaseService {
|
||||
password: password
|
||||
};
|
||||
|
||||
return this.http
|
||||
.post<User>(`${this.apiUrl}/User/Authenticate`, bodyLogin, {
|
||||
headers: this.headers
|
||||
})
|
||||
.pipe(
|
||||
map(user => {
|
||||
this.pushUserToken(username, password, user);
|
||||
return user;
|
||||
})
|
||||
);
|
||||
return this.http.post<User>(`${this.apiUrl}/User/Authenticate`,
|
||||
bodyLogin,
|
||||
{ headers: this.headers })
|
||||
.pipe(map(user => {
|
||||
this.pushUserToken(username, password, user);
|
||||
return user;
|
||||
}));
|
||||
}
|
||||
|
||||
public create(newUser: User) {
|
||||
return this.http
|
||||
.post<any>(`${this.apiUrl}/User`, newUser, {
|
||||
headers: this.headers
|
||||
})
|
||||
.pipe(
|
||||
map(user => {
|
||||
this.pushUserToken(newUser.login, newUser.password, user);
|
||||
return user;
|
||||
})
|
||||
);
|
||||
return this.http.post<User>(`${this.apiUrl}/User`,
|
||||
newUser,
|
||||
{ headers: this.headers })
|
||||
.pipe(map(user => {
|
||||
this.pushUserToken(newUser.login, newUser.password, user);
|
||||
return user;
|
||||
}));
|
||||
}
|
||||
|
||||
private pushUserToken(login: string, password: string, user: any){
|
||||
// store user details and basic auth credentials in local storage to keep user logged in between page refreshes
|
||||
user.authdata = window.btoa(login + ":" + password);
|
||||
localStorage.setItem("currentUser", JSON.stringify(user));
|
||||
this.currentUserSubject.next(user);
|
||||
private pushUserToken(login: string, password: string, user: User){
|
||||
if (user && user.token) {
|
||||
user.authdata = window.btoa(login + ":" + password);
|
||||
localStorage.setItem("currentUser", JSON.stringify(user));
|
||||
this.currentUserSubject.next(user);
|
||||
}
|
||||
}
|
||||
|
||||
private alwaysLogin() {
|
||||
@@ -73,7 +68,6 @@ export class AuthenticationService extends BaseService {
|
||||
}
|
||||
|
||||
logout() {
|
||||
// remove user from local storage to log user out
|
||||
localStorage.removeItem("currentUser");
|
||||
this.currentUserSubject.next(null);
|
||||
}
|
||||
|
||||
@@ -18,16 +18,5 @@ export class BaseService {
|
||||
this.apiUrl = tmpApiUrl + '/api';
|
||||
}
|
||||
});
|
||||
|
||||
// const config: ConfigurationHelper = injector.get(ConfigurationHelper);
|
||||
// config.load(environment.env)
|
||||
// .then(() => {
|
||||
// let tmpApiUrl : string = ConfigurationHelper.settings.apiUrl;
|
||||
|
||||
// this.headers = new HttpHeaders({
|
||||
// 'Access-Control-Allow-Origin': tmpApiUrl
|
||||
// });
|
||||
// this.apiUrl = tmpApiUrl + '/api';
|
||||
// });
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user