feat(商城): 代码优化

master
wayn 1 year ago
parent 8bfc592d07
commit 1777b1ccd6

@ -0,0 +1,57 @@
<?xml version="1.0" encoding="UTF-8"?>
<configuration>
<springProperty scope="context" name="appName" source="spring.application.name" defaultValue="dev"/>
<property name="logPath" value="/home/logs/${appName}"/>
<property name="pattern"
value="%d{yyyy-MM-dd HH:mm:ss.SSS} [%X{request_id}] [%thread] [%-5level] %logger{36}:%L %M - %msg%n"/>
<!-- 控制台输出 -->
<appender name="STDOUT" class="ch.qos.logback.core.ConsoleAppender">
<!-- encoder 默认配置为PatternLayoutEncoder -->
<encoder>
<pattern>${pattern}</pattern>
</encoder>
</appender>
<!-- 记录日志到文件 -->
<appender name="INFO" class="ch.qos.logback.core.rolling.RollingFileAppender">
<file>${logPath}/info.log</file>
<encoder>
<pattern>${pattern}</pattern>
</encoder>
<rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy">
<fileNamePattern>${logPath}/run.%d{yyyy-MM-dd}.log</fileNamePattern>
</rollingPolicy>
<!--<filter class="ch.qos.logback.classic.filter.LevelFilter">
&lt;!&ndash; 过滤的级别 &ndash;&gt;
<level>INFO</level>
&lt;!&ndash; 匹配时的操作:接收(记录) &ndash;&gt;
<onMatch>ACCEPT</onMatch>
&lt;!&ndash; 不匹配时的操作:拒绝(不记录) &ndash;&gt;
<onMismatch>DENY</onMismatch>
</filter>-->
</appender>
<!-- 只记录SQL日志 -->
<appender name="SQL" class="ch.qos.logback.core.rolling.RollingFileAppender">
<file>${logPath}/sql.log</file>
<encoder>
<pattern>${pattern}</pattern>
</encoder>
<rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy">
<fileNamePattern>${logPath}/sql.%d{yyyy-MM-dd}.log</fileNamePattern>
</rollingPolicy>
</appender>
<logger name="org.springframework" level="INFO"/>
<logger name="io.lettuce.core" level="INFO"/>
<!-- logger为java中的包 -->
<logger name="com.wayn.common.core.mapper" level="INFO" activity="false">
<appender-ref ref="SQL"/>
</logger>
<root level="INFO">
<appender-ref ref="STDOUT"/>
<appender-ref ref="INFO"/>
</root>
</configuration>

@ -55,6 +55,7 @@ public enum ReturnCodeEnum {
USER_OLD_PASSWORD_ERROR(5104, "旧密码错误"),
USER_NEW_OLD_PASSWORD_NOT_SAME_ERROR(5105, "新密码不能与旧密码相同"),
USER_CAPTCHA_CODE_ERROR(5106, "图形验证码不正确"),
USER_REGISTER_MOBILE_ERROR(5107, "注册手机号错误"),
// 上传错误
UPLOAD_ERROR(5201, "上传图片失败"),

@ -9,7 +9,6 @@ import jakarta.servlet.http.HttpServletResponse;
import org.springframework.web.context.request.RequestContextHolder;
import org.springframework.web.context.request.ServletRequestAttributes;
import javax.swing.text.html.Option;
import java.io.IOException;
import java.io.UnsupportedEncodingException;
import java.net.URLEncoder;

@ -54,7 +54,6 @@ public class LoginController {
}
// 验证手机号是否唯一
long count = iMemberService.count(Wrappers.lambdaQuery(Member.class).eq(Member::getMobile, registryObj.getMobile()));
iMemberService.count(new QueryWrapper<Member>().eq("mobile", registryObj.getMobile()));
if (count > 0) {
return R.error(USER_PHONE_HAS_REGISTER_ERROR);
}
@ -66,7 +65,18 @@ public class LoginController {
}
// 判断邮箱验证码
String redisEmailCode = redisCache.getCacheObject(registryObj.getEmailKey());
String value = redisCache.getCacheObject(registryObj.getEmailKey());
String[] split = value.split("_");
if (split.length < 2) {
return R.error(ReturnCodeEnum.USER_EMAIL_CODE_ERROR);
}
String redisEmailCode = split[0];
String mobile = split[1];
// 判断发送邮箱验证码的手机号是否与用户当前传入手机号一致
if (!StringUtils.equalsIgnoreCase(mobile, registryObj.getMobile())) {
return R.error(ReturnCodeEnum.USER_REGISTER_MOBILE_ERROR);
}
// 判断用户输入邮箱验证码是否正确
if (registryObj.getEmailCode() == null || !redisEmailCode.equals(registryObj.getEmailCode().trim().toLowerCase())) {
return R.error(ReturnCodeEnum.USER_EMAIL_CODE_ERROR);
}
@ -97,7 +107,7 @@ public class LoginController {
// 存入redis并设置过期时间为30分钟
redisCache.setCacheObject(key, verCode, RedisKeyEnum.CAPTCHA_KEY_CACHE.getExpireSecond());
// 将key和base64返回给前端
return R.success().add("key", key).add("image", specCaptcha.toBase64());
return R.success().add("captchaKey", key).add("captchaImg", specCaptcha.toBase64());
}
@PostMapping("/sendEmailCode")
@ -105,23 +115,32 @@ public class LoginController {
// 判断图形验证码是否正确
String captchaKey = registryObj.getCaptchaKey();
String captchaCode = registryObj.getCaptchaCode();
String mobile = registryObj.getMobile();
if (StringUtils.isBlank(captchaKey)) {
return R.error(CUSTOM_ERROR.setMsg("验证码 key为空"));
return R.error(CUSTOM_ERROR.setMsg("图形验证码错误"));
}
if (StringUtils.isBlank(captchaCode)) {
return R.error(CUSTOM_ERROR.setMsg("验证码 code为空"));
return R.error(CUSTOM_ERROR.setMsg("图形验证码为空"));
}
if (StringUtils.isBlank(mobile)) {
return R.error(CUSTOM_ERROR.setMsg("手机号为空"));
}
String redisCode = redisCache.getCacheObject(captchaKey);
// 判断验证码code
if (!redisCode.equals(captchaCode.trim().toLowerCase())) {
return R.error(USER_CAPTCHA_CODE_ERROR);
}
// 验证手机号是否唯一
long count = iMemberService.count(Wrappers.lambdaQuery(Member.class).eq(Member::getMobile, mobile));
if (count > 0) {
return R.error(USER_PHONE_HAS_REGISTER_ERROR);
}
// 生成邮箱验证码code
String verCode = RandomUtil.randomString(6);
// 生成邮箱验证码唯一key
String key = RedisKeyEnum.EMAIL_KEY_CACHE.getKey(IdUtil.getUid());
// 存入redis并设置过期时间为20分钟
redisCache.setCacheObject(key, verCode, RedisKeyEnum.EMAIL_KEY_CACHE.getExpireSecond());
redisCache.setCacheObject(key, verCode + "_" + mobile, RedisKeyEnum.EMAIL_KEY_CACHE.getExpireSecond());
commonThreadPoolTaskExecutor.execute(() -> {
EmailConfig emailConfig = mailConfigService.getById(1L);
SendMailVO sendMailVO = new SendMailVO();
@ -130,6 +149,6 @@ public class LoginController {
sendMailVO.setTos(Collections.singletonList(registryObj.getEmail()));
MailUtil.sendMail(emailConfig, sendMailVO, false, false);
});
return R.success().add("key", key);
return R.success().add("emailKey", key);
}
}

Loading…
Cancel
Save