增加用户登录校验
parent
c88325d6b1
commit
52b2335556
@ -0,0 +1,55 @@
|
||||
package com.ruoyi.web.controller.tool;
|
||||
|
||||
import com.ruoyi.common.core.domain.entity.SysUser;
|
||||
import com.ruoyi.common.core.domain.model.LoginUser;
|
||||
import com.ruoyi.common.exception.ServiceException;
|
||||
import com.ruoyi.system.domain.TDoctor;
|
||||
import com.ruoyi.system.service.ITDoctorService;
|
||||
import com.ruoyi.system.service.impl.UserTokenService;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.core.annotation.Order;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import javax.servlet.*;
|
||||
import javax.servlet.annotation.WebFilter;
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import java.io.IOException;
|
||||
import java.util.Objects;
|
||||
|
||||
@Order(1)
|
||||
@WebFilter(filterName = "loginFilter", urlPatterns = "/api/app/*")
|
||||
public class LoginFilter implements Filter {
|
||||
private static final Logger logger = LoggerFactory.getLogger(LoginFilter.class);
|
||||
@Autowired
|
||||
private UserTokenService userTokenService;
|
||||
|
||||
@Resource
|
||||
private ITDoctorService tDoctorService;
|
||||
|
||||
@Override
|
||||
public void init(FilterConfig filterConfig) throws ServletException {
|
||||
Filter.super.init(filterConfig);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void doFilter(ServletRequest servletRequest, ServletResponse servletResponse, FilterChain filterChain) throws IOException, ServletException {
|
||||
String currentUrl = ((HttpServletRequest) servletRequest).getServletPath();
|
||||
if (!currentUrl.equals("/api/app/hospital/list")) {
|
||||
LoginUser loginUser = userTokenService.getLoginUser((HttpServletRequest) servletRequest);
|
||||
SysUser user = loginUser.getUser();
|
||||
TDoctor tDoctor = tDoctorService.selectTDoctorByPhone(user.getPhonenumber());
|
||||
if (Objects.isNull(tDoctor) || "2".equals(tDoctor.getDelFlag())) {
|
||||
logger.info("doctor has been deleted , doctor info :{}", tDoctor);
|
||||
throw new ServiceException("用户已被删除");
|
||||
}
|
||||
}
|
||||
filterChain.doFilter(servletRequest, servletResponse);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void destroy() {
|
||||
Filter.super.destroy();
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue