" +
+ "
您好!
" +
+ "
感谢您使用UniLife平台。您的验证码是:
" +
+ "
" +
+ code +
+ "
" +
+ "
此验证码将在10分钟内有效。
" +
+ "
如果您没有请求此验证码,请忽略此邮件。
" +
+ "
" +
+ "这是一封自动生成的邮件,请勿直接回复。" +
+ "
";
+
+ helper.setText(content, true);
+
+ //4.发送邮件
+ mailSender.send(message);
+ }catch (MessagingException e){
+ log.error("邮件发送失败");
+ return Result.error(400,"邮件发送失败");
+ }
+
+
+ //4.存储随机产生的验证码
+ //TODO
+
+
+ return Result.success(200,"验证码已发送");
+
+
+ }
}
diff --git a/unilife-server/src/main/java/com/unilife/utils/RegexPatterns.java b/unilife-server/src/main/java/com/unilife/utils/RegexPatterns.java
new file mode 100644
index 0000000..6f7c2b2
--- /dev/null
+++ b/unilife-server/src/main/java/com/unilife/utils/RegexPatterns.java
@@ -0,0 +1,21 @@
+package com.unilife.utils;
+
+public class RegexPatterns {
+ /**
+ * 手机号正则
+ */
+ public static final String PHONE_REGEX = "^1([38][0-9]|4[579]|5[0-3,5-9]|6[6]|7[0135678]|9[89])\\d{8}$";
+ /**
+ * 邮箱正则
+ */
+ public static final String EMAIL_REGEX = "^[a-zA-Z0-9_-]+@[a-zA-Z0-9_-]+(\\.[a-zA-Z0-9_-]+)+$";
+ /**
+ * 密码正则。4~32位的字母、数字、下划线
+ */
+ public static final String PASSWORD_REGEX = "^\\w{4,32}$";
+ /**
+ * 验证码正则, 6位数字或字母
+ */
+ public static final String VERIFY_CODE_REGEX = "^[a-zA-Z\\d]{6}$";
+
+}
diff --git a/unilife-server/src/main/java/com/unilife/utils/RegexUtils.java b/unilife-server/src/main/java/com/unilife/utils/RegexUtils.java
new file mode 100644
index 0000000..f71719d
--- /dev/null
+++ b/unilife-server/src/main/java/com/unilife/utils/RegexUtils.java
@@ -0,0 +1,39 @@
+package com.unilife.utils;
+
+import cn.hutool.core.util.StrUtil;
+
+public class RegexUtils {
+ /**
+ * 是否是无效手机格式
+ * @param phone 要校验的手机号
+ * @return true:符合,false:不符合
+ */
+ public static boolean isPhoneInvalid(String phone){
+ return mismatch(phone, RegexPatterns.PHONE_REGEX);
+ }
+ /**
+ * 是否是无效邮箱格式
+ * @param email 要校验的邮箱
+ * @return true:符合,false:不符合
+ */
+ public static boolean isEmailInvalid(String email){
+ return mismatch(email, RegexPatterns.EMAIL_REGEX);
+ }
+
+ /**
+ * 是否是无效验证码格式
+ * @param code 要校验的验证码
+ * @return true:符合,false:不符合
+ */
+ public static boolean isCodeInvalid(String code){
+ return mismatch(code, RegexPatterns.VERIFY_CODE_REGEX);
+ }
+
+ // 校验是否不符合正则格式
+ private static boolean mismatch(String str, String regex){
+ if (StrUtil.isBlank(str)) {
+ return true;
+ }
+ return !str.matches(regex);
+ }
+}
diff --git a/unilife-server/src/main/resources/application.yml b/unilife-server/src/main/resources/application.yml
index 8d8e1f5..17b36cb 100644
--- a/unilife-server/src/main/resources/application.yml
+++ b/unilife-server/src/main/resources/application.yml
@@ -1,11 +1,25 @@
server:
- port: 8087
+ port: 8084
spring:
datasource:
url: jdbc:mysql://localhost:3306/UniLife?useSSL=false&serverTimezone=UTC&characterEncoding=UTF-8
username: root
- password: zhong20050428
+ password: 123456
driver-class-name: com.mysql.cj.jdbc.Driver
+ mail:
+ host: smtp.163.com
+ port: 465
+ username: c2991692032@163.com
+ password: VPq5u3NcAAqtG9GT
+ properties:
+ mail:
+ smtp:
+ auth: true
+ ssl:
+ enable: true
+ socketFactory:
+ port: 465
+ class: javax.net.ssl.SSLSocketFactory
knife4j:
enable: true
openapi:
@@ -28,3 +42,6 @@ mybatis:
mapper-locations: classpath:mappers/*.xml
configuration:
map-underscore-to-camel-case: true
+logging:
+ level:
+ com.unilife: debug