From 33a303b6f1a97bb10652f5972dd6dfd4b2cab745 Mon Sep 17 00:00:00 2001 From: kenyanghui Date: Sun, 15 Nov 2026 02:14:18 +0800 Subject: [PATCH] =?UTF-8?q?fix(security):=20=E6=B6=88=E9=99=A4=E6=9C=8D?= =?UTF-8?q?=E5=8A=A1=E7=AB=AF=2019=20=E5=A4=84=20'||=20user-1'=20=E8=BA=AB?= =?UTF-8?q?=E4=BB=BD=E5=9B=9E=E9=80=80=EF=BC=8C=E5=A0=B5=E4=BD=8F=E6=B8=B8?= =?UTF-8?q?=E5=AE=A2=E6=80=81=E6=95=B0=E6=8D=AE=E6=B3=84=E9=9C=B2?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 读路由 7 处回退改 null:游客 joined/created/templates 自然空集、stats 零计数 - 写路由 8 处加 authenticateUser 401 守卫(profile/account/avatar/share/join/checkin/collab) - admin 守卫路由 3 处改用 req.authUser.id,消除 header 伪造面 - multer 文件名回退改 guest;isJoined 改显式布尔(undefined 会被 JSON 序列化丢弃) - 并入前期已上线未提交改动:拆书 level/level1 迁移与 memberLevelLabel、登录/资料编辑页、后台管理页 --- wechat-miniprogram/api/user.js | 10 + .../pages/edit-profile/index.js | 30 ++- .../pages/edit-profile/index.wxml | 55 ++--- .../pages/edit-profile/index.wxss | 53 +++++ wechat-miniprogram/pages/login/index.js | 56 +++-- wechat-miniprogram/pages/login/index.wxml | 32 +++ wechat-miniprogram/pages/login/index.wxss | 86 ++++++++ yaoyue-sever/admin-web/index.html | 203 +++++++++++++----- .../server/scripts/patch-guest-fallback.js | 169 +++++++++++++++ yaoyue-sever/server/server.js | 176 ++++++++++----- 10 files changed, 716 insertions(+), 154 deletions(-) create mode 100644 yaoyue-sever/server/scripts/patch-guest-fallback.js diff --git a/wechat-miniprogram/api/user.js b/wechat-miniprogram/api/user.js index bce6021..07dd510 100644 --- a/wechat-miniprogram/api/user.js +++ b/wechat-miniprogram/api/user.js @@ -106,6 +106,15 @@ const deleteChaishuTag = (tag) => { return post('/chaishu/tags/delete', { tag }); }; +/** + * 绑定/修改邮箱(邮箱为拆书帮会员身份认定凭证) + * @param {string} email + * @returns {Promise} + */ +const bindEmail = (email) => { + return post('/user/email/bind', { email }); +}; + module.exports = { wechatLogin, login, @@ -118,4 +127,5 @@ module.exports = { getUserStats, getChaishuBranches, bindChaishu, + bindEmail, }; diff --git a/wechat-miniprogram/pages/edit-profile/index.js b/wechat-miniprogram/pages/edit-profile/index.js index 06f9421..ea506b9 100644 --- a/wechat-miniprogram/pages/edit-profile/index.js +++ b/wechat-miniprogram/pages/edit-profile/index.js @@ -1,5 +1,5 @@ // pages/edit-profile/index.js -const { getProfile, updateProfile, uploadAvatar, getChaishuBranches, bindChaishu, deleteChaishuTag } = require('../../api/user'); +const { getProfile, updateProfile, uploadAvatar, getChaishuBranches, bindChaishu, deleteChaishuTag, bindEmail } = require('../../api/user'); const { chooseImages, getFullImageUrl } = require('../../utils/helpers'); Page({ @@ -24,6 +24,7 @@ Page({ chaishuBranchIndex: -1, chaishuName: '', binding: false, + bindingEmail: false, }, onLoad() { @@ -225,6 +226,30 @@ Page({ } }, + async handleBindEmail() { + const email = (this.data.form.email || '').trim(); + if (!email) { + wx.showToast({ title: '请输入邮箱', icon: 'none' }); + return; + } + if (this.data.bindingEmail) return; + this.setData({ bindingEmail: true }); + try { + const res = await bindEmail(email); + if (res.success) { + const hadEmail = !!this.data.form.email; + wx.showToast({ title: res.data && res.data.chaishuAutoBound ? '绑定成功,已认证拆书帮身份' : (hadEmail ? '换绑成功' : '绑定成功'), icon: 'none' }); + this.loadProfile(); + } else { + wx.showToast({ title: res.message || '绑定失败', icon: 'none' }); + } + } catch (err) { + wx.showToast({ title: err.message || '绑定失败', icon: 'none' }); + } finally { + this.setData({ bindingEmail: false }); + } + }, + async handleSubmit() { const { form } = this.data; @@ -238,13 +263,14 @@ Page({ this.setData({ submitting: true }); try { - // 构建提交数据:companies 字段需要转为数组 + // 构建提交数据:companies 字段需要转为数组;email 走独立绑定接口,不随资料提交 const submitData = { ...form, companies: form.companies ? (Array.isArray(form.companies) ? form.companies : [form.companies]) : [], }; + delete submitData.email; const res = await updateProfile(submitData); if (res.success) { wx.showToast({ diff --git a/wechat-miniprogram/pages/edit-profile/index.wxml b/wechat-miniprogram/pages/edit-profile/index.wxml index ed939c8..0ffdae8 100644 --- a/wechat-miniprogram/pages/edit-profile/index.wxml +++ b/wechat-miniprogram/pages/edit-profile/index.wxml @@ -21,6 +21,25 @@ /> + + + + + + + 手机号 - - 职位 - - - - - 拆书家级别 - - - {{form.chaishuLevel || '请选择拆书家级别'}} - › - - - - 行业 - - 邮箱 - - - 专长 { Page({ data: { loading: false, + showIdentifierLogin: false, + identifier: '', }, goBack() { @@ -51,10 +53,11 @@ Page({ // 从 e.detail 提取手机号(如果有) const phoneNumber = e.detail?.phoneNumber || null; - // 发送 code 和手机号到后端 + // 发送 code 和手机号到后端;带 e.detail.phoneNumber 即视为运营商验证过的注册凭证 const res = await post('/auth/login', { code, phone: phoneNumber, + phoneVerified: !!e.detail?.phoneNumber, }); console.log('登录返回:', res); @@ -80,18 +83,47 @@ Page({ } }, - onReject() { - wx.showModal({ - title: '提示', - content: '需要授权才能使用完整功能', - showCancel: false, - }); + toggleIdentifierLogin() { + this.setData({ showIdentifierLogin: !this.data.showIdentifierLogin }); }, - onShareAppMessage() { - return { - title: '拆约 - 拆书活动邀约平台', - path: '/pages/home/index', - }; + onIdentifierInput(e) { + this.setData({ identifier: e.detail.value }); + }, + + async handleIdentifierLogin() { + const raw = (this.data.identifier || '').trim(); + if (!raw) { + wx.showToast({ title: '请输入手机号、微信号或邮箱', icon: 'none' }); + return; + } + if (this.data.loading) return; + this.setData({ loading: true }); + try { + const isEmail = /^[\w.+-]+@[\w-]+(\.[\w-]+)+$/.test(raw); + const isCnPhone = /^1\d{10}$/.test(raw); + if (!isEmail && !isCnPhone) { + wx.showToast({ title: '请输入正确的手机号或邮箱', icon: 'none' }); + return; + } + const payload = isEmail ? { email: raw } : { phone: raw }; + const res = await post('/auth/login', payload, { showLoading: false }); + + if (res.success && res.data) { + const { token, user } = res.data; + saveLoginState(token, user?.id, user); + wx.showToast({ title: '登录成功', icon: 'success' }); + setTimeout(() => { + wx.switchTab({ url: '/pages/home/index' }); + }, 1500); + } else { + wx.showToast({ title: res.message || '登录失败', icon: 'none' }); + } + } catch (err) { + console.error('登录异常:', err); + wx.showToast({ title: err.message || '登录失败,请重试', icon: 'none' }); + } finally { + this.setData({ loading: false }); + } }, }); diff --git a/wechat-miniprogram/pages/login/index.wxml b/wechat-miniprogram/pages/login/index.wxml index ece9d8c..126f4b5 100644 --- a/wechat-miniprogram/pages/login/index.wxml +++ b/wechat-miniprogram/pages/login/index.wxml @@ -25,6 +25,38 @@ {{loading ? '登录中...' : '手机号快速验证'}} + + + 其他登录方式 + + + + + + diff --git a/wechat-miniprogram/pages/login/index.wxss b/wechat-miniprogram/pages/login/index.wxss index 0873cad..ed2ecfa 100644 --- a/wechat-miniprogram/pages/login/index.wxss +++ b/wechat-miniprogram/pages/login/index.wxss @@ -101,6 +101,92 @@ color: #ffffff; } +.divider { + display: flex; + align-items: center; + width: 100%; + margin: 48rpx 0 8rpx; +} + +.divider-line { + flex: 1; + height: 1rpx; + background-color: #eeeeee; +} + +.divider-text { + font-size: 24rpx; + color: #999999; + margin: 0 24rpx; +} + +.identifier-login { + display: flex; + flex-direction: column; + width: 100%; +} + +.identifier-input { + width: 100%; + height: 96rpx; + box-sizing: border-box; + padding: 0 32rpx; + border: 2rpx solid #eeeeee; + border-radius: 48rpx; + background-color: #f7f8fa; + font-size: 30rpx; + color: #333333; +} + +.identifier-placeholder { + color: #bbbbbb; + font-size: 28rpx; +} + +.identifier-login-btn { + display: flex; + align-items: center; + justify-content: center; + width: 100%; + height: 96rpx; + margin-top: 24rpx; + background-color: #333333; + border-radius: 48rpx; + border: none; +} + +.identifier-login-btn[disabled] { + background-color: #777777; +} + +.identifier-btn-text { + font-size: 32rpx; + font-weight: 500; + color: #ffffff; +} + +.identifier-tip { + margin-top: 24rpx; + display: flex; + justify-content: center; +} + +.identifier-tip text { + font-size: 22rpx; + color: #999999; +} + +.toggle-login-wrap { + display: flex; + justify-content: center; + margin-top: 40rpx; +} + +.toggle-login-text { + font-size: 26rpx; + color: #4A90E2; +} + .login-tips { display: flex; align-items: center; diff --git a/yaoyue-sever/admin-web/index.html b/yaoyue-sever/admin-web/index.html index c6b2971..30598ff 100644 --- a/yaoyue-sever/admin-web/index.html +++ b/yaoyue-sever/admin-web/index.html @@ -35,7 +35,10 @@ .topbar .who a { color: var(--red); cursor: pointer; text-decoration: none; } .container { max-width: 1100px; margin: 24px auto; padding: 0 24px; } - .stats { display: grid; grid-template-columns: repeat(4, 1fr); gap: 16px; margin-bottom: 22px; } + .stats { display: grid; grid-template-columns: repeat(5, 1fr); gap: 16px; margin-bottom: 22px; } + .tabs { display: flex; gap: 8px; margin-bottom: 16px; } + .tab { border: 1px solid var(--line); background: var(--card); border-radius: 8px; padding: 9px 20px; font-size: 14px; cursor: pointer; color: var(--muted); } + .tab.active { background: var(--brand); border-color: var(--brand); color: #fff; font-weight: 500; } .stat-card { background: var(--card); border-radius: 12px; padding: 18px 20px; border: 1px solid var(--line); } .stat-card .num { font-size: 26px; font-weight: 700; } .stat-card .label { color: var(--muted); font-size: 13px; margin-top: 4px; } @@ -110,11 +113,15 @@
-
+
+ + +
+

用户列表

@@ -122,7 +129,7 @@ - + @@ -135,6 +142,31 @@ +
用户手机号活动数注册时间角色操作用户邮箱微信号手机号职业/公司籍贯专长拆书帮活动数注册时间角色操作
+ + + + + + +
姓名城市/分舵等级微信号邮箱师父标签
+
+ +
+ + + +
+
@@ -151,14 +183,23 @@ - -