邮件API
This commit is contained in:
23
src/main/java/com/mini/capi/config/LoginInterceptor.java
Normal file
23
src/main/java/com/mini/capi/config/LoginInterceptor.java
Normal file
@@ -0,0 +1,23 @@
|
||||
package com.mini.capi.config;
|
||||
|
||||
import jakarta.servlet.http.HttpServletRequest;
|
||||
import jakarta.servlet.http.HttpServletResponse;
|
||||
import jakarta.servlet.http.HttpSession;
|
||||
import org.springframework.web.servlet.HandlerInterceptor;
|
||||
|
||||
public class LoginInterceptor implements HandlerInterceptor {
|
||||
|
||||
|
||||
@Override
|
||||
public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception {
|
||||
String cPath = request.getContextPath();
|
||||
HttpSession session = request.getSession();
|
||||
Object currentUser = session.getAttribute("currentUser");
|
||||
if (currentUser != null) {
|
||||
return true;
|
||||
} else {
|
||||
response.sendRedirect(cPath + "/login");
|
||||
return false; // 拦截
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,14 +1,33 @@
|
||||
package com.mini.capi.config;
|
||||
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
|
||||
import org.springframework.web.servlet.config.annotation.ViewControllerRegistry;
|
||||
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;
|
||||
|
||||
@Configuration
|
||||
public class WebMvcConfig implements WebMvcConfigurer{
|
||||
public class WebMvcConfig implements WebMvcConfigurer {
|
||||
|
||||
@Override
|
||||
public void addViewControllers(ViewControllerRegistry registry) {
|
||||
// 访问根路径 "/" 时,自动重定向到 Swagger UI
|
||||
registry.addRedirectViewController("/", "/login");
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void addInterceptors(InterceptorRegistry registry) {
|
||||
// 注册登录拦截器
|
||||
registry.addInterceptor(new LoginInterceptor())
|
||||
.addPathPatterns("/**") // 拦截所有路径
|
||||
.excludePathPatterns( // 排除不需要拦截的路径
|
||||
"/", // 登录页
|
||||
"/login", // 登录页
|
||||
"/biz/userLogin", // 登录接口
|
||||
"/static/**", // 静态资源(CSS、JS、图片等)
|
||||
"/erpApi/**",
|
||||
"/appApi/**",
|
||||
"/jobApi/**"
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user