Commit 2f745854 authored by Quxl's avatar Quxl

增加会员登陆拦截

parent c84f2968
...@@ -29,11 +29,15 @@ public class WebMvcConfig extends WebMvcConfigurerAdapter { ...@@ -29,11 +29,15 @@ public class WebMvcConfig extends WebMvcConfigurerAdapter {
@Autowired @Autowired
private UserLoginInterceptor userLoginInterceptor; private UserLoginInterceptor userLoginInterceptor;
@Autowired
private UserLoginInterceptor memberLoginInterceptor;
@Override @Override
public void addInterceptors(InterceptorRegistry registry) { public void addInterceptors(InterceptorRegistry registry) {
registry.addInterceptor(adminLoginInterceptor).addPathPatterns("/admin/**").excludePathPatterns("/admin/login"); registry.addInterceptor(adminLoginInterceptor).addPathPatterns("/admin/**").excludePathPatterns("/admin/login");
registry.addInterceptor(userLoginInterceptor).addPathPatterns("/user/**").excludePathPatterns("/user/login"); registry.addInterceptor(userLoginInterceptor).addPathPatterns("/user/**").excludePathPatterns("/user/login");
registry.addInterceptor(memberLoginInterceptor).addPathPatterns("/member/**").excludePathPatterns("/member/login");
} }
@Override @Override
......
package com.egolm.film.config.interceptor;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import org.springframework.web.servlet.handler.HandlerInterceptorAdapter;
import com.egolm.film.config.XException;
import com.egolm.film.login.service.MemberTokenService;
@Component
public class MemberLoginInterceptor extends HandlerInterceptorAdapter {
@Autowired
private MemberTokenService tokenService;
@Override
public boolean preHandle(HttpServletRequest req, HttpServletResponse resp, Object handler) throws Exception {
if(tokenService.isLogin()) {
return super.preHandle(req, resp, handler);
} else {
throw new XException("用户未登陆");
}
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment