| | |
| | | package com.whyc.service; |
| | | |
| | | import com.baomidou.mybatisplus.core.conditions.Wrapper; |
| | | import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; |
| | | import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper; |
| | | import com.baomidou.mybatisplus.core.metadata.IPage; |
| | | import com.baomidou.mybatisplus.extension.plugins.pagination.Page; |
| | | import com.baomidou.mybatisplus.core.toolkit.Wrappers; |
| | | import com.github.pagehelper.PageHelper; |
| | | import com.github.pagehelper.PageInfo; |
| | | import com.whyc.constant.UserConstant; |
| | | import com.whyc.constant.YamlProperties; |
| | | import com.whyc.dto.Response; |
| | | import com.whyc.mapper.UserMapper; |
| | | import com.whyc.pojo.UserClient; |
| | | import com.whyc.pojo.UserInf; |
| | | import com.whyc.mapper.*; |
| | | import com.whyc.pojo.*; |
| | | import com.whyc.util.ActionUtil; |
| | | import com.whyc.util.DigestsUtil; |
| | | import com.whyc.util.RSAUtil; |
| | | import lombok.extern.slf4j.Slf4j; |
| | | import org.apache.catalina.User; |
| | | import org.apache.catalina.Wrapper; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.context.ApplicationContext; |
| | | import org.springframework.stereotype.Service; |
| | | import org.springframework.transaction.annotation.Transactional; |
| | | import org.springframework.web.bind.annotation.RequestParam; |
| | | |
| | | import javax.annotation.Resource; |
| | | import javax.servlet.ServletContext; |
| | | import javax.servlet.http.HttpSession; |
| | | import java.io.UnsupportedEncodingException; |
| | | import java.net.URLDecoder; |
| | | import java.util.Date; |
| | | import java.util.HashMap; |
| | | import java.util.List; |
| | | import java.util.Map; |
| | | import java.security.InvalidParameterException; |
| | | import java.util.*; |
| | | |
| | | @Service |
| | | @Slf4j |
| | |
| | | |
| | | @Resource |
| | | private UserMapper userMapper; |
| | | |
| | | @Resource |
| | | private UserPermitGroupDataMapper permitMapper; |
| | | @Resource |
| | | private BaoJiGroupUserMapper baoJiGroupUserMapper; |
| | | @Resource |
| | | private UserBridgeService userBridgeService; |
| | | |
| | | @Autowired |
| | | private ApplicationContext applicationContext; |
| | | |
| | | @Resource |
| | | private PermitGroupUserService permitGroupUserService; |
| | | |
| | | @Resource |
| | | private PageParamMapper pageParamMapper; |
| | | |
| | | |
| | | |
| | | public Response add(UserInf user) { |
| | | try { |
| | |
| | | if (userFound.getUId() != 0) { |
| | | return new Response<>().set(1, false, "用户已存在"); |
| | | } |
| | | if (userMapper.addJudge(user.getUName(),user.getUMobilephone())>0){ |
| | | return new Response<>().set(1, false, "用户已存在"); |
| | | } |
| | | //user.setCreateTime(new Date()); |
| | | Map<String, String> encryptMap = DigestsUtil.encryptPassword(user.getUpassword()); |
| | | user.setUpassword(encryptMap.get("password")); |
| | | if (userMapper.insert(user) > 0) { |
| | | String[] dataArr = RSAUtil.decryptFrontP(user.getUpassword(), RSAUtil.fontSeparator); |
| | | String password = dataArr[0]; |
| | | String passwordMD5 = dataArr[1]; |
| | | if(!ActionUtil.EncryptionMD5(password).equals(passwordMD5)){ |
| | | throw new InvalidParameterException("参数校验失败"); |
| | | } |
| | | user.setUpassword(RSAUtil.encrypt(password,RSAUtil.getPublicKey())); |
| | | int flag = userMapper.insert(user); |
| | | if (flag > 0) { |
| | | Integer uId= userMapper.getUserInfoByPhoneNumber(user.getUMobilephone()).getUId().intValue(); |
| | | UserPermitGroupData permitGroupData = new UserPermitGroupData(); |
| | | permitGroupData.setPermitGroupId(user.getPermitGroupId()); |
| | | permitGroupData.setUId(uId); |
| | | permitMapper.insert(permitGroupData); |
| | | return new Response<>().set(1, true); |
| | | } else { |
| | | return new Response<>().set(1, false, "添加失败"); |
| | |
| | | } |
| | | } |
| | | public Response addByRSA(UserInf user) { |
| | | //首先校验当前用户所在的权限组,是否存在用户编辑权限 usr_edit_permit |
| | | if (!checkUserPermit()) return new Response<>().set(1, false, "当前用户没有用户编辑权限"); |
| | | try { |
| | | UserInf userFound = userBridgeService.findPasswordByUserName(user.getUName()); |
| | | if (userFound.getUId() != 0) { |
| | | return new Response<>().set(1, false, "用户已存在"); |
| | | return new Response<>().set(1, false, "用户名已存在"); |
| | | } |
| | | String password = ""; |
| | | try { |
| | | password = URLDecoder.decode(user.getUpassword(), "utf-8"); |
| | | }catch (UnsupportedEncodingException e){ |
| | | e.printStackTrace(); |
| | | UserInf userOfMobilephone = userBridgeService.findUserByMobilephone(user.getUMobilephone()); |
| | | if (userOfMobilephone.getUId()!=0) { |
| | | return new Response<>().set(1, false, "手机号已存在"); |
| | | } |
| | | //String password = URLDecoder.decode(user.getUpassword(), "utf-8"); |
| | | String password = user.getUpassword(); |
| | | String[] dataArr = RSAUtil.decryptFront(password, RSAUtil.fontSeparator); |
| | | String pwd = RSAUtil.encrypt(dataArr[0],RSAUtil.getPublicKey()); |
| | | user.setUpassword(pwd); |
| | | if (userMapper.insert(user) > 0) { |
| | | user.setUSnId(pwd); |
| | | user.setPasswordUpdateTime(new Date()); |
| | | user.setCreateTime(new Date()); |
| | | user.setLastLoginTime(new Date()); |
| | | int flag = userMapper.insert(user); |
| | | if (flag > 0) { |
| | | //添加成功,分配到默认初始化权限组 |
| | | Integer uId= userMapper.getUserInfoByPhoneNumber(user.getUMobilephone()).getUId().intValue(); |
| | | UserPermitGroupData permitGroupData = new UserPermitGroupData(); |
| | | permitGroupData.setPermitGroupId(user.getPermitGroupId()); |
| | | permitGroupData.setUId(uId); |
| | | permitMapper.insert(permitGroupData); |
| | | return new Response<>().set(1, true); |
| | | } else { |
| | | return new Response<>().set(1, false, "添加失败"); |
| | | } |
| | | }catch (Exception e){ |
| | | e.printStackTrace(); |
| | | return new Response<>().set(0); |
| | | } |
| | | } |
| | | |
| | | private boolean checkUserPermit() { |
| | | //首先校验当前用户所在的权限组,是否存在用户编辑权限 usr_edit_permit |
| | | Long uId = ActionUtil.getUser().getUId(); |
| | | List<String> itemList = permitGroupUserService.getItemList(uId); |
| | | if (!itemList.contains("usr_edit_permit")){ |
| | | return false; |
| | | } |
| | | return true; |
| | | } |
| | | |
| | | private boolean checkUserPermitWithQuery() { |
| | | //首先校验当前用户所在的权限组,是否存在用户查询权限 usr_query_permit |
| | | Long uId = ActionUtil.getUser().getUId(); |
| | | List<String> itemList = permitGroupUserService.getItemList(uId); |
| | | if (!itemList.contains("usr_query_permit")){ |
| | | return false; |
| | | } |
| | | return true; |
| | | } |
| | | |
| | | public Response registerUser(UserInf user){ |
| | | try { |
| | | UserInf userFound = userBridgeService.findPasswordByUserName(user.getUName()); |
| | | if (userFound.getUId() != 0) { |
| | | return new Response<>().set(1, false, "用户名已存在"); |
| | | } |
| | | UserInf userOfMobilephone = userBridgeService.findUserByMobilephone(user.getUMobilephone()); |
| | | if (userOfMobilephone.getUId()!=0) { |
| | | return new Response<>().set(1, false, "手机号已存在"); |
| | | } |
| | | //String password = URLDecoder.decode(user.getUpassword(), "utf-8"); |
| | | String password = user.getUpassword(); |
| | | |
| | | String[] dataArr = RSAUtil.decryptFront(password, RSAUtil.fontSeparator); |
| | | String pwd = RSAUtil.encrypt(dataArr[0],RSAUtil.getPublicKey()); |
| | | user.setUpassword(pwd); |
| | | user.setUSnId(pwd); |
| | | int flag = userMapper.insert(user); |
| | | if (flag > 0) { |
| | | //添加成功,分配到默认初始化权限组 |
| | | Integer uId= userMapper.getUserInfoByPhoneNumber(user.getUMobilephone()).getUId().intValue(); |
| | | UserPermitGroupData permitGroupData = new UserPermitGroupData(); |
| | | permitGroupData.setPermitGroupId(100020); |
| | | permitGroupData.setUId(uId); |
| | | permitMapper.insert(permitGroupData); |
| | | //添加成功,分配到默认的包机组 |
| | | BaoJiGroupUser baoJiGroupUser = new BaoJiGroupUser(); |
| | | baoJiGroupUser.setBaoJiGroupId(100091); |
| | | baoJiGroupUser.setuId(uId); |
| | | baoJiGroupUserMapper.insert(baoJiGroupUser); |
| | | return new Response<>().set(1, true,"注册成功"); |
| | | } else { |
| | | return new Response<>().set(1, false, "注册失败"); |
| | | } |
| | | }catch (Exception e){ |
| | | e.printStackTrace(); |
| | |
| | | } |
| | | |
| | | public List<UserInf> getAll() { |
| | | List<UserInf> users = userMapper.selectList(null); |
| | | List<UserInf> users = userMapper.selectList((Wrapper<UserInf>) ActionUtil.objeNull); |
| | | return users; |
| | | } |
| | | |
| | | public IPage<UserInf> getAllWithPage(Page page) { |
| | | return userMapper.selectPage(page, null); |
| | | public Response getAllWithPage(int pageNum,int pageSize) { |
| | | //验证是否存在usr_query_permit权限 |
| | | if (!checkUserPermitWithQuery()) { |
| | | return new Response<Boolean>().set(1, false, "当前用户没有查询权限"); |
| | | } |
| | | PageHelper.startPage(pageNum,pageSize); |
| | | List<UserInf> list = userMapper.getUserInfAndPermitInf(); |
| | | for (UserInf uinf:list) { |
| | | uinf.setUSnId("*******"); |
| | | uinf.setUpassword("*******"); |
| | | } |
| | | PageInfo<UserInf> pageInfo = new PageInfo<>(list); |
| | | return new Response().set(1,pageInfo,"查询成功"); |
| | | } |
| | | |
| | | public boolean update(UserInf user) { |
| | | return userMapper.updateById(user)>0; |
| | | public Response update(UserInf user) { |
| | | //首先校验当前用户所在的权限组,是否存在用户编辑权限 usr_edit_permit |
| | | if (!checkUserPermit()) return new Response<>().set(1, false, "当前用户没有用户编辑权限"); |
| | | //非系统管理员用户,禁止修改访问ip和访问时间 |
| | | if(user.getUId()!=1 && user.getUName().equals("sys_admin")){ |
| | | user.setVisitIp((String) ActionUtil.objeNull); |
| | | user.setVisitTime((String) ActionUtil.objeNull); |
| | | } |
| | | UserInf userFound = userBridgeService.findPasswordByUserName(user.getUName()); |
| | | UserInf userOfMobilephone = userBridgeService.findUserByMobilephone(user.getUMobilephone()); |
| | | if (userFound.getUId() != 0 && !userFound.getUId().equals(user.getUId())) { |
| | | return new Response().set(1,false,"用户名重复"); |
| | | } |
| | | if( userOfMobilephone.getUId()!=0 && !userFound.getUId().equals(user.getUId())){ |
| | | return new Response().set(1,false,"手机号重复"); |
| | | } |
| | | user.setUpassword(null); |
| | | user.setUSnId(null); |
| | | if(userMapper.updateById(user)>0){ |
| | | return new Response().set(1,true,"修改成功"); |
| | | }else{ |
| | | return new Response().set(1,false,"修改失败"); |
| | | } |
| | | |
| | | } |
| | | |
| | | @Transactional |
| | | public boolean delete(int id) { |
| | | return userMapper.deleteById(id)>0; |
| | | //首先校验当前用户所在的权限组,是否存在用户编辑权限 usr_edit_permit |
| | | if (!checkUserPermit()) return false; |
| | | UpdateWrapper wrapper = new UpdateWrapper(); |
| | | wrapper.eq("uId", id); |
| | | //删除对应的包机组记录 |
| | | baoJiGroupUserMapper.delete(wrapper); |
| | | //删除对应的权限组记录 |
| | | permitMapper.delete(wrapper); |
| | | //删除用户 |
| | | return userMapper.deleteById(id) > 0; |
| | | } |
| | | |
| | | // 将所有登陆的用户的信息存到application中 |
| | |
| | | ServletContext application = ActionUtil.getApplication(); |
| | | //查看全局中存储的users的Map的key-value集合 |
| | | Map<String, UserClient> map = (Map) application.getAttribute("users"); |
| | | if (map == null) { |
| | | if (map == ActionUtil.objeNull) { |
| | | map = new HashMap<String, UserClient>(); |
| | | } else { |
| | | //如果集合中有值,则获取当前用户对应的用户信息,key为用户名username,Value为用户名,存储的时间 |
| | | UserClient client = map.get(user.getUName()); |
| | | if (client != null) { //已存在 |
| | | if (client != ActionUtil.objeNull) { //已存在 |
| | | map.remove(user.getUName()); |
| | | } |
| | | } |
| | |
| | | public UserInf getUserByUKeyId(String uKeyId){ |
| | | QueryWrapper queryWrapper = new QueryWrapper(); |
| | | queryWrapper.eq("uKey_ID",uKeyId); |
| | | queryWrapper.last("limit 1"); |
| | | UserInf userInf = userMapper.selectOne(queryWrapper); |
| | | return userInf; |
| | | } |
| | |
| | | public UserInf getUserByUserName(String userName){ |
| | | QueryWrapper queryWrapper = new QueryWrapper(); |
| | | queryWrapper.eq("Uname",userName); |
| | | queryWrapper.last("limit 1"); |
| | | UserInf userInf = userMapper.selectOne(queryWrapper); |
| | | return userInf; |
| | | } |
| | | |
| | | public boolean bindUkey(UserInf userInf){ |
| | | UpdateWrapper updateWrapper = new UpdateWrapper(); |
| | | updateWrapper.set("uKey_ID",userInf.getUkeyId()); |
| | | updateWrapper.eq("uName",userInf.getUName()); |
| | | int affectRows = userMapper.update(userInf,updateWrapper); |
| | | int affectRows = userMapper.update((UserInf) ActionUtil.objeNull,updateWrapper); |
| | | return affectRows>0; |
| | | } |
| | | |
| | | |
| | | public Response updatePassword(UserInf userInf,String uSnId){ |
| | | String password = (String) ActionUtil.EncryptionMD5(uSnId); |
| | | userInf.setUSnId(uSnId); |
| | | userInf.setUpassword(password); |
| | | public Response updatePassword(UserInf userInf,String password){ |
| | | String[] dataArr = RSAUtil.decryptFrontP(password, RSAUtil.fontSeparator); |
| | | password = dataArr[0]; |
| | | String passwordMD5 = dataArr[1]; |
| | | if(!ActionUtil.EncryptionMD5(password).equals(passwordMD5)){ |
| | | throw new InvalidParameterException("参数校验失败"); |
| | | } |
| | | String pwd = RSAUtil.encrypt(password,RSAUtil.getPublicKey()); |
| | | userInf.setUpassword(pwd); |
| | | userInf.setUSnId(pwd); |
| | | if (userMapper.updateById(userInf)>0){ |
| | | return new Response().set(1,"修改成功"); |
| | | }else { |
| | |
| | | } |
| | | |
| | | public Response updatePasswordByRSA(UserInf user,String newPwd){ |
| | | String password = ""; |
| | | try { |
| | | password = URLDecoder.decode(newPwd, "utf-8"); |
| | | }catch (UnsupportedEncodingException e){ |
| | | e.printStackTrace(); |
| | | String[] dataArr = RSAUtil.decryptFrontP(newPwd, RSAUtil.fontSeparator); |
| | | newPwd = dataArr[0]; |
| | | String passwordMD5 = dataArr[1]; |
| | | if(!ActionUtil.EncryptionMD5(newPwd).equals(passwordMD5)){ |
| | | throw new InvalidParameterException("参数校验失败"); |
| | | } |
| | | String[] dataArr = RSAUtil.decryptFront(password, RSAUtil.fontSeparator); |
| | | String pwd = RSAUtil.encrypt(dataArr[0],RSAUtil.getPublicKey()); |
| | | if(!ActionUtil.filterPwd(newPwd)){ |
| | | return new Response().set(0,false,"新密码验证不通过(最少8个字符,至少1个大写字母,1个小写字母,1个数字和1个特殊字符)"); |
| | | } |
| | | String pwd = RSAUtil.encrypt(newPwd,RSAUtil.getPublicKey()); |
| | | user.setUpassword(pwd); |
| | | user.setUSnId(pwd); |
| | | user.setPasswordUpdateTime(new Date()); |
| | | if (userMapper.updateById(user)>0){ |
| | | return new Response().set(1,"修改成功"); |
| | | return new Response().set(1,true,"新密码修改成功"); |
| | | }else { |
| | | return new Response().set(0,"修改失败"); |
| | | return new Response().set(0,false,"新密码修改失败"); |
| | | } |
| | | } |
| | | //密码失效修改密码 |
| | | public Response updatePasswordByValidity(String uname, String oldPwd, String newPwd) throws UnsupportedEncodingException { |
| | | //验证旧密码是否正确 |
| | | QueryWrapper<UserInf> queryWrapper = Wrappers.query(); |
| | | queryWrapper.select("uid","upassword").eq("uName",uname).last(" limit 1"); |
| | | UserInf user=userMapper.selectOne(queryWrapper); |
| | | if(user==null){ |
| | | return new Response().set(0,false,"用户不存在"); |
| | | } |
| | | String passwordDB =user.getUpassword(); |
| | | oldPwd = RSAUtil.decryptFront(oldPwd, RSAUtil.fontSeparator)[0]; |
| | | if(!RSAUtil.decrypt(passwordDB,RSAUtil.getPrivateKey()).equals(oldPwd)){ |
| | | return new Response().set(0,false,"旧密码输入错误"); |
| | | } |
| | | String[] dataArr = RSAUtil.decryptFrontP(newPwd, RSAUtil.fontSeparator); |
| | | newPwd = dataArr[0]; |
| | | String passwordMD5 = dataArr[1]; |
| | | if(!ActionUtil.filterPwd(newPwd)){ |
| | | return new Response().set(0,false,"新密码验证不通过(最少8个字符,至少1个大写字母,1个小写字母,1个数字和1个特殊字符)"); |
| | | } |
| | | if(!ActionUtil.EncryptionMD5(newPwd).equals(passwordMD5)){ |
| | | throw new InvalidParameterException("参数校验失败"); |
| | | } |
| | | String pwd = RSAUtil.encrypt(newPwd,RSAUtil.getPublicKey()); |
| | | user.setUpassword(pwd); |
| | | user.setUSnId(pwd); |
| | | user.setPasswordUpdateTime(new Date()); |
| | | if (userMapper.updateById(user)>0){ |
| | | return new Response().set(1,true,"新密码修改成功"); |
| | | }else { |
| | | return new Response().set(0,false,"新密码修改失败"); |
| | | } |
| | | } |
| | | |
| | | |
| | | public Response updatePassword2(UserInf userInf, String passwordOld, String passwordNew) { |
| | | //检查旧密码 |
| | | QueryWrapper<UserInf> queryWrapper = Wrappers.query(); |
| | | queryWrapper.select("upassword").eq("uName",userInf.getUName()).last(" limit 1"); |
| | | String passwordDB = userMapper.selectOne(queryWrapper).getUpassword(); |
| | | if(!RSAUtil.decrypt(passwordDB,RSAUtil.getPrivateKey()).equals(passwordOld)){ |
| | | return new Response().set(1,false,"旧密码输入错误"); |
| | | } |
| | | //更新新密码 |
| | | UpdateWrapper<UserInf> updateWrapper = Wrappers.update(); |
| | | updateWrapper.set("upassword",RSAUtil.encrypt(passwordNew,RSAUtil.getPublicKey())).set("password_update_time",new Date()).eq("uName",userInf.getUName()); |
| | | userMapper.update((UserInf) ActionUtil.objeNull,updateWrapper); |
| | | return new Response().set(1,true,"密码修改成功"); |
| | | } |
| | | |
| | | /**锁定账号*/ |
| | | public void lock(Long uId) { |
| | | UpdateWrapper<UserInf> wrapper = Wrappers.update(); |
| | | wrapper.set("status", UserConstant.ACCOUNT_STATUS_LOCK_FAIL.getValue()).set("lock_time",new Date()).eq("uId",uId); |
| | | userMapper.update((UserInf) ActionUtil.objeNull,wrapper); |
| | | } |
| | | |
| | | /**更新登录时间*/ |
| | | public void updateLoginTime(Long uId) { |
| | | UpdateWrapper<UserInf> wrapper = Wrappers.update(); |
| | | wrapper.set("last_login_time", new Date()).eq("uId",uId); |
| | | userMapper.update((UserInf) ActionUtil.objeNull,wrapper); |
| | | } |
| | | |
| | | |
| | | public void updateExpiredAccount() { |
| | | UpdateWrapper<UserInf> wrapper = Wrappers.update(); |
| | | wrapper.set("status",UserConstant.ACCOUNT_STATUS_CANCEL.getValue()).eq("type",UserConstant.ACCOUNT_TYPE_TEMP.getValue()).gt("expiration_time",new Date()); |
| | | userMapper.update((UserInf) ActionUtil.objeNull,wrapper); |
| | | } |
| | | |
| | | public void unLock() { |
| | | UpdateWrapper<UserInf> wrapper = Wrappers.update(); |
| | | wrapper.set("status", UserConstant.ACCOUNT_STATUS_ACTIVE.getValue()).set("lock_time",null) |
| | | .eq("status",UserConstant.ACCOUNT_STATUS_LOCK_FAIL.getValue()) |
| | | .last(" and date_add(lock_time,interval 20 MINUTE)<now() and uId is not null"); |
| | | userMapper.update((UserInf) ActionUtil.objeNull,wrapper); |
| | | } |
| | | |
| | | public void updateAccountStatus(int status) { |
| | | UpdateWrapper<UserInf> wrapper = Wrappers.update(); |
| | | wrapper.set("status", status) |
| | | .eq("status",UserConstant.ACCOUNT_STATUS_ACTIVE.getValue()) |
| | | .last(" and date_add(last_login_time,interval 3 MONTH)<now() and uId >100"); |
| | | userMapper.update((UserInf) ActionUtil.objeNull,wrapper); |
| | | } |
| | | |
| | | public void unLock(int uId, int unLockType) { |
| | | UpdateWrapper<UserInf> wrapper = Wrappers.update(); |
| | | wrapper.set("status",1).eq("uId",uId); |
| | | if(unLockType==1){ |
| | | wrapper.set("lock_time",ActionUtil.objeNull); |
| | | }else{ |
| | | wrapper.set("last_login_time",new Date()); |
| | | } |
| | | userMapper.update((UserInf) ActionUtil.objeNull,wrapper); |
| | | } |
| | | |
| | | public List<UserInf> searchCS_All2() { |
| | | return userMapper.searchCS_All2(); |
| | | } |
| | | |
| | | public List<UserInf> getUserInfoByStationId(String stationId){ |
| | | List<UserInf> list = userMapper.getUserInfoByStationId(stationId); |
| | | return list; |
| | | } |
| | | |
| | | public Response loginByUId(int uId) { |
| | | Response<Object> response = new Response<>(); |
| | | response.setCode(1); |
| | | response.setData(false); |
| | | //查询对应的用户 |
| | | QueryWrapper<UserInf> query = Wrappers.query(); |
| | | query.select("uId","uName","uSnId","upassword","unote","UKey_ID","uRole","password_update_time","status","visit_time","visit_ip") |
| | | .eq("uId",uId).last(" limit 1"); |
| | | UserInf userInf = userMapper.selectOne(query); |
| | | if(userInf == ActionUtil.objeNull){ |
| | | response.setMsg("对应的用户不存在"); |
| | | }else{ |
| | | //判断用户状态 |
| | | if(userInf.getStatus()!=1){ |
| | | switch (userInf.getStatus()){ |
| | | case 0: response.setMsg("当前账号的状态异常,无法登录. 异常信息为: "+UserConstant.ACCOUNT_STATUS_CANCEL.getLabel());break; |
| | | case 2: response.setMsg("当前账号的状态异常,无法登录. 异常信息为: "+UserConstant.ACCOUNT_STATUS_HIBERNATE.getLabel());break; |
| | | case 3: response.setMsg("当前账号的状态异常,无法登录. 异常信息为: "+UserConstant.ACCOUNT_STATUS_LOCK.getLabel());break; |
| | | case 4: response.setMsg("当前账号的状态异常,无法登录. 异常信息为: "+UserConstant.ACCOUNT_STATUS_LOCK_FAIL.getLabel());break; |
| | | default:response.setMsg("当前账号的状态异常,无法登录. 异常信息为: 无"); |
| | | } |
| | | return response; |
| | | } |
| | | //判断是否为国网系统,校验密码是否3个月修改过一次 |
| | | if(1 == YamlProperties.systemType){ |
| | | |
| | | //登录之前,首先校验允许时间和登录ip |
| | | boolean ipPass = true; |
| | | |
| | | String firstTime = userInf.getVisitTime().split("~")[0]; |
| | | String lastTime = userInf.getVisitTime().split("~")[1]; |
| | | |
| | | List<String> ipRules = new LinkedList<>(); |
| | | String ipRuleStr = userInf.getVisitIp(); |
| | | ipRules = Arrays.asList(ipRuleStr.split(",")); |
| | | |
| | | Calendar instance = Calendar.getInstance(); |
| | | String hourOfDay = String.format("%1$02d",instance.get(Calendar.HOUR_OF_DAY)); |
| | | int minute = instance.get(Calendar.MINUTE); |
| | | int second = instance.get(Calendar.SECOND); |
| | | String nowTime = hourOfDay+":"+minute+":"+second; |
| | | //登录时间校验 |
| | | if(nowTime.compareTo(firstTime)>=0 && nowTime.compareTo(lastTime)<=0){ |
| | | //登录ip校验 |
| | | String clientIp = ActionUtil.getRequest().getRemoteAddr(); |
| | | if(!ipRules.contains("*")){ |
| | | for(String ipRule:ipRules){ |
| | | ipPass = true; |
| | | //ip规则格式为 * 或者 xxx.xxx.x.x |
| | | String[] ipArr = clientIp.split("\\."); |
| | | String[] ipRuleArr = ipRule.split("\\."); |
| | | for (int i = 0; i < ipRuleArr.length; i++) { |
| | | if(!ipRuleArr[i].equals("*") && !ipRuleArr[i].equals(ipArr[i])){ |
| | | ipPass = false; |
| | | break; |
| | | } |
| | | } |
| | | if(ipPass){ |
| | | break; |
| | | } |
| | | } |
| | | } |
| | | if(!ipPass){ |
| | | return response.set(1,false,"您的IP禁止访问,请知晓"); |
| | | } |
| | | }else{ |
| | | return response.set(1,false,"登录时间不在允许的时间范围内"); |
| | | } |
| | | } |
| | | //校验通过,登录成功 |
| | | { |
| | | response.setData(true); |
| | | //查询用户对应的权限组id并返回给前端 |
| | | QueryWrapper<UserPermitGroupData> query2 = Wrappers.query(); |
| | | query2.select("permit_group_id").eq("uId",uId).last(" limit 1"); |
| | | UserPermitGroupData userPermitGroupData = permitMapper.selectOne(query2); |
| | | response.setData2(userPermitGroupData.getPermitGroupId()); |
| | | //将登陆成功的用户存入session |
| | | HttpSession session = ActionUtil.getSession(); |
| | | session.setAttribute("user",userInf); |
| | | session.setAttribute("ip",ActionUtil.getRequest().getRemoteAddr()); |
| | | |
| | | List<UserPermitGroup> permitGroupList = permitMapper.getPermitGroupListByUId(uId); |
| | | if(permitGroupList!=ActionUtil.objeNull && permitGroupList.size()>0){ |
| | | session.setAttribute("permits", ActionUtil.tojson(permitGroupList)); |
| | | }else{ |
| | | response.setMsg("还未分配权限"); |
| | | return response; |
| | | } |
| | | //将新登录的用户存入application |
| | | setApplication(userInf); |
| | | //特定的用户信息返回 |
| | | UserInf userDto = new UserInf(); |
| | | userDto.setUId(userInf.getUId()); |
| | | userDto.setURole(userInf.getURole()); |
| | | userDto.setUName(userInf.getUName()); |
| | | response.setData3(userDto); |
| | | } |
| | | } |
| | | return response; |
| | | } |
| | | |
| | | public void updatePasswordsTo3072(List<UserInf> userListWithNewPwd) { |
| | | userMapper.updatePasswordsTo3072(userListWithNewPwd); |
| | | } |
| | | //验证密码的时效性 |
| | | public int checkPasswordValidity(UserInf uinf) { |
| | | int flag=1; |
| | | //获取系统设置的密码时效(57,15) |
| | | QueryWrapper wrapper=new QueryWrapper(); |
| | | wrapper.eq("categoryId",15); |
| | | wrapper.eq("id",57); |
| | | wrapper.last("limit 1"); |
| | | PageParam pageParam=pageParamMapper.selectOne(wrapper); |
| | | if(pageParam!=null){ |
| | | int dayDifference=ActionUtil.daysBetween(uinf.getPasswordUpdateTime(),new Date()); |
| | | if((pageParam.getStatus()>0)&&(dayDifference>pageParam.getStatus())){ |
| | | flag= -1; |
| | | } |
| | | } |
| | | return flag; |
| | | } |
| | | } |