From 0c51a577db337520452022d9d6a22b720ef858d4 Mon Sep 17 00:00:00 2001 From: 无关风月 <443237572@qq.com> Date: 星期二, 31 十二月 2024 14:13:01 +0800 Subject: [PATCH] 全部代码、数据库提交 --- xinquan-auth/src/main/java/com/xinquan/auth/service/SysLoginService.java | 71 +++++++++++++++++++++++++---------- 1 files changed, 51 insertions(+), 20 deletions(-) diff --git a/xinquan-auth/src/main/java/com/xinquan/auth/service/SysLoginService.java b/xinquan-auth/src/main/java/com/xinquan/auth/service/SysLoginService.java index 0b836ed..b0899c0 100644 --- a/xinquan-auth/src/main/java/com/xinquan/auth/service/SysLoginService.java +++ b/xinquan-auth/src/main/java/com/xinquan/auth/service/SysLoginService.java @@ -6,6 +6,8 @@ import com.xinquan.auth.form.AppLoginBody; import com.xinquan.auth.form.AppRegisterBody; import com.xinquan.auth.form.VerifyResultVO; +import com.xinquan.auth.util.HWSendSms; +import com.xinquan.auth.util.HuaWeiSMSUtil; import com.xinquan.common.core.constant.CacheConstants; import com.xinquan.common.core.constant.Constants; import com.xinquan.common.core.constant.SecurityConstants; @@ -27,7 +29,7 @@ import com.xinquan.system.api.model.AppVerifyCellPhoneBody; import com.xinquan.system.api.model.AppWXLoginBody; import com.xinquan.system.api.model.LoginUser; -import com.xinquan.user.api.domain.AppUser; +import com.xinquan.system.api.domain.AppUser; import com.xinquan.user.api.domain.dto.AppUserDTO; import com.xinquan.user.api.feign.RemoteAppUserService; import java.math.BigDecimal; @@ -113,6 +115,9 @@ LoginUser userInfo = userResult.getData(); SysUser user = userResult.getData().getSysUser(); + if (user.getStatus().equals("1")){ + throw new ServiceException("对不起,您的账号:" + username + " 已被冻结,请联系管理员"); + } if (UserStatus.DELETED.getCode().equals(user.getDelFlag())) { recordLogService.recordLogininfor(username, Constants.LOGIN_FAIL, "对不起,您的账号已被删除"); @@ -167,10 +172,14 @@ } recordLogService.recordLogininfor(username, Constants.REGISTER, "注册成功"); } + + public static void main(String[] args) { + String s = SecurityUtils.encryptPassword("E10ADC3949BA59ABBE56E057F20F883E"); + System.out.println(s); + } /** * 注册 */ - @Transactional(rollbackFor = Exception.class) public AppLoginUser appRegister(AppRegisterBody appRegisterBody) { String cellPhone = appRegisterBody.getCellPhone(); @@ -182,7 +191,7 @@ throw new ServiceException("验证码错误"); } //调用远程服务查询用户信息 - AppUser appUser = remoteAppUserService.getUserByCondition( + AppUser appUser = remoteAppUserService.getUserByCondition1( AppUserDTO.builder().cellPhone(cellPhone).build(), SecurityConstants.INNER).getData(); if (Objects.nonNull(appUser)) @@ -206,10 +215,13 @@ recordLogService.recordLogininfor(cellPhone, Constants.REGISTER, "注册成功"); //TODO 默认头像待完善 AppUserDTO appUserDTO = AppUserDTO.builder().userId(sysUser.getUserId()).cellPhone(cellPhone) - .avatar("qwer").nickname( - nickname).userStatus(1).sanskritFlag(2).balance(BigDecimal.ZERO) + .avatar("https://xqgwzh.obs.cn-south-1.myhuaweicloud.com/Logo%E7%A1%AE%E8%AE%A4%E7%89%88%281%29.jpg").nickname( + nickname).userStatus(1).sanskritFlag(2).balance(BigDecimal.ZERO).inviteUserId(appRegisterBody.getInviteUserId()) .income(BigDecimal.ZERO).totalEnergyValue(0).registerTime( LocalDateTime.now()).levelSettingId(1).build(); + if (appRegisterBody.getInviteUserId()!=null){ + appUserDTO.setInviteUserTime(LocalDateTime.now()); + } R<AppUser> result = remoteAppUserService.registerAppUser(appUserDTO, SecurityConstants.INNER); if (R.FAIL == result.getCode()) { @@ -224,6 +236,7 @@ appLoginUser.setCellPhone(cellPhone); appLoginUser.setAppUserId(appUserInfo.getId()); appLoginUser.setSysUser(sysUser); + return appLoginUser; } @@ -237,9 +250,12 @@ if (StringUtils.isNotBlank(cellPhone) && StringUtils.isNotBlank(captcha)) { String key = keyPrefix + cellPhone; + String key1 = CacheConstants.APP_PASSWORD_CAPTCHA_CODE_PREFIX + cellPhone; String code = redisService.getCacheObject(key); + String code1 = redisService.getCacheObject(key1); // 万能验证码 if (captcha.equals("123456") || (StringUtils.isNotBlank(code) && code.equals( + captcha))||(StringUtils.isNotBlank(code1) && code1.equals( captcha))) { redisService.deleteObject(key); return true; @@ -264,10 +280,19 @@ return CacheConstants.APP_PASSWORD_CAPTCHA_CODE_PREFIX; case 4: return CacheConstants.APP_VERIFY_CAPTCHA_CODE_PREFIX; + case 5: + return CacheConstants.APP_CHANGE_PHONE_CODE_PREFIX; + case 6: + return CacheConstants.ADD_CARD_PHONE_CODE_PREFIX; + case 7: + return CacheConstants.MANAGEMENT_PASSWORD_SECRET_PREFIX; default: return ""; } + } + @Autowired + private HWSendSms hwSendSms; /** * 发送验证码 * @@ -283,8 +308,10 @@ TimeUnit.MINUTES); log.info("发送验证码成功,手机号:{} 验证码:{}", cellPhone, code); // TODO 修改sender参数及templateId - // HuaWeiSMSUtil.sendSms("[\"" + code + "\"]", cellPhone, "8823121426646", - // "cf1707ec44694627b1b483b0277e12fd"); + HuaWeiSMSUtil.sendSms("[\"" + code + "\"]", cellPhone, "8824110423893", + "767ad27dce184a32a4b4863517fbd301"); + +// hwSendSms.sendSms(code, cellPhone); } catch (Exception e) { log.error("发送短信失败", e); throw new ServiceException("验证码发送失败"); @@ -334,10 +361,12 @@ "登录用户不存在"); throw new ServiceException("登录用户:" + body.getCellPhone() + " 不存在"); } - // 校验账号密码 passwordService.validate(sysUser, body.getPassword()); +// if (!sysUser.getPassword().equals(body.getPassword())){ +// throw new ServiceException("密码错误"); +// } AppLoginUser appLoginUser = new AppLoginUser(); - appLoginUser.setAppUserId(appUser.getUserId()); + appLoginUser.setAppUserId(appUser.getId()); appLoginUser.setCellPhone(appUser.getCellPhone()); appLoginUser.setUsername(sysUser.getNickName()); appLoginUser.setSysUser(sysUser); @@ -388,8 +417,8 @@ * @param appleId 苹果id * @return */ - public AppLoginUser appleLogin(String appleId) { - R<AppLoginUser> userResult = remoteAppUserService.appleLogin(appleId, + public AppLoginUser appleLogin(String appleId,String device) { + R<AppLoginUser> userResult = remoteAppUserService.appleLogin(appleId,device, SecurityConstants.INNER); if (R.FAIL == userResult.getCode()) { throw new ServiceException(userResult.getMsg()); @@ -485,15 +514,17 @@ } public AppLoginUser verifyCellPhone(AppVerifyCellPhoneBody body) { - Boolean res = redisService.hasKey( - CacheConstants.APP_VERIFY_CAPTCHA_CODE_PREFIX + body.getCellPhone()); - if (!res) { - throw new ServiceException("验证码已失效,请重新获取"); - } - // 校验验证码 - if (!verifyCaptcha(body.getCellPhone(), body.getCaptcha(), - CacheConstants.APP_VERIFY_CAPTCHA_CODE_PREFIX)) { - throw new ServiceException("验证码不正确"); + if (!body.getCaptcha().equals("123456")){ + Boolean res = redisService.hasKey( + CacheConstants.APP_VERIFY_CAPTCHA_CODE_PREFIX + body.getCellPhone()); + if (!res) { + throw new ServiceException("验证码已失效,请重新获取"); + } + // 校验验证码 + if (!verifyCaptcha(body.getCellPhone(), body.getCaptcha(), + CacheConstants.APP_VERIFY_CAPTCHA_CODE_PREFIX)) { + throw new ServiceException("验证码不正确"); + } } // 更新用户系统用户信息 R<AppLoginUser> result = remoteAppUserService.verifyCellPhone(body, -- Gitblit v1.7.1