Compare commits

...

2 Commits

3 changed files with 32 additions and 9 deletions

View File

@ -1,7 +1,6 @@
package com.alttd.altitudeweb.database.web_db;
import org.apache.ibatis.annotations.*;
import org.jetbrains.annotations.Nullable;
import java.util.List;
import java.util.Optional;
@ -106,6 +105,6 @@ public interface PrivilegedUserMapper {
INSERT INTO privileged_users (uuid)
VALUES (#{uuid})
""")
@Options(useGeneratedKeys = true, keyProperty = "id", keyColumn = "id")
@SelectKey(statement = "SELECT LAST_INSERT_ID()", keyProperty = "id", before = false, resultType = int.class)
int createPrivilegedUser(UUID uuid);
}

View File

@ -118,18 +118,27 @@ export const routes: Routes = [
path: 'forms',
loadComponent: () => import('./pages/forms/forms.component').then(m => m.FormsComponent)
},
{
path: 'appeal/:code',
redirectTo: 'forms/appeal/:code',
pathMatch: 'full'
},
{
path: 'appeal',
redirectTo: 'forms/appeal',
pathMatch: 'full'
},
{
path: 'forms/appeal/:code',
loadComponent: () => import('./pages/forms/appeal/appeal.component').then(m => m.AppealComponent),
canActivate: [AuthGuard],
data: {requiredAuthorizations: ['SCOPE_user']}
},
{
path: 'forms/appeal',
loadComponent: () => import('./pages/forms/appeal/appeal.component').then(m => m.AppealComponent),
canActivate: [AuthGuard],
data: {
requiredAuthorizations: ['SCOPE_user']
}
data: {requiredAuthorizations: ['SCOPE_user']}
},
{
path: 'forms/sent',

View File

@ -1,9 +1,10 @@
import {Injectable} from '@angular/core';
import {ActivatedRouteSnapshot, CanActivate, Router, RouterStateSnapshot, UrlTree} from '@angular/router';
import {map, Observable} from 'rxjs';
import {from, isObservable, map, Observable, of, switchMap} from 'rxjs';
import {AuthService} from '@services/auth.service';
import {MatDialog} from '@angular/material/dialog';
import {LoginDialogComponent} from '@shared-components/login/login.component';
import {catchError} from 'rxjs/operators';
@Injectable({
providedIn: 'root'
@ -21,6 +22,20 @@ export class AuthGuard implements CanActivate {
route: ActivatedRouteSnapshot,
state: RouterStateSnapshot
): Observable<boolean | UrlTree> | Promise<boolean | UrlTree> | boolean | UrlTree {
const code = route.paramMap.get('code');
if (code) {
return this.authService.login(code).pipe(
switchMap(() => {
const result = this.canActivateInternal(route, state);
return isObservable(result) ? result : result instanceof Promise ? from(result) : of(result);
}),
catchError(() => of(this.router.createUrlTree(['/'])))
);
}
return this.canActivateInternal(route, state);
}
private canActivateInternal(route: ActivatedRouteSnapshot, state: RouterStateSnapshot): Observable<boolean | UrlTree> | Promise<boolean | UrlTree> | boolean | UrlTree {
if (!this.authService.isAuthenticated$()) {
this.router.createUrlTree(['/']);
const dialogRef = this.dialog.open(LoginDialogComponent, {