Subject subject = SecurityUtils.getSubject();
UsernamePasswordToken usernamePasswordToken = new UsernamePasswordToken(userInfo.getUserName(),
userInfo.getPassword(), false);
try {
subject.login(usernamePasswordToken);
} catch (IncorrectCredentialsException e) {
return AjaxResult.error("密码错误");
}catch (UnknownAccountException e){
UserBasicInfo where = new UserBasicInfo();
where.setIdCardNo(ArithmeticAPI.base64Encode(userInfo.getUserName()));
List<HashMap<String, Object>> userBasicInfos = userBasicInfoService.findUserBasicInfoPage(where);
if (userBasicInfos.size() > 0) {
UserInfo where_user = new UserInfo();
where_user.setUserId(String.valueOf(userBasicInfos.get(0).get("userId")));
HashMap<String,Object> user = userService.findUserInfoPage(where_user).get(0);
UsernamePasswordToken usernamePasswordToken2 = new UsernamePasswordToken(String.valueOf(user.get("userName")),
userInfo.getPassword(), false);
subject.login(usernamePasswordToken2);
}else {
return AjaxResult.error("该账号不存在");
}
}
ShiroUser shiroUser = (ShiroUser) subject.getPrincipal();
subject.getSession().setAttribute("USER_NAME", shiroUser.getUserName());
return AjaxResult.success("登入成功");
shiro 多字段作登录名登录
最新推荐文章于 2022-08-11 16:08:55 发布