| | |
| | | import com.ruoyi.common.core.utils.StringUtils; |
| | | import com.ruoyi.common.redis.service.RedisService; |
| | | import com.ruoyi.common.security.service.TokenService; |
| | | import com.ruoyi.system.api.model.LoginUser; |
| | | import com.ruoyi.system.api.model.LoginUserInfo; |
| | | import com.ruoyi.user.entity.RecoveryClassify; |
| | | import com.ruoyi.user.entity.RecoveryServe; |
| | |
| | | public R<Object> phoneCodeLogin(@RequestBody @Validated LoginPhoneRequest loginPhoneRequest) { |
| | | String phone = loginPhoneRequest.getPhone(); |
| | | String phoneCode = loginPhoneRequest.getPhoneCode(); |
| | | // 手机验证码校验获取缓存验证码 |
| | | Object phoneCodeRedis = redisService.getCacheObject(RedisConstants.USER_LOGIN_PHONE_CODE + phone); |
| | | if (null == phoneCodeRedis) { |
| | | return R.errorCode("登录失败,验证码已过期!"); |
| | | } else { |
| | | // redis 验证码的value 为 code:时间戳 |
| | | String rCodeAndTime = String.valueOf(phoneCodeRedis); |
| | | String rCode = rCodeAndTime.split(":")[0]; |
| | | if (!rCode.equalsIgnoreCase(phoneCode)) { |
| | | return R.errorCode("登录失败,验证码无效!"); |
| | | // 默认验证码 123456 |
| | | if (!"123456".equals(phoneCode)) { |
| | | // 手机验证码校验获取缓存验证码 |
| | | Object phoneCodeRedis = redisService.getCacheObject(RedisConstants.USER_LOGIN_PHONE_CODE + phone); |
| | | if (null == phoneCodeRedis) { |
| | | return R.errorCode("登录失败,验证码已过期!"); |
| | | } else { |
| | | // redis 验证码的value 为 code:时间戳 |
| | | String rCodeAndTime = String.valueOf(phoneCodeRedis); |
| | | String rCode = rCodeAndTime.split(":")[0]; |
| | | if (!rCode.equalsIgnoreCase(phoneCode)) { |
| | | return R.errorCode("登录失败,验证码无效!"); |
| | | } |
| | | } |
| | | } |
| | | // 用户账号校验 |
| | |
| | | // 随机编号 |
| | | user.setUserNo(String.format(Constants.USER_NO_PRE, RandomUtil.randomNumbers(Constants.EIGHT))); |
| | | user.setState(Constants.ONE); |
| | | user.setNickname(phone); |
| | | user.setPhone(phone); |
| | | user.setCity(loginPhoneRequest.getCity()); |
| | | user.setOpenId(loginPhoneRequest.getOpenId()); |
| | |
| | | } |
| | | // 校验通过,生成token及过期时间 |
| | | LoginUserInfo loginUserInfo = new LoginUserInfo(); |
| | | loginUserInfo.setName(user.getNickname()); |
| | | loginUserInfo.setName(user.getPhone()); |
| | | loginUserInfo.setUserid(user.getId()); |
| | | loginUserInfo.setPhone(user.getPhone()); |
| | | loginUserInfo.setLoginTime(System.currentTimeMillis()); |
| | |
| | | public R<List<RecoveryServe>> recoverySearch(@RequestParam String keyword) { |
| | | LambdaQueryChainWrapper<RecoveryServe> wrapper = recoveryServeService.lambdaQuery() |
| | | .eq(RecoveryServe::getIsDelete, 0) |
| | | .orderByAsc(RecoveryServe::getOrder); |
| | | .orderByAsc(RecoveryServe::getSort); |
| | | wrapper = StringUtils.isNotBlank(keyword) ? wrapper.like(RecoveryServe::getServeName, keyword) : wrapper; |
| | | return R.ok(wrapper.list()); |
| | | } |
| | |
| | | @ApiOperation(value = "个人中心用户信息", tags = {"用户端-个人中心"}) |
| | | @GetMapping(value = "/userInfo") |
| | | public R<User> userInfo() { |
| | | LoginUser loginUser = tokenService.getLoginUserByUser(); |
| | | LoginUserInfo loginUser = tokenService.getLoginUserByUser(); |
| | | if (null == loginUser) { |
| | | return R.loginExpire("登录失效!"); |
| | | } |