解决admin项目无法启动问题。

完善验证码模块优化需要优化的项目
This commit is contained in:
Chopper 2021-11-03 09:36:25 +08:00
parent 956a6e465a
commit af9ffd1cbf
4 changed files with 59 additions and 30 deletions

View File

@ -0,0 +1,41 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE configuration>
<configuration>
<include resource="org/springframework/boot/logging/logback/defaults.xml"/>
<include resource="org/springframework/boot/logging/logback/console-appender.xml"/>
<!--应用名称-->
<springProperty scope="context" name="APP_NAME" source="spring.application.name"/>
<!--日志文件保存路径-->
<springProperty scope="context" name="LOG_FILE_PATH" source="logging.file.path"/>
<contextName>${APP_NAME}</contextName>
<appender name="FILE" class="ch.qos.logback.core.rolling.RollingFileAppender">
<rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy">
<fileNamePattern>${LOG_FILE_PATH}/${APP_NAME}-%d{yyyy-MM-dd}.log</fileNamePattern>
<maxHistory>30</maxHistory>
</rollingPolicy>
<encoder>
<pattern>${FILE_LOG_PATTERN}</pattern>
</encoder>
</appender>
<!--输出到elk的LOGSTASH-->
<appender name="LOGSTASH" class="net.logstash.logback.appender.LogstashTcpSocketAppender">
<!-- 配置elk日志收集 配饰的是 LOGSTASH 的地址-->
<destination>127.0.0.1:4560</destination>
<encoder charset="UTF-8" class="net.logstash.logback.encoder.LogstashEncoder">
<providers>
<timestamp>
<timeZone>UTC</timeZone>
</timestamp>
</providers>
<!--自定义字段 区分项目-->
<customFields>{"appName":"${APP_NAME}"}</customFields>
</encoder>
</appender>
<root level="INFO">
<appender-ref ref="CONSOLE"/>
<appender-ref ref="FILE"/>
<appender-ref ref="LOGSTASH"/>
</root>
</configuration>

View File

@ -47,11 +47,8 @@ public class MemberBuyerController {
public ResultMessage<Object> userLogin(@NotNull(message = "用户名不能为空") @RequestParam String username,
@NotNull(message = "密码不能为空") @RequestParam String password,
@RequestHeader String uuid) {
if (verificationService.check(uuid, VerificationEnums.LOGIN)) {
return ResultUtil.data(this.memberService.usernameLogin(username, password));
} else {
throw new ServiceException(ResultCode.VERIFICATION_ERROR);
}
verificationService.check(uuid, VerificationEnums.LOGIN);
return ResultUtil.data(this.memberService.usernameLogin(username, password));
}
@ApiOperation(value = "短信登录接口")
@ -63,11 +60,8 @@ public class MemberBuyerController {
public ResultMessage<Object> smsLogin(@NotNull(message = "手机号为空") @RequestParam String mobile,
@NotNull(message = "验证码为空") @RequestParam String code,
@RequestHeader String uuid) {
if (smsUtil.verifyCode(mobile, VerificationEnums.LOGIN, uuid, code)) {
return ResultUtil.data(memberService.mobilePhoneLogin(mobile));
} else {
throw new ServiceException(ResultCode.VERIFICATION_SMS_ERROR);
}
smsUtil.verifyCode(mobile, VerificationEnums.LOGIN, uuid, code);
return ResultUtil.data(memberService.mobilePhoneLogin(mobile));
}
@ApiOperation(value = "注册用户")
@ -84,12 +78,9 @@ public class MemberBuyerController {
@RequestHeader String uuid,
@NotNull(message = "验证码不能为空") @RequestParam String code) {
boolean result = smsUtil.verifyCode(mobilePhone, VerificationEnums.REGISTER, uuid, code);
if (result) {
return ResultUtil.data(memberService.register(username, password, mobilePhone));
} else {
throw new ServiceException(ResultCode.VERIFICATION_SMS_ERROR);
}
smsUtil.verifyCode(mobilePhone, VerificationEnums.REGISTER, uuid, code);
return ResultUtil.data(memberService.register(username, password, mobilePhone));
}
@ApiOperation(value = "获取当前登录用户接口")
@ -109,13 +100,11 @@ public class MemberBuyerController {
@NotNull(message = "验证码为空") @RequestParam String code,
@RequestHeader String uuid) {
//校验短信验证码是否正确
if (smsUtil.verifyCode(mobile, VerificationEnums.FIND_USER, uuid, code)) {
//校验是否通过手机号可获取会员,存在则将会员信息存入缓存有效时间3分钟
if (memberService.findByMobile(uuid, mobile)) {
return ResultUtil.success();
}
}
throw new ServiceException(ResultCode.VERIFICATION_ERROR);
smsUtil.verifyCode(mobile, VerificationEnums.FIND_USER, uuid, code);
//校验是否通过手机号可获取会员,存在则将会员信息存入缓存有效时间3分钟
memberService.findByMobile(uuid, mobile);
return ResultUtil.success();
}
@ApiOperation(value = "修改密码")

View File

@ -182,7 +182,6 @@ mybatis-plus:
# 日志
logging:
config: classpath:logback-spring.xml
# 输出级别
level:
cn.lili: info
@ -230,11 +229,11 @@ lili:
system:
isDemoSite: false
isTestModel: true
# 脱敏级别:
# 0不做脱敏处理
# 1管理端用户手机号等信息脱敏
# 2商家端信息脱敏为2时表示管理端商家端同时脱敏
# sensitiveLevel: 2
# 脱敏级别:
# 0不做脱敏处理
# 1管理端用户手机号等信息脱敏
# 2商家端信息脱敏为2时表示管理端商家端同时脱敏
# sensitiveLevel: 2
statistics:
# 在线人数统计 X 小时。这里设置48即统计过去48小时每小时在线人数

View File

@ -139,7 +139,7 @@ public class VerificationServiceImpl implements VerificationService {
}
log.debug("{}{}", randomX, xPos);
//验证结果正确 && 删除标记成功
if (Math.abs(randomX - xPos) < verificationCodeProperties.getFaultTolerant() && cache.remove(cacheResult(verificationEnums, uuid))) {
if (Math.abs(randomX - xPos) < verificationCodeProperties.getFaultTolerant() && cache.remove(cacheKey(verificationEnums, uuid))) {
//验证成功则记录验证结果 验证有效时间与验证码创建有效时间一致
cache.put(cacheResult(verificationEnums, uuid), true, verificationCodeProperties.getEffectiveTime());
return true;