mirror of https://gitee.com/stylefeng/roses
【captcha】整理代码
parent
d3e6943810
commit
d413d70bb3
|
@ -61,7 +61,6 @@
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>com.github.whvcse</groupId>
|
<groupId>com.github.whvcse</groupId>
|
||||||
<artifactId>easy-captcha</artifactId>
|
<artifactId>easy-captcha</artifactId>
|
||||||
<version>1.6.2</version>
|
|
||||||
</dependency>
|
</dependency>
|
||||||
|
|
||||||
</dependencies>
|
</dependencies>
|
||||||
|
|
|
@ -32,7 +32,6 @@
|
||||||
<version>1.0.0</version>
|
<version>1.0.0</version>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
|
||||||
|
|
||||||
</dependencies>
|
</dependencies>
|
||||||
|
|
||||||
<build>
|
<build>
|
||||||
|
|
|
@ -67,18 +67,7 @@ public enum AuthExceptionEnum implements AbstractExceptionEnum {
|
||||||
/**
|
/**
|
||||||
* 权限校验失败,只有超级管理员可以授权所有数据
|
* 权限校验失败,只有超级管理员可以授权所有数据
|
||||||
*/
|
*/
|
||||||
ONLY_SUPER_ERROR(RuleConstants.BUSINESS_ERROR_TYPE_CODE + AuthConstants.AUTH_EXCEPTION_STEP_CODE + "11", "权限校验失败,只有超级管理员可以授权所有数据"),
|
ONLY_SUPER_ERROR(RuleConstants.BUSINESS_ERROR_TYPE_CODE + AuthConstants.AUTH_EXCEPTION_STEP_CODE + "11", "权限校验失败,只有超级管理员可以授权所有数据");
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 验证码为空
|
|
||||||
*/
|
|
||||||
KAPTCHA_EMPTY(RuleConstants.USER_OPERATION_ERROR_TYPE_CODE + AuthConstants.AUTH_EXCEPTION_STEP_CODE + "12", "验证码不能为空"),
|
|
||||||
/**
|
|
||||||
* 验证码错误
|
|
||||||
*/
|
|
||||||
KAPTCHA_ERROR(RuleConstants.USER_OPERATION_ERROR_TYPE_CODE + AuthConstants.AUTH_EXCEPTION_STEP_CODE + "13", "验证码错误");
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 错误编码
|
* 错误编码
|
||||||
|
|
|
@ -34,12 +34,13 @@ public class LoginRequest extends BaseRequest {
|
||||||
private Boolean rememberMe = false;
|
private Boolean rememberMe = false;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 图形验证码
|
* 验证码图形对应的缓存key
|
||||||
|
*/
|
||||||
|
private String verKey;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 用户输入的验证码的值
|
||||||
*/
|
*/
|
||||||
private String verCode;
|
private String verCode;
|
||||||
|
|
||||||
/**
|
|
||||||
* 缓存 key
|
|
||||||
*/
|
|
||||||
private String verKey;
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -23,6 +23,7 @@ import cn.stylefeng.roses.kernel.system.enums.UserStatusEnum;
|
||||||
import cn.stylefeng.roses.kernel.system.expander.SystemConfigExpander;
|
import cn.stylefeng.roses.kernel.system.expander.SystemConfigExpander;
|
||||||
import cn.stylefeng.roses.kernel.system.pojo.user.UserLoginInfoDTO;
|
import cn.stylefeng.roses.kernel.system.pojo.user.UserLoginInfoDTO;
|
||||||
import cn.stylefeng.roses.kernel.validator.CaptchaApi;
|
import cn.stylefeng.roses.kernel.validator.CaptchaApi;
|
||||||
|
import cn.stylefeng.roses.kernel.validator.exception.enums.ValidatorExceptionEnum;
|
||||||
import org.springframework.stereotype.Service;
|
import org.springframework.stereotype.Service;
|
||||||
|
|
||||||
import javax.annotation.Resource;
|
import javax.annotation.Resource;
|
||||||
|
@ -172,13 +173,14 @@ public class AuthServiceImpl implements AuthServiceApi {
|
||||||
|
|
||||||
// 2. 如果开启了验证码校验,则验证当前请求的验证码是否正确
|
// 2. 如果开启了验证码校验,则验证当前请求的验证码是否正确
|
||||||
if (SystemConfigExpander.getCaptchaOpen()) {
|
if (SystemConfigExpander.getCaptchaOpen()) {
|
||||||
String verCode = loginRequest.getVerCode();
|
|
||||||
String verKey = loginRequest.getVerKey();
|
String verKey = loginRequest.getVerKey();
|
||||||
if (StrUtil.isEmpty(verCode) || StrUtil.isEmpty(verKey)) {
|
String verCode = loginRequest.getVerCode();
|
||||||
throw new AuthException(AuthExceptionEnum.KAPTCHA_EMPTY);
|
|
||||||
|
if (StrUtil.isEmpty(verKey) || StrUtil.isEmpty(verCode)) {
|
||||||
|
throw new AuthException(ValidatorExceptionEnum.CAPTCHA_EMPTY);
|
||||||
}
|
}
|
||||||
if (!captchaApi.validate(verCode, verKey)) {
|
if (captchaApi.validateCaptcha(verKey, verCode)) {
|
||||||
throw new AuthException(AuthExceptionEnum.KAPTCHA_ERROR);
|
throw new AuthException(ValidatorExceptionEnum.CAPTCHA_EMPTY);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -23,13 +23,13 @@ public interface CaptchaApi {
|
||||||
/**
|
/**
|
||||||
* 校验图形验证码
|
* 校验图形验证码
|
||||||
*
|
*
|
||||||
* @param verCode 验证码
|
|
||||||
* @param verKey 缓存key值
|
* @param verKey 缓存key值
|
||||||
* @return
|
* @param verCode 验证码
|
||||||
|
* @return true-验证码正确,false-验证码错误
|
||||||
* @author chenjinlong
|
* @author chenjinlong
|
||||||
* @date 2021/1/15 12:38
|
* @date 2021/1/15 12:38
|
||||||
*/
|
*/
|
||||||
boolean validate(String verCode, String verKey);
|
boolean validateCaptcha(String verKey, String verCode);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 根据key值获取验证码
|
* 根据key值获取验证码
|
||||||
|
@ -40,5 +40,4 @@ public interface CaptchaApi {
|
||||||
*/
|
*/
|
||||||
String getVerCode(String verKey);
|
String getVerCode(String verKey);
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -49,7 +49,17 @@ public enum ValidatorExceptionEnum implements AbstractExceptionEnum {
|
||||||
/**
|
/**
|
||||||
* 数据库字段值唯一性校验出错,参数不完整
|
* 数据库字段值唯一性校验出错,参数不完整
|
||||||
*/
|
*/
|
||||||
TABLE_UNIQUE_VALIDATE_ERROR(RuleConstants.USER_OPERATION_ERROR_TYPE_CODE + ValidatorConstants.VALIDATOR_EXCEPTION_STEP_CODE + "07", "数据库字段值唯一性校验出错,具体信息:{}");
|
TABLE_UNIQUE_VALIDATE_ERROR(RuleConstants.USER_OPERATION_ERROR_TYPE_CODE + ValidatorConstants.VALIDATOR_EXCEPTION_STEP_CODE + "07", "数据库字段值唯一性校验出错,具体信息:{}"),
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 验证码为空
|
||||||
|
*/
|
||||||
|
CAPTCHA_EMPTY(RuleConstants.USER_OPERATION_ERROR_TYPE_CODE + ValidatorConstants.VALIDATOR_EXCEPTION_STEP_CODE + "08", "验证码参数不能为空"),
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 验证码错误
|
||||||
|
*/
|
||||||
|
CAPTCHA_ERROR(RuleConstants.USER_OPERATION_ERROR_TYPE_CODE + ValidatorConstants.VALIDATOR_EXCEPTION_STEP_CODE + "09", "验证码错误");
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 错误编码
|
* 错误编码
|
||||||
|
|
|
@ -22,4 +22,5 @@ public class EasyCaptcha {
|
||||||
* Base64 图形验证码
|
* Base64 图形验证码
|
||||||
*/
|
*/
|
||||||
private String verImage;
|
private String verImage;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -31,7 +31,7 @@ public class CaptchaService implements CaptchaApi {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean validate(String verCode, String verKey) {
|
public boolean validateCaptcha(String verKey, String verCode) {
|
||||||
if (StrUtil.isAllEmpty(verKey, verCode)) {
|
if (StrUtil.isAllEmpty(verKey, verCode)) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
@ -48,5 +48,4 @@ public class CaptchaService implements CaptchaApi {
|
||||||
return cacheOperatorApi.get(verKey);
|
return cacheOperatorApi.get(verKey);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,66 +0,0 @@
|
||||||
/*
|
|
||||||
Copyright [2020] [https://www.stylefeng.cn]
|
|
||||||
|
|
||||||
Licensed under the Apache License, Version 2.0 (the "License");
|
|
||||||
you may not use this file except in compliance with the License.
|
|
||||||
You may obtain a copy of the License at
|
|
||||||
|
|
||||||
http://www.apache.org/licenses/LICENSE-2.0
|
|
||||||
|
|
||||||
Unless required by applicable law or agreed to in writing, software
|
|
||||||
distributed under the License is distributed on an "AS IS" BASIS,
|
|
||||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
||||||
See the License for the specific language governing permissions and
|
|
||||||
limitations under the License.
|
|
||||||
|
|
||||||
Guns采用APACHE LICENSE 2.0开源协议,您在使用过程中,需要注意以下几点:
|
|
||||||
|
|
||||||
1.请不要删除和修改根目录下的LICENSE文件。
|
|
||||||
2.请不要删除和修改Guns源码头部的版权声明。
|
|
||||||
3.请保留源码和相关描述文件的项目出处,作者声明等。
|
|
||||||
4.分发源码时候,请注明软件出处 https://gitee.com/stylefeng/guns-separation
|
|
||||||
5.在修改包名,模块名称,项目代码等时,请注明软件出处 https://gitee.com/stylefeng/guns-separation
|
|
||||||
6.若您的项目无法满足以上几点,可申请商业授权,获取Guns商业授权许可,请在官网购买授权,地址为 https://www.stylefeng.cn
|
|
||||||
*/
|
|
||||||
package cn.stylefeng.roses.kernel.system.exception.enums;
|
|
||||||
|
|
||||||
import cn.stylefeng.roses.kernel.rule.abstracts.AbstractExceptionEnum;
|
|
||||||
import cn.stylefeng.roses.kernel.rule.constants.RuleConstants;
|
|
||||||
import cn.stylefeng.roses.kernel.system.constants.SystemConstants;
|
|
||||||
import lombok.Getter;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 系统角色相关异常枚举
|
|
||||||
*
|
|
||||||
* @author majianguo
|
|
||||||
* @date 2020/11/5 上午11:06
|
|
||||||
*/
|
|
||||||
@Getter
|
|
||||||
public enum SysSmsExceptionEnum implements AbstractExceptionEnum {
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 验证码不能为空
|
|
||||||
*/
|
|
||||||
KAPTCHA_EMPTY(RuleConstants.USER_OPERATION_ERROR_TYPE_CODE + SystemConstants.SYSTEM_EXCEPTION_STEP_CODE + "101", "验证码不能为空"),
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 图形验证码错误
|
|
||||||
*/
|
|
||||||
KAPTCHA_ERROR(RuleConstants.USER_OPERATION_ERROR_TYPE_CODE + SystemConstants.SYSTEM_EXCEPTION_STEP_CODE + "102", "验证码错误");
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 错误编码
|
|
||||||
*/
|
|
||||||
private final String errorCode;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 提示用户信息
|
|
||||||
*/
|
|
||||||
private final String userTip;
|
|
||||||
|
|
||||||
SysSmsExceptionEnum(String errorCode, String userTip) {
|
|
||||||
this.errorCode = errorCode;
|
|
||||||
this.userTip = userTip;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
|
@ -28,16 +28,16 @@ public class SysSmsSendParam {
|
||||||
@NotBlank(message = "模板号为空,请检查templateCode参数")
|
@NotBlank(message = "模板号为空,请检查templateCode参数")
|
||||||
private String templateCode;
|
private String templateCode;
|
||||||
|
|
||||||
/**
|
|
||||||
* 图形验证码
|
|
||||||
*/
|
|
||||||
private String verCode;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 缓存 key
|
* 缓存 key
|
||||||
*/
|
*/
|
||||||
private String verKey;
|
private String verKey;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 图形验证码
|
||||||
|
*/
|
||||||
|
private String verCode;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 模板中的参数
|
* 模板中的参数
|
||||||
*/
|
*/
|
||||||
|
|
|
@ -19,8 +19,8 @@ import cn.stylefeng.roses.kernel.sms.modular.param.SysSmsSendParam;
|
||||||
import cn.stylefeng.roses.kernel.sms.modular.param.SysSmsVerifyParam;
|
import cn.stylefeng.roses.kernel.sms.modular.param.SysSmsVerifyParam;
|
||||||
import cn.stylefeng.roses.kernel.sms.modular.service.SysSmsInfoService;
|
import cn.stylefeng.roses.kernel.sms.modular.service.SysSmsInfoService;
|
||||||
import cn.stylefeng.roses.kernel.system.exception.SystemModularException;
|
import cn.stylefeng.roses.kernel.system.exception.SystemModularException;
|
||||||
import cn.stylefeng.roses.kernel.system.exception.enums.SysSmsExceptionEnum;
|
|
||||||
import cn.stylefeng.roses.kernel.validator.CaptchaApi;
|
import cn.stylefeng.roses.kernel.validator.CaptchaApi;
|
||||||
|
import cn.stylefeng.roses.kernel.validator.exception.enums.ValidatorExceptionEnum;
|
||||||
import com.alibaba.fastjson.JSON;
|
import com.alibaba.fastjson.JSON;
|
||||||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||||
|
@ -56,13 +56,13 @@ public class SysSmsInfoServiceImpl extends ServiceImpl<SysSmsMapper, SysSms> imp
|
||||||
@Transactional(rollbackFor = Exception.class)
|
@Transactional(rollbackFor = Exception.class)
|
||||||
@Override
|
@Override
|
||||||
public boolean sendShortMessage(SysSmsSendParam sysSmsSendParam) {
|
public boolean sendShortMessage(SysSmsSendParam sysSmsSendParam) {
|
||||||
String verCode = sysSmsSendParam.getVerCode();
|
|
||||||
String verKey = sysSmsSendParam.getVerKey();
|
String verKey = sysSmsSendParam.getVerKey();
|
||||||
if (StrUtil.isEmpty(verCode) || StrUtil.isEmpty(verKey)) {
|
String verCode = sysSmsSendParam.getVerCode();
|
||||||
throw new SystemModularException(SysSmsExceptionEnum.KAPTCHA_EMPTY);
|
if (StrUtil.isEmpty(verKey) || StrUtil.isEmpty(verCode)) {
|
||||||
|
throw new SystemModularException(ValidatorExceptionEnum.CAPTCHA_EMPTY);
|
||||||
}
|
}
|
||||||
if (!captchaApi.validate(verCode, verKey)) {
|
if (captchaApi.validateCaptcha(verKey, verCode)) {
|
||||||
throw new SystemModularException(SysSmsExceptionEnum.KAPTCHA_ERROR);
|
throw new SystemModularException(ValidatorExceptionEnum.CAPTCHA_ERROR);
|
||||||
}
|
}
|
||||||
|
|
||||||
Map<String, Object> params = sysSmsSendParam.getParams();
|
Map<String, Object> params = sysSmsSendParam.getParams();
|
||||||
|
|
8
pom.xml
8
pom.xml
|
@ -103,6 +103,7 @@
|
||||||
<aws.sdk.version>1.11.106</aws.sdk.version>
|
<aws.sdk.version>1.11.106</aws.sdk.version>
|
||||||
<minio.version>3.0.10</minio.version>
|
<minio.version>3.0.10</minio.version>
|
||||||
<rocketmq.version>4.5.2</rocketmq.version>
|
<rocketmq.version>4.5.2</rocketmq.version>
|
||||||
|
<easy.captcha>1.6.2</easy.captcha>
|
||||||
</properties>
|
</properties>
|
||||||
|
|
||||||
<dependencyManagement>
|
<dependencyManagement>
|
||||||
|
@ -240,6 +241,13 @@
|
||||||
<version>${minio.version}</version>
|
<version>${minio.version}</version>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
|
||||||
|
<!-- EasyCaptcha图形验证码 -->
|
||||||
|
<dependency>
|
||||||
|
<groupId>com.github.whvcse</groupId>
|
||||||
|
<artifactId>easy-captcha</artifactId>
|
||||||
|
<version>${easy.captcha}</version>
|
||||||
|
</dependency>
|
||||||
|
|
||||||
</dependencies>
|
</dependencies>
|
||||||
</dependencyManagement>
|
</dependencyManagement>
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue