用户登录问题修改

This commit is contained in:
jiang 2024-09-10 18:08:54 +08:00
parent 2f705bc955
commit e51de30aee
1 changed files with 20 additions and 24 deletions

View File

@ -1,20 +1,9 @@
package com.bonus.gateway.service.impl; package com.bonus.gateway.service.impl;
import java.awt.image.BufferedImage;
import java.io.IOException;
import java.util.concurrent.TimeUnit;
import javax.annotation.Resource;
import javax.imageio.ImageIO;
import com.bonus.common.core.utils.VerificationCodeUtils;
import com.bonus.common.core.utils.sms.SmsUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.util.FastByteArrayOutputStream;
import com.google.code.kaptcha.Producer;
import com.bonus.common.core.constant.CacheConstants; import com.bonus.common.core.constant.CacheConstants;
import com.bonus.common.core.constant.Constants; import com.bonus.common.core.constant.Constants;
import com.bonus.common.core.exception.CaptchaException; import com.bonus.common.core.exception.CaptchaException;
import com.bonus.common.core.exception.ServiceException;
import com.bonus.common.core.utils.StringUtils; import com.bonus.common.core.utils.StringUtils;
import com.bonus.common.core.utils.sign.Base64; import com.bonus.common.core.utils.sign.Base64;
import com.bonus.common.core.utils.uuid.IdUtils; import com.bonus.common.core.utils.uuid.IdUtils;
@ -22,6 +11,16 @@ import com.bonus.common.core.web.domain.AjaxResult;
import com.bonus.common.redis.service.RedisService; import com.bonus.common.redis.service.RedisService;
import com.bonus.gateway.config.properties.CaptchaProperties; import com.bonus.gateway.config.properties.CaptchaProperties;
import com.bonus.gateway.service.ValidateCodeService; import com.bonus.gateway.service.ValidateCodeService;
import com.google.code.kaptcha.Producer;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.util.FastByteArrayOutputStream;
import javax.annotation.Resource;
import javax.imageio.ImageIO;
import java.awt.image.BufferedImage;
import java.io.IOException;
import java.util.concurrent.TimeUnit;
/** /**
* 验证码实现处理 * 验证码实现处理
@ -56,7 +55,6 @@ public class ValidateCodeServiceImpl implements ValidateCodeService {
if (!captchaEnabled) { if (!captchaEnabled) {
return ajax; return ajax;
} }
// 保存验证码信息 // 保存验证码信息
String uuid = IdUtils.simpleUUID(); String uuid = IdUtils.simpleUUID();
String verifyKey = CacheConstants.CAPTCHA_CODE_KEY + uuid; String verifyKey = CacheConstants.CAPTCHA_CODE_KEY + uuid;
@ -96,16 +94,16 @@ public class ValidateCodeServiceImpl implements ValidateCodeService {
@Override @Override
public void checkCaptcha(String code, String uuid) throws CaptchaException { public void checkCaptcha(String code, String uuid) throws CaptchaException {
if (StringUtils.isEmpty(code)) { if (StringUtils.isEmpty(code)) {
throw new CaptchaException("人机验证码不能为空"); throw new ServiceException("人机验证码不能为空");
} }
String verifyKey = CacheConstants.CAPTCHA_CODE_KEY + StringUtils.nvl(uuid, ""); String verifyKey = CacheConstants.CAPTCHA_CODE_KEY + StringUtils.nvl(uuid, "");
String captcha = redisService.getCacheObject(verifyKey); String captcha = redisService.getCacheObject(verifyKey);
if (captcha == null) { if (captcha == null) {
throw new CaptchaException("人机验证码已失效"); throw new ServiceException("人机验证码已失效");
} }
redisService.deleteObject(verifyKey); redisService.deleteObject(verifyKey);
if (!code.equalsIgnoreCase(captcha)) { if (!code.equalsIgnoreCase(captcha)) {
throw new CaptchaException("人机验证码错误"); throw new ServiceException("人机验证码错误");
} }
} }
@ -113,21 +111,19 @@ public class ValidateCodeServiceImpl implements ValidateCodeService {
/** /**
* 校验手机验证码 * 校验手机验证码
*/ */
public void checkPhoneCaptcha(String code, String phone) throws CaptchaException { @Override
public void checkPhoneCaptcha(String code, String uuid) throws CaptchaException {
if (StringUtils.isEmpty(code)) { if (StringUtils.isEmpty(code)) {
throw new CaptchaException("手机验证码不能为空"); throw new ServiceException("验证码不能为空");
} }
if (StringUtils.isEmpty(phone)) { String verifyKey = CacheConstants.VERIFICATION_CODE + StringUtils.nvl(uuid, "");
throw new CaptchaException("手机号不能为空");
}
String verifyKey = CacheConstants.CAPTCHA_PHONE_CODE_KEY + StringUtils.nvl(phone, "");
String captcha = redisService.getCacheObject(verifyKey); String captcha = redisService.getCacheObject(verifyKey);
if (captcha == null) { if (captcha == null) {
throw new CaptchaException("手机验证码已失效"); throw new ServiceException("验证码已失效");
} }
redisService.deleteObject(verifyKey); redisService.deleteObject(verifyKey);
if (!code.equalsIgnoreCase(captcha)) { if (!code.equalsIgnoreCase(captcha)) {
throw new CaptchaException("手机验证码错误"); throw new ServiceException("验证码错误");
} }
} }