当前位置:网站首页>Login interceptor
Login interceptor
2022-06-26 00:42:00 【-LM-】
Login interceptor
Myconfig.java
@Component
public class MyConfig implements WebMvcConfigurer {
@Override
public void addInterceptors(InterceptorRegistry registry) {
registry.addInterceptor(new LoginInterceptor()).addPathPatterns("/**").excludePathPatterns("/","/user","/login","/echarts/**","/img/**","/layui/**","/login.html","/code");
}
}
LoginInterceptor
public class LoginInterceptor implements HandlerInterceptor {
@Override
public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception {
Object user=request.getSession().getAttribute("loginUser");
if(user==null){
request.setAttribute("msg"," No authority , Please log in first !");
request.getRequestDispatcher("/login").forward(request,response);
return false;
}else{
return true;
}
}
}
LoginController
// Check the legitimacy of login user identity
@RequestMapping("/user")
public String user(@RequestParam("username") String username,
@RequestParam("password") String password,
@RequestParam("captcha") String captcha,Model model, HttpSession session,HttpServletRequest request){
session = request.getSession();
String code = (String) session.getAttribute("code");
System.out.println(code);
System.out.println(captcha);
if(!captcha.equalsIgnoreCase(code.trim())){
model.addAttribute("msg"," Verification code error ");
return "login";
}
Map<String,Object> mp = new HashMap<>();
mp.put("username",username); mp.put("password",password);
List<User> list = loginService.checkuser(mp);
if(list.size()>0){
session.setAttribute("loginUser",username);
return "index";
}else{
model.addAttribute("msg"," Wrong account or password ");
return "login";
}
}
边栏推荐
- 1-10vmware builds customized network architecture
- The development context of Ba Kong Yuan universe industry
- Tensorrt PB to UF problem
- Core ideas of SQL optimization
- “Method Not Allowed“,405问题分析及解决
- flink报错:No ExecutorFactory found to execute the application
- 防抖和节流
- "Method not allowed", 405 problem analysis and solution
- 什么是微服务
- QT custom QSlider with cursor
猜你喜欢

Flink reports error: a JNI error has occurred, please check your installation and try again

JS to input the start time and end time, output the number of seasons, and print the corresponding month and year

1-11Vmware虚拟机常见的问题解决

【图像检测】基于高斯过程和Radon变换实现血管跟踪和直径估计附matlab代码

How to design the product roadmap?

Daily question brushing record (IV)

Run the test program using rknn-toolkit-lite2 for rk3568 development board

Learn to identify follow-up questions in dialogue Q & A

Atlas200dk刷机

mtb13_ Perform extract_ blend_ Super{candidate (primaryalternate) \u unique (nullable filtering \foreign\index\granulati
随机推荐
What is micro service
Research and development practice of Kwai real-time data warehouse support system
farsync 简易测试
Ssl/tls, symmetric and asymmetric encryption, and tlsv1.3
【图像检测】基于高斯过程和Radon变换实现血管跟踪和直径估计附matlab代码
Comprehensive introduction to Simulink solver
鼠标拖拽围绕某个物体旋转展示
No executorfactory found to execute the application
11.1.2 overview of Flink_ Wordcount case
实现异步的方法
“Method Not Allowed“,405问题分析及解决
[advanced ROS] Lecture 1 Introduction to common APIs
删库跑路、“投毒”、改协议,开源有哪几大红线千万不能踩?
Redux workflow + complete code of small examples
快手实时数仓保障体系研发实践
Analyze the five root causes of product development failure
SQL中只要用到聚合函数就一定要用到group by 吗?
使用coe_load_sql_profile.sql固定执行计划
ORA-01153 :激活了不兼容的介质恢复
19c installing PSU 19.12