当前位置:网站首页>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";
}
}
边栏推荐
- Solution to component stele in SMT chip processing
- 1-11solutions to common problems of VMware virtual machine
- What is micro service
- Cloud rendering and Intel jointly create the "core" era of cloud rendering
- Things / phenomena / things / things / situations / appearances
- mtb13_Perform extract_blend_Super{Candidate(PrimaryAlternate)_Unique(可NULL过滤_Foreign_index_granulari
- Function and principle of SPI solder paste inspection machine
- The problem of low video memory in yolov5 accelerated multi GPU training
- 1-10vmware builds customized network architecture
- Machine vision: illuminating "intelligence" and creating a new "vision" world
猜你喜欢

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
![[image detection] vascular tracking and diameter estimation based on Gaussian process and Radon transform with matlab code](/img/1d/511dceb9decd73976d577af991afc9.png)
[image detection] vascular tracking and diameter estimation based on Gaussian process and Radon transform with matlab code

Law and self-regulation in the meta universe

学习识别对话式问答中的后续问题

7. common instructions (Part 2): common operations of v-on, v-bind and V-model

被新冠后遗症困住15个月后,斯坦福学霸被迫缺席毕业典礼,现仍需每天卧床16小时:我本该享受20岁的人生啊...

渲云携手英特尔,共创云渲染“芯”时代

No executorfactory found to execute the application

1-9network configuration in VMWare

flink报错:No ExecutorFactory found to execute the application
随机推荐
Correct writing methods of case, number and punctuation in Chinese and English papers
2021-04-28
Some basic uses of mongodb
用js根据当前季度获取上一季度
深圳台电:联合国的“沟通”之道
Drag the mouse to rotate the display around an object
Setting up a cluster environment under Linux (2) -- installing MySQL under Linux
How to bypass SSL authentication
DNS review
Methods of modifying elements in JS array
Datetimeformatter and localdatetime
19c installing PSU 19.12
How to deliver a shelter hospital within 48 hours?
从进程的角度来解释 输入URL后浏览器会发生什么?
1-10Vmware构建自定义的网络架构
SQL中只要用到聚合函数就一定要用到group by 吗?
leetcode.14 --- 最长公共前缀
Circuit board edge removal - precautions for V-CUT splitting machine
1-11solutions to common problems of VMware virtual machine
Deploy Ogg on the same machine and test