|
|
@@ -25,10 +25,7 @@ import com.yingyangfly.core.mapper.*;
|
|
|
import com.yingyangfly.core.recommend.RecommendFacade;
|
|
|
import com.yingyangfly.core.security.util.TokenUtil;
|
|
|
import com.yingyangfly.core.service.*;
|
|
|
-import com.yingyangfly.core.util.AmountUtils;
|
|
|
-import com.yingyangfly.core.util.EntityConverter;
|
|
|
-import com.yingyangfly.core.util.Sm4Util;
|
|
|
-import com.yingyangfly.core.util.SmgUtil;
|
|
|
+import com.yingyangfly.core.util.*;
|
|
|
import com.yingyangfly.core.vo.WxPayJsApiPreVO;
|
|
|
import com.yingyangfly.redis.client.RedisClient;
|
|
|
import lombok.extern.slf4j.Slf4j;
|
|
|
@@ -157,10 +154,36 @@ public class AppUserService extends ServiceImpl<AppUserMapper, AppUser> implemen
|
|
|
@Transactional(rollbackFor = Exception.class)
|
|
|
public String login(LoginDto dto) {
|
|
|
AppCurrentLoginUser userDetails = (AppCurrentLoginUser) loadUserByUsername(dto.getLoginName());
|
|
|
+ if (ObjectUtils.isNull(userDetails.getOrderEndTime())){
|
|
|
+ throw new BadCredentialsException("请充值后在进行登录");
|
|
|
+ }
|
|
|
+ if (LocalDate.parse(userDetails.getOrderEndTime()).isBefore(LocalDate.now())){
|
|
|
+ throw new BadCredentialsException("你的套餐已到期,请充值后登录!");
|
|
|
+ }
|
|
|
+
|
|
|
+ String errorNumKey = "app:error:num:"+dto.getLoginName();
|
|
|
+ String errorNumRedis = redisClient.get(errorNumKey, "");
|
|
|
+ if (ObjectUtils.isNotNull(errorNumRedis)){
|
|
|
+ if (Integer.parseInt(errorNumRedis) >= 3){
|
|
|
+ throw new BadCredentialsException("密码错误了3次,账户锁定10分钟");
|
|
|
+ }
|
|
|
+ }
|
|
|
+ dto.setPassWord(CryptoUtil.decrypt(dto.getPassWord()));
|
|
|
if (!bCryptPasswordEncoder.matches(dto.getPassWord(), userDetails.getPassword())) {
|
|
|
+ Integer errorNum = 0;
|
|
|
+ if (ObjectUtils.isNotNull(errorNumRedis)){
|
|
|
+ errorNum = Integer.parseInt(errorNumRedis);
|
|
|
+ }
|
|
|
+ errorNum++;
|
|
|
+ redisClient.set(errorNumKey,String.valueOf(errorNum),600);
|
|
|
throw new BadCredentialsException("密码不正确");
|
|
|
}
|
|
|
String token = tokenUtil.generateToken(userDetails, dto.getRememberMe(),"app");
|
|
|
+ String tokenRedis = redisClient.get(String.format("%s%s", "token:app:", dto.getLoginName()),"");
|
|
|
+ if (StringUtils.isNotBlank(tokenRedis)){
|
|
|
+ redisClient.del(String.format("%s%s", "token:app:", dto.getLoginName()));
|
|
|
+ }
|
|
|
+ redisClient.set(String.format("%s%s", "token:app:", dto.getLoginName()),token);
|
|
|
//记录登录历史
|
|
|
LoginRecord loginRecord = new LoginRecord();
|
|
|
loginRecord.setCreateTime(new Date());
|
|
|
@@ -174,6 +197,65 @@ public class AppUserService extends ServiceImpl<AppUserMapper, AppUser> implemen
|
|
|
return token;
|
|
|
}
|
|
|
|
|
|
+ /**
|
|
|
+ * app 忘记密码重置
|
|
|
+ * @param username
|
|
|
+ * @param newPass
|
|
|
+ * @param code
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ public Boolean resetPassWordApp(String username,String newPass,String code) {
|
|
|
+ // 判断验证码是否正确
|
|
|
+ String redisKey = "hcp:changePass:mobile:" + username;
|
|
|
+ String checkCodeRedis = redisClient.get(redisKey, "");
|
|
|
+ if (StringUtils.isEmpty(checkCodeRedis)) {
|
|
|
+ throw new BadCredentialsException("验证码已经过期");
|
|
|
+ }
|
|
|
+ if (!checkCodeRedis.equals(code)) {
|
|
|
+ throw new BadCredentialsException("验证码输入错误");
|
|
|
+ }
|
|
|
+ String encrypt = Sm4Util.encrypt(username);
|
|
|
+ AppUser appUser = selectByMobile(encrypt, "0");
|
|
|
+ if (appUser == null){
|
|
|
+ throw new ServiceException("手机号:" + username + " 不存在");
|
|
|
+ }
|
|
|
+ AppUser appUserUpdate = new AppUser();
|
|
|
+ appUserUpdate.setId(appUser.getId());
|
|
|
+ String pwd = CryptoUtil.decrypt(newPass);
|
|
|
+ appUserUpdate.setPwd(bCryptPasswordEncoder.encode(pwd));
|
|
|
+ int i = appUserMapper.updateById(appUserUpdate);
|
|
|
+ // 清除缓存
|
|
|
+ cacheUserService.delAppUser(username);
|
|
|
+ if (i>0) {
|
|
|
+ return true;
|
|
|
+ }else {
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 后台重置密码
|
|
|
+ * @param appUser
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ public Boolean resetPassWordSys(AppUser appUser) {
|
|
|
+ AppUser appUserUpdate = new AppUser();
|
|
|
+ appUserUpdate.setId(appUser.getId());
|
|
|
+ if (ObjectUtils.isNotNull(appUser.getPwd())) {
|
|
|
+ appUser.setPwd(CryptoUtil.decrypt(appUser.getPwd()));
|
|
|
+ }
|
|
|
+ appUserUpdate.setPwd(bCryptPasswordEncoder.encode(appUser.getPwd()));
|
|
|
+ int i = appUserMapper.updateById(appUserUpdate);
|
|
|
+ if (i>0) {
|
|
|
+ AppUser appUser1 = appUserMapper.selectById(appUser.getId());
|
|
|
+ // 清除缓存
|
|
|
+ cacheUserService.delAppUser(Sm4Util.decrypt(appUser1.getMobile()));
|
|
|
+ return true;
|
|
|
+ }else {
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
/**
|
|
|
* 退出
|
|
|
*/
|
|
|
@@ -634,7 +716,7 @@ public class AppUserService extends ServiceImpl<AppUserMapper, AppUser> implemen
|
|
|
Boolean isSuccess = true;
|
|
|
if (isSuccess) {
|
|
|
// 防机器
|
|
|
- redisClient.set("hcp:sms:mobile:"+mobile,random,60);
|
|
|
+ redisClient.set("hcp:sms:mobile:"+mobile,random,120);
|
|
|
//存入redis
|
|
|
redisClient.set("hcp:mobile:" + mobile, random, 300);
|
|
|
return ResultResponse.success(true);
|
|
|
@@ -644,6 +726,39 @@ public class AppUserService extends ServiceImpl<AppUserMapper, AppUser> implemen
|
|
|
|
|
|
}
|
|
|
|
|
|
+
|
|
|
+ public ResultResponse getChangePasswordCode(String mobile) {
|
|
|
+ String redisKey = "hcp:sms:changePass:mobile:" + mobile;
|
|
|
+ String checkCodeRedis = redisClient.get(redisKey, "");
|
|
|
+ if (!StringUtils.isEmpty(checkCodeRedis)) {
|
|
|
+ return ResultResponse.fail("请不要频繁发送验证码");
|
|
|
+ }
|
|
|
+ String encrypt = Sm4Util.encrypt(mobile);
|
|
|
+ AppUser appUser = this.selectByMobile(encrypt,"0");
|
|
|
+ if (appUser == null) {
|
|
|
+ return ResultResponse.fail("患者不存在");
|
|
|
+ }
|
|
|
+ if (ObjectUtils.isNull(appUser.getOrderEndTime())){
|
|
|
+ return ResultResponse.success(false);
|
|
|
+ }
|
|
|
+ if (LocalDate.parse(appUser.getOrderEndTime()).isBefore(LocalDate.now())){
|
|
|
+ return ResultResponse.success(false);
|
|
|
+ }
|
|
|
+ Random rand = new Random();
|
|
|
+ int randomNumber = rand.nextInt(1000000);
|
|
|
+ String random = String.format("%06d", randomNumber);
|
|
|
+ Boolean isSuccess = SmgUtil.sendCheckCode(mobile, MsgTemplateEnums.GET_CHECK_CODE.getTempalteCode(), random);
|
|
|
+ if (isSuccess) {
|
|
|
+ // 防机器
|
|
|
+ redisClient.set("hcp:sms:changePass:mobile:"+mobile,random,120);
|
|
|
+ //存入redis
|
|
|
+ redisClient.set("hcp:changePass:mobile:" + mobile, random, 300);
|
|
|
+ return ResultResponse.success(true);
|
|
|
+ } else {
|
|
|
+ return ResultResponse.fail("请不要频繁发送验证码");
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
public List<GameDto> findByGameNameAndUserId(String gameName,String playClass,Long userId,String status) {
|
|
|
|
|
|
List<GameDto> gameDtoList = new ArrayList<>();
|