feat: 邮箱验证码注册+登录协议勾选

- 后端: VerificationCode模型+send-code API+register增加verifyCode校验
- 前端: 注册表单增加验证码输入框+60s倒计时获取按钮
- 前端: 登录表单增加用户协议/隐私政策勾选
- 前端: 登录按钮增加disabled状态(未勾选时不可点击)
- 后端: nodemailer邮件发送工具(可配置SMTP,未配置时返回devCode)
This commit is contained in:
Yuzhiran Dev
2026-07-12 16:02:57 +08:00
parent dd5c1bc7ac
commit 23de8bc86a
12 changed files with 626 additions and 253 deletions
+13 -7
View File
@@ -53,13 +53,19 @@ const UserSchema = new Schema({
},
// H5环境用户名密码登录
username: {
type: String,
unique: true,
sparse: true,
index: true
},
password: {
username: {
type: String,
unique: true,
sparse: true,
index: true
},
email: {
type: String,
unique: true,
sparse: true,
index: true
},
password: {
type: String,
select: false
},
+15
View File
@@ -0,0 +1,15 @@
const mongoose = require('mongoose')
const { Schema } = mongoose
const VerificationCodeSchema = new Schema({
email: { type: String, required: true, index: true },
code: { type: String, required: true },
expiresAt: { type: Date, required: true, index: true },
used: { type: Boolean, default: false },
createdAt: { type: Date, default: Date.now }
})
// 自动过期 TTL 索引(MongoDB 自动删除过期文档)
VerificationCodeSchema.index({ expiresAt: 1 }, { expireAfterSeconds: 0 })
module.exports = mongoose.model('VerificationCode', VerificationCodeSchema)
+3 -1
View File
@@ -9,6 +9,7 @@ const AIModel = require('./AIModel')
const LoginLog = require('./LoginLog')
const Feedback = require('./Feedback')
const Trend = require('./Trend')
const VerificationCode = require('./VerificationCode')
module.exports = {
User,
@@ -21,5 +22,6 @@ module.exports = {
AIModel,
LoginLog,
Feedback,
Trend
Trend,
VerificationCode
}