当前位置:网站首页>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";
}
}
边栏推荐
- ORA-01153 :激活了不兼容的介质恢复
- DPVS fullnat mode kept
- Mysql5.7.31 user defined installation details
- idea设置mapper映射文件的模板
- 使用VS2022編譯Telegram桌面端(tdesktop)
- How ASA configures port mapping and pat
- 基于OpenVINOTM开发套件“无缝”部署PaddleNLP模型
- 7. common instructions (Part 2): common operations of v-on, v-bind and V-model
- Understanding of prototypes and prototype chains
- darkent2ncnn出错
猜你喜欢

【TSP问题】基于Hopfield神经网络求解旅行商问题附Matlab代码

leetcode. 14 --- longest public prefix

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

Analyze the five root causes of product development failure

Shenzhen Taipower: the way of "communication" of the United Nations

Cloud rendering and Intel jointly create the "core" era of cloud rendering

After being trapped by the sequelae of the new crown for 15 months, Stanford Xueba was forced to miss the graduation ceremony. Now he still needs to stay in bed for 16 hours every day: I should have e

When installing PSU /usr/bin/ld:warning: -z lazload ignore

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

1-10Vmware构建自定义的网络架构
随机推荐
1-9network configuration in VMWare
1-11Vmware虚拟机常见的问题解决
86. (cesium chapter) cesium overlay surface receiving shadow effect (gltf model)
What do SMT operators do? operating duty?
The development context of Ba Kong Yuan universe industry
Drag the mouse to rotate the display around an object
Use Coe_ load_ sql_ profile. SQL fixed execution plan
DPVS fullnat mode kept
学习识别对话式问答中的后续问题
使用VS2022編譯Telegram桌面端(tdesktop)
[OEM special event] in the summer of "core cleaning", there are prize papers
Redisson 3.17.4 发布
JS to input the start time and end time, output the number of seasons, and print the corresponding month and year
anchor free dection简介
leetcode. 14 --- longest public prefix
【OEM专场活动】清“芯”夏日,有奖征文
ffmpeg 版本切换
渲云携手英特尔,共创云渲染“芯”时代
QT excellent open source project 9: qtox
Law and self-regulation in the meta universe