|
|
@@ -5,8 +5,11 @@ import cn.hutool.core.lang.Validator;
|
|
|
import cn.hutool.core.map.MapUtil;
|
|
|
import cn.hutool.json.JSONObject;
|
|
|
import cn.hutool.json.JSONUtil;
|
|
|
+import com.aliyun.captcha20230305.models.VerifyIntelligentCaptchaResponse;
|
|
|
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
|
|
import com.baomidou.mybatisplus.core.toolkit.StringUtils;
|
|
|
+import com.qnfhq.aliyun.CaptchaConfig;
|
|
|
+import com.qnfhq.common.exception.ErrorCode;
|
|
|
import com.qnfhq.common.exception.RenException;
|
|
|
import com.qnfhq.common.redis.RedisUtils;
|
|
|
import com.qnfhq.common.utils.DateUtils;
|
|
|
@@ -18,6 +21,7 @@ import com.qnfhq.modules.user.dao.AppUserDao;
|
|
|
import com.qnfhq.modules.user.dao.AppUserDetailDao;
|
|
|
import com.qnfhq.modules.user.dto.*;
|
|
|
import com.qnfhq.modules.user.dto.setting.AssetSymbolSetting;
|
|
|
+import com.qnfhq.modules.user.dto.setting.CaptchaSetting;
|
|
|
import com.qnfhq.modules.user.entity.AppAssetEntity;
|
|
|
import com.qnfhq.modules.user.entity.AppUserDetailEntity;
|
|
|
import com.qnfhq.modules.user.entity.AppUserEntity;
|
|
|
@@ -35,11 +39,9 @@ import jakarta.servlet.http.HttpServletRequest;
|
|
|
import lombok.extern.slf4j.Slf4j;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
|
|
-
|
|
|
import java.math.BigDecimal;
|
|
|
import java.util.*;
|
|
|
import java.util.stream.Collectors;
|
|
|
-
|
|
|
import lombok.AllArgsConstructor;
|
|
|
import org.springframework.transaction.annotation.Transactional;
|
|
|
import org.springframework.util.CollectionUtils;
|
|
|
@@ -73,8 +75,6 @@ public class AppUserServiceImpl extends ServiceImpl<AppUserDao, AppUserEntity> i
|
|
|
@Resource
|
|
|
private SmsSendService smsSendService;
|
|
|
|
|
|
- @Resource
|
|
|
- private CaptchaService captchaService;
|
|
|
|
|
|
@Resource
|
|
|
private AppUserDetailDao appUserDetailDao;
|
|
|
@@ -84,7 +84,6 @@ public class AppUserServiceImpl extends ServiceImpl<AppUserDao, AppUserEntity> i
|
|
|
return getOne(new LambdaQueryWrapper<AppUserEntity>()
|
|
|
.eq(AppUserEntity::getEmail, email)
|
|
|
.eq(AppUserEntity::getStatus, UserStatus.OK.getCode())
|
|
|
- .last(" limit 1")
|
|
|
);
|
|
|
}
|
|
|
|
|
|
@@ -94,21 +93,15 @@ public class AppUserServiceImpl extends ServiceImpl<AppUserDao, AppUserEntity> i
|
|
|
.eq(AppUserEntity::getPhone, mobile)
|
|
|
.eq(AppUserEntity::getZone, zone)
|
|
|
.eq(AppUserEntity::getStatus, UserStatus.OK.getCode())
|
|
|
- .last(" limit 1")
|
|
|
);
|
|
|
}
|
|
|
|
|
|
- @Override
|
|
|
- public AppUserEntity getUserByUserId(Long userId) {
|
|
|
- return getById(userId);
|
|
|
- }
|
|
|
|
|
|
@Override
|
|
|
public AppUserEntity getUserByActiveCode(String activeCode) {
|
|
|
return getOne(new LambdaQueryWrapper<AppUserEntity>()
|
|
|
.eq(AppUserEntity::getActiveCode, activeCode)
|
|
|
.eq(AppUserEntity::getStatus, UserStatus.OK.getCode())
|
|
|
- .last(" limit 1")
|
|
|
);
|
|
|
}
|
|
|
|
|
|
@@ -211,7 +204,7 @@ public class AppUserServiceImpl extends ServiceImpl<AppUserDao, AppUserEntity> i
|
|
|
appUserEntity.setUid(uuid);
|
|
|
appUserEntity.setCreateTime(new Date());
|
|
|
appUserEntity.setUpdateTime(new Date());
|
|
|
- if (save(appUserEntity)) {
|
|
|
+ if (!save(appUserEntity)) {
|
|
|
throw new RenException(MessageUtils.message("user.register.fail"));//注册失败
|
|
|
}
|
|
|
|
|
|
@@ -236,10 +229,6 @@ public class AppUserServiceImpl extends ServiceImpl<AppUserDao, AppUserEntity> i
|
|
|
@Transactional(rollbackFor = Exception.class)
|
|
|
@Override
|
|
|
public Result login(AppLoginDTO dto, HttpServletRequest request) {
|
|
|
- //图形验证码 要改滑动码
|
|
|
- //if(!captchaService.validate(dto.getUuid(), dto.getCode())) {
|
|
|
- // throw new RenException(MessageUtils.message("appUser.login.code.err"));//验证码错误
|
|
|
- //}
|
|
|
|
|
|
//账号密码失败重试次数
|
|
|
checkPwdErrTryTimes(dto.getLoginName());
|
|
|
@@ -341,7 +330,9 @@ public class AppUserServiceImpl extends ServiceImpl<AppUserDao, AppUserEntity> i
|
|
|
* @return
|
|
|
*/
|
|
|
@Override
|
|
|
- public Result sendEmailCode(String codeType, String email) {
|
|
|
+ public Result sendEmailCode(String uuid, String codeType, String email) {
|
|
|
+ //阿里云滑动验证码
|
|
|
+ checkIntelligentCaptcha(uuid);
|
|
|
|
|
|
if (!EmailUtils.checkEmail(email)) {
|
|
|
throw new RenException(MessageUtils.message("user.register.email.format"));//邮箱格式不正确
|
|
|
@@ -379,7 +370,9 @@ public class AppUserServiceImpl extends ServiceImpl<AppUserDao, AppUserEntity> i
|
|
|
* @return
|
|
|
*/
|
|
|
@Override
|
|
|
- public Result sendMobileCode(String codeType, String phone, String zone) {
|
|
|
+ public Result sendMobileCode(String uuid, String codeType, String phone, String zone) {
|
|
|
+ //阿里云滑动验证码
|
|
|
+ checkIntelligentCaptcha(uuid);
|
|
|
|
|
|
if (StringUtils.isEmpty(phone)) {
|
|
|
throw new RenException(MessageUtils.message("phone_code_empty"));//手机号不能为空!
|
|
|
@@ -457,21 +450,22 @@ public class AppUserServiceImpl extends ServiceImpl<AppUserDao, AppUserEntity> i
|
|
|
public Result resetPwdByPhone(String zone, String phone, String newPwd) {
|
|
|
Result result = new Result();
|
|
|
String codeType = "FIND_PASSWORD";
|
|
|
- //校验手机验证码
|
|
|
- final String phoneCodeResultKey = String.format("%s%s%s%s%s", CachePrefix.SMS_CODE.getPrefix(), UserCodeTypeEnum.valueOf(codeType).name(), zone, phone, ":result");
|
|
|
- verifyResult(phoneCodeResultKey);
|
|
|
+
|
|
|
|
|
|
//密码强度检测
|
|
|
PasswordStrengthValidator.validatePasswordStrength(newPwd);
|
|
|
- //更新密码
|
|
|
+
|
|
|
AppUserEntity appUser = getUserByMobile(phone, zone);
|
|
|
if (Objects.isNull(appUser)) {
|
|
|
throw new RenException(MessageUtils.message("user.not.exist"));//用户不存在
|
|
|
}
|
|
|
-
|
|
|
+ //校验手机验证码
|
|
|
+ final String phoneCodeResultKey = String.format("%s%s%s%s%s", CachePrefix.SMS_CODE.getPrefix(), UserCodeTypeEnum.valueOf(codeType).name(), zone, phone, ":result");
|
|
|
+ verifyResult(phoneCodeResultKey);
|
|
|
+ //校验邮箱验证码
|
|
|
final String emailCodeResultKey = String.format("%s%s%s%s", CachePrefix.EMAIL_CODE.getPrefix(), UserCodeTypeEnum.valueOf(codeType).name(), appUser.getEmail(), ":result");
|
|
|
verifyResult(emailCodeResultKey);
|
|
|
-
|
|
|
+ //更新密码
|
|
|
appUser.setLoginPassword(PasswordUtils.encode(newPwd));
|
|
|
appUser.setTransferOutTime(DateUtils.addDays(new Date(), 1));
|
|
|
updateById(appUser);
|
|
|
@@ -479,7 +473,10 @@ public class AppUserServiceImpl extends ServiceImpl<AppUserDao, AppUserEntity> i
|
|
|
|
|
|
}
|
|
|
|
|
|
-
|
|
|
+ /**
|
|
|
+ * 校验手机或邮箱验证码是否通过
|
|
|
+ * @param codeResultKey
|
|
|
+ */
|
|
|
private void verifyResult(String codeResultKey) {
|
|
|
Object codeResult = redisUtils.get(codeResultKey);
|
|
|
if (Objects.isNull(codeResult) || (int) codeResult != 1) {
|
|
|
@@ -488,6 +485,16 @@ public class AppUserServiceImpl extends ServiceImpl<AppUserDao, AppUserEntity> i
|
|
|
redisUtils.delete(codeResultKey);
|
|
|
}
|
|
|
|
|
|
+ /**
|
|
|
+ * 验证码智能验证是否通过
|
|
|
+ */
|
|
|
+ private void checkIntelligentCaptcha(String uuid) {
|
|
|
+ Object codeResult = redisUtils.get(uuid);
|
|
|
+ if (Objects.isNull(codeResult) || (int) codeResult != 1) {
|
|
|
+ throw new RenException(ErrorCode.AUTH_ALIYUN_CAPTCHA);//智能验证码校验失败
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
|
|
|
|
|
|
|
|
|
@@ -546,31 +553,23 @@ public class AppUserServiceImpl extends ServiceImpl<AppUserDao, AppUserEntity> i
|
|
|
return pwdFailTimes;
|
|
|
}
|
|
|
|
|
|
-
|
|
|
- @Override
|
|
|
- public Result checkCaptcha(CheckCaptchaDTO dto, HttpServletRequest request) {
|
|
|
- if (!captchaService.validate(dto.getUuid(), dto.getCode())) {
|
|
|
- throw new RenException(MessageUtils.message("appUser.login.code.err"));//验证码错误
|
|
|
- }
|
|
|
- Result result = new Result();
|
|
|
- return result;
|
|
|
- }
|
|
|
-
|
|
|
@Override
|
|
|
public Result checkPhoneCode(String codeType, String zone, String phone, String code) {
|
|
|
//校验手机验证码
|
|
|
final String phoneCodeKey = String.format("%s%s%s%s", CachePrefix.SMS_CODE.getPrefix(), UserCodeTypeEnum.valueOf(codeType).name(), zone, phone);
|
|
|
checkCode(phoneCodeKey, code);
|
|
|
|
|
|
- AppUserEntity user = getUserByMobile(phone, zone);
|
|
|
- if (Objects.isNull(user)) {
|
|
|
- throw new RenException(MessageUtils.message("user.not.exist"));//用户不存在
|
|
|
- }
|
|
|
- Map data = MapUtil.of("phone", user.getPhone());
|
|
|
- data.put("zone", user.getZone());
|
|
|
- data.put("email", user.getEmail());
|
|
|
Result result = new Result();
|
|
|
- result.setData(data);
|
|
|
+ if(!codeType.equals(UserCodeTypeEnum.REGISTER.name())) {
|
|
|
+ AppUserEntity user = getUserByMobile(phone, zone);
|
|
|
+ if (Objects.isNull(user)) {
|
|
|
+ throw new RenException(MessageUtils.message("user.not.exist"));//用户不存在
|
|
|
+ }
|
|
|
+ Map data = MapUtil.of("phone", user.getPhone());
|
|
|
+ data.put("zone", user.getZone());
|
|
|
+ data.put("email", user.getEmail());
|
|
|
+ result.setData(data);
|
|
|
+ }
|
|
|
return result;
|
|
|
}
|
|
|
|
|
|
@@ -581,15 +580,17 @@ public class AppUserServiceImpl extends ServiceImpl<AppUserDao, AppUserEntity> i
|
|
|
final String emailCodeKey = String.format("%s%s%s", CachePrefix.EMAIL_CODE.getPrefix(), UserCodeTypeEnum.valueOf(codeType).name(), email);
|
|
|
checkCode(emailCodeKey, code);
|
|
|
|
|
|
- AppUserEntity user = getUserByEmail(email);
|
|
|
- if (Objects.isNull(user)) {
|
|
|
- throw new RenException(MessageUtils.message("user.not.exist"));//用户不存在
|
|
|
- }
|
|
|
- Map data = MapUtil.of("phone", user.getPhone());
|
|
|
- data.put("zone", user.getZone());
|
|
|
- data.put("email", user.getEmail());
|
|
|
Result result = new Result();
|
|
|
- result.setData(data);
|
|
|
+ if(!codeType.equals(UserCodeTypeEnum.REGISTER.name())) {
|
|
|
+ AppUserEntity user = getUserByEmail(email);
|
|
|
+ if (Objects.isNull(user)) {
|
|
|
+ throw new RenException(MessageUtils.message("user.not.exist"));//用户不存在
|
|
|
+ }
|
|
|
+ Map data = MapUtil.of("phone", user.getPhone());
|
|
|
+ data.put("zone", user.getZone());
|
|
|
+ data.put("email", user.getEmail());
|
|
|
+ result.setData(data);
|
|
|
+ }
|
|
|
return result;
|
|
|
}
|
|
|
|
|
|
@@ -618,4 +619,30 @@ public class AppUserServiceImpl extends ServiceImpl<AppUserDao, AppUserEntity> i
|
|
|
final String checkCodeResult = String.format("%s%s", cacheKey, ":result");
|
|
|
redisUtils.set(checkCodeResult, 1, ApiConstant.CHECK_EXPIRE);
|
|
|
}
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public Result verifyIntelligentCaptcha(String verifyParam) {
|
|
|
+ SettingEntity setting = settingService.getSetting(SettingEnum.CAPTCHA_SETTING.name());
|
|
|
+ CaptchaSetting captchaSetting = JSONUtil.toBean(setting.getSettingValue(), CaptchaSetting.class);
|
|
|
+ VerifyIntelligentCaptchaResponse response = CaptchaConfig.verifyIntelligentCaptcha(captchaSetting.getAccessKeyId(), captchaSetting.getAccessKeySecret(),
|
|
|
+ captchaSetting.getSceneId(),captchaSetting.getEndpoint(), verifyParam);
|
|
|
+ if(response==null) {
|
|
|
+ throw new RenException(MessageUtils.message("user.verifyIntelligentCaptcha.err"));//验证码校验接口报错
|
|
|
+ }
|
|
|
+ if(response.statusCode == 200 && response.body.success) {
|
|
|
+ //设置验证通过
|
|
|
+ final String uuid = UUID.randomUUID().toString();
|
|
|
+ redisUtils.set(uuid, 1, ApiConstant.CHECK_EXPIRE);
|
|
|
+
|
|
|
+ Map data = MapUtil.of("verifyResult", response.body.result.verifyResult);
|
|
|
+ data.put("uuid", uuid);
|
|
|
+ return new Result().ok(data);
|
|
|
+ } else {
|
|
|
+ return new Result().error(response.body.message);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
}
|