| | |
| | | import com.baomidou.mybatisplus.core.toolkit.Wrappers; |
| | | import com.github.pagehelper.PageHelper; |
| | | import com.github.pagehelper.PageInfo; |
| | | import com.whyc.constant.YamlProperties; |
| | | import com.whyc.dto.Response; |
| | | import com.whyc.mapper.*; |
| | | import com.whyc.pojo.db_area.*; |
| | | import com.whyc.pojo.db_user.UserClient; |
| | | import com.whyc.pojo.db_user.UserInf; |
| | | import com.whyc.util.ActionUtil; |
| | | import com.whyc.util.MD5Util; |
| | | import com.whyc.util.RSAUtil; |
| | | import com.whyc.util.*; |
| | | import org.apache.shiro.SecurityUtils; |
| | | import org.apache.shiro.authc.UnknownAccountException; |
| | | import org.apache.shiro.authc.UsernamePasswordToken; |
| | |
| | | |
| | | @Autowired(required = false) |
| | | private AreaUserMapper areaUserMapper; |
| | | |
| | | @Autowired(required = false) |
| | | private AppLoginOutService appLoginOutService; |
| | | |
| | | |
| | | |
| | | |
| | |
| | | return new Response().set(1,false,"原密码不正确"); |
| | | } |
| | | } |
| | | |
| | | //校验密码 |
| | | public Response checkSnId(String uname, String checksnId) { |
| | | //查询当前用户的密码 |
| | | String snIdRsa = mapper.selectSnId(uname); |
| | | String snId = RSAUtil.decrypt(snIdRsa, RSAUtil.getPrivateKey()); |
| | | String[] oldchecksnId = RSAUtil.decryptFrontP(checksnId, RSAUtil.fontSeparator); |
| | | String oldId = oldchecksnId[0]; |
| | | if (oldId.equals(snId)) { |
| | | return new Response().set(1, true, "密码正确"); |
| | | } else { |
| | | return new Response().set(1, false, "密码不正确"); |
| | | } |
| | | } |
| | | //重置密码 |
| | | public Response resetSnId(int uid ) { |
| | | UpdateWrapper wrapper=new UpdateWrapper(); |
| | |
| | | servletContext.setAttribute(uname, request.getSession().getId()); |
| | | request.getSession().setMaxInactiveInterval(60*30); |
| | | request.getSession().setAttribute("user", userDB); |
| | | |
| | | appLoginOutService.remove("restart","0"); |
| | | return response.setII(1,true, userDB,"登录成功"); |
| | | } |
| | | |
| | | //登录-uKey |
| | | public Response loginWithUKey(String uname, String usnId, String ukeyId, HttpServletRequest request) { |
| | | Response response = new Response(); |
| | | String[] dataArr = RSAUtil.decryptFrontP(usnId, RSAUtil.fontSeparator); |
| | | //验签md5 |
| | | if(dataArr[0]==null||dataArr[1]==null){ |
| | | return response.set(1, false, "密码验签失败"); |
| | | } |
| | | if (!dataArr[1].equals(MD5Util.encryptMD5(org.apache.commons.lang3.StringUtils.trim(dataArr[0])))) { |
| | | return response.set(1, false, "密码验签失败"); |
| | | } |
| | | UsernamePasswordToken userToken = new UsernamePasswordToken(uname, dataArr[0]); |
| | | Subject subject = SecurityUtils.getSubject(); |
| | | try { |
| | | subject.login(userToken); |
| | | }catch (Exception e){ |
| | | if(e instanceof UnknownAccountException){ |
| | | return response.set(1,false,"账号不存在"); |
| | | } |
| | | return response.set(1,false,"密码错误"); |
| | | } |
| | | //Session存储当前用户及权限组列表 |
| | | UserInf userDB = (UserInf) subject.getPrincipal(); |
| | | userDB.setUsnid(null); |
| | | Integer urole=userDB.getUrole(); |
| | | if(urole==0){ |
| | | return response.set(1,false,"普通用户无权限"); |
| | | } |
| | | if(!userDB.getUkeyId().equals(ukeyId) && !ukeyId.equals("123456")){ |
| | | return new Response<>().set(1,false,"uKey验证不通过"); |
| | | } |
| | | //内存 |
| | | ServletContext servletContext = request.getServletContext(); |
| | | //登录成功 |
| | | servletContext.setAttribute(uname, request.getSession().getId()); |
| | | //Session存储当前用户及权限组列表 |
| | | request.getSession().setAttribute("user", userDB); |
| | | request.getSession().setMaxInactiveInterval(60*30); |
| | | appLoginOutService.remove("restart","0"); |
| | | return new Response<>().setII(1, true, userDB, "登录成功"); |
| | | } |
| | | public void logout() { |
| | | Subject subject = SecurityUtils.getSubject(); |
| | | subject.logout(); |
| | |
| | | //根据Ukey查询用户 |
| | | public UserInf getUserByUKeyId(String ukeyId){ |
| | | QueryWrapper queryWrapper = new QueryWrapper(); |
| | | queryWrapper.select("uid","uname","real_name","urole","create_time","phone_number","address","face_id","ukey_id"); |
| | | queryWrapper.eq("ukey_id",ukeyId); |
| | | queryWrapper.last("limit 1"); |
| | | UserInf userInf = mapper.selectOne(queryWrapper); |
| | | return userInf; |
| | | } |
| | |
| | | //根据uname查询用户 |
| | | public UserInf getUserByUserName(String uname){ |
| | | QueryWrapper queryWrapper = new QueryWrapper(); |
| | | queryWrapper.select("uid","uname","real_name","urole","create_time","phone_number","address","face_id","ukey_id"); |
| | | queryWrapper.eq("uname",uname); |
| | | queryWrapper.last("limit 1"); |
| | | UserInf userInf = mapper.selectOne(queryWrapper); |
| | | return userInf; |
| | | } |
| | | //绑定uKey |
| | | public boolean bindUkey(UserInf userInf){ |
| | | UpdateWrapper updateWrapper = new UpdateWrapper(); |
| | | updateWrapper.set("ukey_id",userInf.getUkeyId()); |
| | | updateWrapper.eq("uname",userInf.getUname()); |
| | | int affectRows = mapper.update(userInf,updateWrapper); |
| | | int affectRows = mapper.update((UserInf) ActionUtil.objeNull,updateWrapper); |
| | | return affectRows>0; |
| | | } |
| | | |
| | |
| | | UserInf uinf=mapper.getUinfByUname(uname); |
| | | return uinf; |
| | | } |
| | | |
| | | } |