增加用户登录校验

master
heminjian502 2 years ago
parent c88325d6b1
commit 52b2335556

@ -8,6 +8,7 @@ import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.autoconfigure.jdbc.DataSourceAutoConfiguration;
import org.springframework.boot.web.embedded.tomcat.TomcatServletWebServerFactory;
import org.springframework.boot.web.servlet.ServletComponentScan;
import org.springframework.context.annotation.Bean;
/**
@ -16,6 +17,7 @@ import org.springframework.context.annotation.Bean;
* @author ruoyi
*/
@SpringBootApplication(exclude = { DataSourceAutoConfiguration.class })
@ServletComponentScan
public class RuoYiApplication
{
public static void main(String[] args)

@ -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();
}
}

@ -71,4 +71,6 @@ public interface ITDoctorService
* @return
*/
public AppDoctorResp selectAppDoctorDetailById(Long id);
public TDoctor selectTDoctorByPhone(String phone);
}

@ -134,4 +134,9 @@ public class TDoctorServiceImpl implements ITDoctorService
public AppDoctorResp selectAppDoctorDetailById(Long id) {
return tDoctorMapper.selectAppDoctorDetailById(id);
}
@Override
public TDoctor selectTDoctorByPhone(String phone) {
return tDoctorMapper.selectTDoctorByPhone(phone);
}
}

Loading…
Cancel
Save