| | |
| | | import com.whyc.mapper.PageParamMapper; |
| | | import com.whyc.mapper.UserMapper; |
| | | import com.whyc.pojo.PageParam; |
| | | import com.whyc.pojo.PermitGroupUser; |
| | | import com.whyc.pojo.UserClient; |
| | | import com.whyc.pojo.UserInf; |
| | | import com.whyc.util.ActionUtil; |
| | | import com.whyc.util.CommonUtil; |
| | | import com.whyc.util.MessageUtils; |
| | | import com.whyc.util.RSAUtil; |
| | | import org.apache.shiro.SecurityUtils; |
| | | import org.apache.shiro.authc.UsernamePasswordToken; |
| | | import org.apache.shiro.subject.Subject; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.stereotype.Service; |
| | | |
| | | import javax.annotation.Resource; |
| | |
| | | |
| | | @Resource |
| | | private MapOutlineService mapOutlineService; |
| | | |
| | | @Autowired |
| | | private BaoJiGroupUserService baoJiGroupUserService; |
| | | |
| | | public Response login(String userName, String password, HttpServletRequest request) { |
| | | UsernamePasswordToken userToken = new UsernamePasswordToken(userName, password); |
| | |
| | | deliveredCode = deliveredCode.toUpperCase(); |
| | | String fontDynamicCode = (String) ActionUtil.getSession().getAttribute("fontDynamicCode"); |
| | | if (fontDynamicCode == null || "".equals(fontDynamicCode)) { |
| | | return response.set(1, false, "请刷新验证码"); |
| | | return response.set(1, false, MessageUtils.getMessage("RefreshVerification")); |
| | | } |
| | | if (!deliveredCode.equals(fontDynamicCode.toUpperCase())) { |
| | | return response.set(1, false, "验证码错误"); |
| | | return response.set(1, false, MessageUtils.getMessage("VerificationError")); |
| | | } |
| | | //验证正确,清除验证码 |
| | | ActionUtil.getSession().removeAttribute("fontDynamicCode"); |
| | |
| | | String[] dataArr = RSAUtil.decryptFront(password, RSAUtil.fontSeparator); |
| | | //验签md5 |
| | | if (!dataArr[1].equals(ActionUtil.EncryptionMD5(org.apache.commons.lang3.StringUtils.trim(dataArr[0])).toString())) { |
| | | return response.set(1, false, "密码验签失败"); |
| | | return response.set(1, false, MessageUtils.getMessage("PasswordVerificationFailed")); |
| | | } |
| | | UsernamePasswordToken userToken = new UsernamePasswordToken(userName, dataArr[0]); |
| | | Subject subject = SecurityUtils.getSubject(); |
| | |
| | | } else { |
| | | servletContext.setAttribute(userName + "_login_fail_times_" + System.currentTimeMillis(), 0); |
| | | } |
| | | //根据当前的语言环境设置不同的日志记录 |
| | | String lang = ActionUtil.getLang(); |
| | | if (lang.contains("zh")) { |
| | | CommonUtil.record(0, UserOperation.TYPE_LOGIN_FAIL.getType(), UserOperation.TYPE_LOGIN_FAIL.getTypeName()); |
| | | } else { |
| | | CommonUtil.record(0, UserOperation.TYPE_LOGIN_FAIL.getType(), UserOperation.TYPE_LOGIN_FAIL.getTypeNameEn()); |
| | | } |
| | | |
| | | return response.set(1, false, "密码错误"); |
| | | CommonUtil.record(0, UserOperation.TYPE_LOGIN_FAIL.getType(), UserOperation.TYPE_LOGIN_FAIL.getTypeName(), UserOperation.TYPE_LOGIN_FAIL.getTypeNameEn()); |
| | | return response.set(1, false, MessageUtils.getMessage("PasswordError")); |
| | | } |
| | | return response.set(1, false, message); |
| | | } |
| | |
| | | if (userInf.getStatus() != 1) { |
| | | switch (userInf.getStatus()) { |
| | | case 0: |
| | | response.setMsg("当前账号的状态异常,无法登录. 异常信息为: " + UserConstant.ACCOUNT_STATUS_CANCEL.getLabel()); |
| | | response.setMsg(MessageUtils.getMessage("AccountException") + ": " + UserConstant.ACCOUNT_STATUS_CANCEL.getLabel()); |
| | | break; |
| | | case 2: |
| | | response.setMsg("当前账号的状态异常,无法登录. 异常信息为: " + UserConstant.ACCOUNT_STATUS_HIBERNATE.getLabel()); |
| | | response.setMsg(MessageUtils.getMessage("AccountException") + ": " + UserConstant.ACCOUNT_STATUS_HIBERNATE.getLabel()); |
| | | break; |
| | | case 3: |
| | | response.setMsg("当前账号的状态异常,无法登录. 异常信息为: " + UserConstant.ACCOUNT_STATUS_LOCK.getLabel()); |
| | | response.setMsg(MessageUtils.getMessage("AccountException") + ": " + UserConstant.ACCOUNT_STATUS_LOCK.getLabel()); |
| | | break; |
| | | case 4: |
| | | response.setMsg("当前账号的状态异常,无法登录. 异常信息为: " + UserConstant.ACCOUNT_STATUS_LOCK_FAIL.getLabel()); |
| | | response.setMsg(MessageUtils.getMessage("AccountException") + ": " + UserConstant.ACCOUNT_STATUS_LOCK_FAIL.getLabel()); |
| | | break; |
| | | default: |
| | | response.setMsg("当前账号的状态异常,无法登录. 异常信息为: 无"); |
| | | response.setMsg(MessageUtils.getMessage("AccountException") + ": " + MessageUtils.getMessage("Nothing")); |
| | | } |
| | | return response.set(1, false); |
| | | } |
| | |
| | | } |
| | | } |
| | | if (!ipPass) { |
| | | return response.set(1, false, "您的IP禁止访问,请知晓"); |
| | | return response.set(1, false, MessageUtils.getMessage("IPProhibition")); |
| | | } |
| | | } else { |
| | | return response.set(1, false, "登录时间不在允许的时间范围内"); |
| | | return response.set(1, false, MessageUtils.getMessage("LoginOutOfAllowed")); |
| | | } |
| | | //首次登录,密码修改;超过3个月未修改密码,强制修改密码 |
| | | Date passwordUpdateTime = userInf.getPasswordUpdateTime(); |
| | |
| | | if (passwordUpdateTime == null) { //密码修改时间为空,尚未修改初始口令 |
| | | response.setCode(3); |
| | | response.setData(false); |
| | | response.setMsg("首次登录,请先修改初始化口令"); |
| | | response.setMsg(MessageUtils.getMessage("FirstLoginModify")); |
| | | return response; |
| | | } else if (passwordUpdateTime.compareTo(now.getTime()) < 0) { |
| | | response.setCode(2); |
| | | response.setData(false); |
| | | response.setMsg("超过3个月没有修改口令,请修改口令后重新登录"); |
| | | response.setMsg(MessageUtils.getMessage("ThreeMonthModify")); |
| | | return response; |
| | | } |
| | | } |
| | |
| | | //查询用户对应的权限组id并返回给前端 |
| | | LinkedList<Object> dataList = new LinkedList<>(); |
| | | dataList.add(subject.getPrincipal()); |
| | | int permitGroupId = permitGroupUserService.getPermitGroupId(userInf.getUId()); |
| | | dataList.add(permitGroupId); |
| | | PermitGroupUser permitGroup = permitGroupUserService.getPermitGroup(userInf.getUId()); |
| | | if(permitGroup == null){ |
| | | return new Response().set(1, false, MessageUtils.getMessage("userNoPermitGroup")); |
| | | }else { |
| | | int permitGroupId = permitGroup.getPermitGroupId(); |
| | | dataList.add(permitGroupId); |
| | | } |
| | | //查询用户对应的班组标识 |
| | | dataList.add(baoJiGroupUserService.getGroupFlag(userInf.getUId().intValue())); |
| | | //查询激活的地图 |
| | | String mapName = mapOutlineService.selectMapName(); |
| | | dataList.add(mapName); |
| | | //根据当前的语言环境设置不同的日志记录 |
| | | String lang = ActionUtil.getLang(); |
| | | if (lang.contains("zh")) { |
| | | CommonUtil.record(((UserInf) subject.getPrincipal()).getUId(), UserOperation.TYPE_LOGIN.getType(), UserOperation.TYPE_LOGIN.getTypeName()); |
| | | } else { |
| | | CommonUtil.record(((UserInf) subject.getPrincipal()).getUId(), UserOperation.TYPE_LOGIN.getType(), UserOperation.TYPE_LOGIN.getTypeNameEn()); |
| | | } |
| | | |
| | | return new Response<>().setII(1, true, dataList, "登录成功"); |
| | | CommonUtil.record(((UserInf) subject.getPrincipal()).getUId(), UserOperation.TYPE_LOGIN.getType(), UserOperation.TYPE_LOGIN.getTypeName(), UserOperation.TYPE_LOGIN.getTypeNameEn()); |
| | | return new Response<>().setII(1, true, dataList, MessageUtils.getMessage("LoginSucceeded")); |
| | | } |
| | | return new Response().set(1,false,"认证未通过"); |
| | | return new Response().set(1, false, MessageUtils.getMessage("AuthenticationFailed")); |
| | | } |
| | | |
| | | // 将所有登陆的用户的信息存到application中 |
| | |
| | | } else { |
| | | servletContext.setAttribute(userName + "_login_fail_times_" + System.currentTimeMillis(), 0); |
| | | } |
| | | //根据当前的语言环境设置不同的日志记录 |
| | | String lang = ActionUtil.getLang(); |
| | | if (lang.contains("zh")) { |
| | | CommonUtil.record(0, UserOperation.TYPE_LOGIN_FAIL.getType(), UserOperation.TYPE_LOGIN_FAIL.getTypeName()); |
| | | } else { |
| | | CommonUtil.record(0, UserOperation.TYPE_LOGIN_FAIL.getType(), UserOperation.TYPE_LOGIN_FAIL.getTypeNameEn()); |
| | | } |
| | | CommonUtil.record(0, UserOperation.TYPE_LOGIN_FAIL.getType(), UserOperation.TYPE_LOGIN_FAIL.getTypeName(), UserOperation.TYPE_LOGIN_FAIL.getTypeNameEn()); |
| | | return response.set(1, false, "密码错误"); |
| | | } |
| | | return response.set(1, false, message); |
| | |
| | | //查询用户对应的权限组id并返回给前端 |
| | | LinkedList<Object> dataList = new LinkedList<>(); |
| | | dataList.add(subject.getPrincipal()); |
| | | int permitGroupId = permitGroupUserService.getPermitGroupId(userInf.getUId()); |
| | | dataList.add(permitGroupId); |
| | | //根据当前的语言环境设置不同的日志记录 |
| | | String lang = ActionUtil.getLang(); |
| | | if (lang.contains("zh")) { |
| | | CommonUtil.record(((UserInf) subject.getPrincipal()).getUId(), UserOperation.TYPE_LOGIN.getType(), UserOperation.TYPE_LOGIN.getTypeName()); |
| | | } else { |
| | | CommonUtil.record(((UserInf) subject.getPrincipal()).getUId(), UserOperation.TYPE_LOGIN.getType(), UserOperation.TYPE_LOGIN.getTypeNameEn()); |
| | | PermitGroupUser permitGroup = permitGroupUserService.getPermitGroup(userInf.getUId()); |
| | | if(permitGroup == null){ |
| | | return new Response<>().set(1,false,MessageUtils.getMessage("userNoPermitGroup")); |
| | | }else { |
| | | int permitGroupId = permitGroup.getPermitGroupId(); |
| | | dataList.add(permitGroupId); |
| | | } |
| | | CommonUtil.record(((UserInf) subject.getPrincipal()).getUId(), UserOperation.TYPE_LOGIN.getType(), UserOperation.TYPE_LOGIN.getTypeName(), UserOperation.TYPE_LOGIN.getTypeNameEn()); |
| | | return new Response<>().setII(1, true, dataList, "登录成功"); |
| | | } |
| | | return new Response<>().set(1,false,"密码错误"); |
| | |
| | | //查询用户对应的权限组id并返回给前端 |
| | | LinkedList<Object> dataList = new LinkedList<>(); |
| | | dataList.add(subject.getPrincipal()); |
| | | int permitGroupId = permitGroupUserService.getPermitGroupId(userInf.getUId()); |
| | | dataList.add(permitGroupId); |
| | | //根据当前的语言环境设置不同的日志记录 |
| | | String lang = ActionUtil.getLang(); |
| | | if (lang.contains("zh")) { |
| | | CommonUtil.record(((UserInf) subject.getPrincipal()).getUId(), UserOperation.TYPE_LOGIN_NO_PASS.getType(), UserOperation.TYPE_LOGIN_NO_PASS.getTypeName()); |
| | | } else { |
| | | CommonUtil.record(((UserInf) subject.getPrincipal()).getUId(), UserOperation.TYPE_LOGIN_NO_PASS.getType(), UserOperation.TYPE_LOGIN_NO_PASS.getTypeNameEn()); |
| | | PermitGroupUser permitGroup = permitGroupUserService.getPermitGroup(userInf.getUId()); |
| | | if(permitGroup == null){ |
| | | return new Response<>().set(1,false,MessageUtils.getMessage("userNoPermitGroup")); |
| | | }else { |
| | | int permitGroupId = permitGroup.getPermitGroupId(); |
| | | dataList.add(permitGroupId); |
| | | } |
| | | CommonUtil.record(((UserInf) subject.getPrincipal()).getUId(), UserOperation.TYPE_LOGIN_NO_PASS.getType(), UserOperation.TYPE_LOGIN_NO_PASS.getTypeName(), UserOperation.TYPE_LOGIN_NO_PASS.getTypeNameEn()); |
| | | return new Response<>().setII(1, true, dataList, "登录成功"); |
| | | } |
| | | return new Response().set(1,false,"认证未通过"); |