[webapp,manager] 路由守卫,升级sureness
This commit is contained in:
@@ -108,7 +108,7 @@
|
||||
<dependency>
|
||||
<groupId>com.usthe.sureness</groupId>
|
||||
<artifactId>spring-boot-starter-sureness</artifactId>
|
||||
<version>1.0.0-beta.2</version>
|
||||
<version>1.0.6</version>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
|
||||
|
||||
@@ -7,11 +7,11 @@
|
||||
resourceRole:
|
||||
- /account/auth/refresh===post===[role1,role2,role3,role4]
|
||||
|
||||
# load api resource which do not need be protected, means them need be excluded.
|
||||
# load api resource which do not need protected, means them need be excluded.
|
||||
# these api resource can be access by everyone
|
||||
excludedResource:
|
||||
- /**===*
|
||||
- /account/auth/form===post
|
||||
- /i18n/**===get
|
||||
- /**/*.html===get
|
||||
- /**/*.js===get
|
||||
- /**/*.css===get
|
||||
|
||||
27
web-app/src/app/core/guard/detect-auth-guard.ts
Normal file
27
web-app/src/app/core/guard/detect-auth-guard.ts
Normal file
@@ -0,0 +1,27 @@
|
||||
import {ActivatedRouteSnapshot, CanActivate, Router, RouterStateSnapshot, UrlTree} from "@angular/router";
|
||||
import {Observable} from "rxjs";
|
||||
import {Injectable} from "@angular/core";
|
||||
import {LocalStorageService} from "../../service/local-storage.service";
|
||||
import {NzNotificationService} from "ng-zorro-antd/notification";
|
||||
|
||||
@Injectable({
|
||||
providedIn: 'root'
|
||||
})
|
||||
export class DetectAuthGuard implements CanActivate {
|
||||
|
||||
constructor(private localStorageSvc : LocalStorageService,
|
||||
private notifySvc: NzNotificationService,
|
||||
private router: Router) { }
|
||||
|
||||
canActivate(route: ActivatedRouteSnapshot, state: RouterStateSnapshot):
|
||||
Observable<boolean | UrlTree> | Promise<boolean | UrlTree> | boolean | UrlTree {
|
||||
let activate = this.localStorageSvc.hasAuthorizationToken();
|
||||
if (!activate) {
|
||||
setTimeout(() => {
|
||||
this.notifySvc.warning('请先登陆!','')
|
||||
this.router.navigateByUrl('/passport/login');
|
||||
});
|
||||
}
|
||||
return activate;
|
||||
}
|
||||
}
|
||||
@@ -1,6 +1,5 @@
|
||||
import { NgModule } from '@angular/core';
|
||||
import { RouterModule, Routes } from '@angular/router';
|
||||
import { SimpleGuard } from '@delon/auth';
|
||||
import { environment } from '@env/environment';
|
||||
// layout
|
||||
import { LayoutBasicComponent } from '../layout/basic/basic.component';
|
||||
@@ -14,13 +13,14 @@ import { UserLockComponent } from './passport/lock/lock.component';
|
||||
import { UserLoginComponent } from './passport/login/login.component';
|
||||
import { UserRegisterResultComponent } from './passport/register-result/register-result.component';
|
||||
import { UserRegisterComponent } from './passport/register/register.component';
|
||||
import {DetectAuthGuard} from "../core/guard/detect-auth-guard";
|
||||
|
||||
const routes: Routes = [
|
||||
{
|
||||
path: '',
|
||||
component: LayoutBasicComponent,
|
||||
// 路由守卫 在路由之前判断是否有认证或者权限进入此路由
|
||||
// canActivate: [SimpleGuard],
|
||||
canActivate: [DetectAuthGuard],
|
||||
children: [
|
||||
// todo 根据路由自动生成面包屑
|
||||
{ path: '', redirectTo: 'dashboard', pathMatch: 'full'},
|
||||
|
||||
@@ -35,6 +35,10 @@ export class LocalStorageService {
|
||||
return this.putData(Authorization, token);
|
||||
}
|
||||
|
||||
public hasAuthorizationToken() {
|
||||
return localStorage.getItem(Authorization) === null;
|
||||
}
|
||||
|
||||
public clear() {
|
||||
localStorage.clear();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user