| | |
| | | if(vo.orgTag == null || vo.orgTag.trim().length() == 0){ |
| | | return BaseResponseUtils.buildErrorMsg("未选择组织单位"); |
| | | } |
| | | if(vo.token == null || vo.token.trim().length() == 0){ |
| | | return BaseResponseUtils.buildErrorMsg("无token"); |
| | | } |
| | | if(vo.code == null || vo.code.trim().length() == 0){ |
| | | return BaseResponseUtils.buildErrorMsg("请输入验证码"); |
| | | } |
| | | //把组织单位标签作为数据源名称 |
| | | DataSourceContext.set(vo.orgTag); |
| | | |
| | | String token = Optional.ofNullable(vo.getToken()).orElse(""); |
| | | String code = Optional.ofNullable(vo.getCode()).orElse(""); |
| | | |
| | | if(token.length() > 0 && code.length() > 0) { |
| | | // 从session中获取验证码 |
| | | //HttpSession session = (HttpSession) request.getSession(); |
| | | //String localCode = session.getAttribute(token).toString(); |
| | | |
| | | Map map = sv.getCodeByToken(token); |
| | | Long expiration = Long.parseLong(map.get("expiration").toString()); |
| | | Long currentTimestamp = System.currentTimeMillis(); |
| | | if(currentTimestamp > expiration) { |
| | | return BaseResponseUtils.buildErrorMsg("验证码已超时"); |
| | | } |
| | | |
| | | // 从数据库获取验证码 |
| | | String localCode = map.get("code").toString(); |
| | | if(!code.equals(localCode)) { |
| | | return BaseResponseUtils.buildErrorMsg("验证码错误"); |
| | | } |
| | | // 从数据库获取验证码 |
| | | Map map = sv.getCodeByToken(vo.token); |
| | | Long expiration = Long.parseLong(map.get("expiration").toString()); |
| | | Long currentTimestamp = System.currentTimeMillis(); |
| | | if(currentTimestamp > expiration) { |
| | | return BaseResponseUtils.buildErrorMsg("验证码已超时"); |
| | | } |
| | | String localCode = map.get("code").toString(); |
| | | if(!vo.code.equals(localCode)) { |
| | | return BaseResponseUtils.buildErrorMsg("验证码错误"); |
| | | } |
| | | |
| | | //得到所有用户账号 |
| | | List<String> phones = sv.getPhones(); |
| | | if(!phones.contains(vo.phone)){ |
| | | if(!sv.existPhone(vo.phone)){ |
| | | return BaseResponseUtils.buildErrorMsg("账号不存在"); |
| | | } |
| | | |
| | | String uuid ; |
| | | BaUser userPo ; |
| | | String uuid4Token = null; |
| | | BaUser userPo = null ; |
| | | try { |
| | | //Boolean flag = cacheManager.getCacheNames().isEmpty() ; |
| | | uuid = UUID.randomUUID().toString(); |
| | | uuid4Token = UUID.randomUUID().toString(); |
| | | if(!StringUtils.isNullOrEmpty(vo.password)){ |
| | | /* |
| | | 如果前端进行了base64加密 |
| | |
| | | */ |
| | | vo.password = MD5.encrypt(vo.password) ; |
| | | } |
| | | userPo = this.sv.loginWithMapperXml(uuid, vo.phone, vo.password); |
| | | userPo = this.sv.loginWithMapperXml(uuid4Token, vo.phone, vo.password); |
| | | } catch (Exception e) { |
| | | log.error("用户登录异常", e); |
| | | return BaseResponseUtils.buildException(e.getMessage()) ; |
| | |
| | | |
| | | if(userPo != null){ |
| | | UserVo uVo = UserVoMapper.INSTANCT.po2vo(userPo); |
| | | uVo.token = uuid ; |
| | | uVo.token = uuid4Token ; |
| | | return BaseResponseUtils.buildSuccess(uVo); |
| | | }else{ |
| | | return BaseResponseUtils.buildErrorMsg("密码错误"); |
| | | return BaseResponseUtils.buildErrorMsg("登录失败"); |
| | | } |
| | | } |
| | | |