Browse Source

🐞 fix: 修复部分bug

Pchen0 1 month ago
parent
commit
a28c1f33a3

+ 1 - 1
apis/User/uniLogin/BindSocial.js

@@ -7,7 +7,7 @@ const {
     getBindingByIdentity,
     getBindingByIdentity,
     getUserSocialBindings,
     getUserSocialBindings,
     insertSocialBinding,
     insertSocialBinding,
-            updateSocialBindingProfile,
+    updateSocialBindingProfile,
     syncLegacySocialMirror,
     syncLegacySocialMirror,
     toSocialBindingSummary
     toSocialBindingSummary
 } = require('../../../lib/UserSocialBinding')
 } = require('../../../lib/UserSocialBinding')

+ 18 - 3
apis/User/uniLogin/GetLoginUrl.js

@@ -25,13 +25,28 @@ class GetLoginUrl extends API {
 
 
         const uniConfig = config.unilogin
         const uniConfig = config.unilogin
 
 
+        /** 解析 URL 与 hash 内查询串,判断 query 是否已包含某键(避免对整段 URL 做子串误判) */
+        const redirectUrlHasQueryKey = (redirectUrl, key) => {
+            if (!redirectUrl || !key) return false
+            try {
+                const u = new URL(redirectUrl)
+                if (u.searchParams.has(key)) return true
+                const h = u.hash || ''
+                const qPos = h.indexOf('?')
+                if (qPos === -1) return false
+                return new URLSearchParams(h.slice(qPos + 1)).has(key)
+            } catch {
+                return false
+            }
+        }
+
         const appendQuery = (redirectUrl) => {
         const appendQuery = (redirectUrl) => {
             const params = []
             const params = []
-            if (mode && !redirectUrl.includes('mode='))
+            if (mode && !redirectUrlHasQueryKey(redirectUrl, 'mode'))
                 params.push(`mode=${encodeURIComponent(mode)}`)
                 params.push(`mode=${encodeURIComponent(mode)}`)
-            if (action)
+            if (action && !redirectUrlHasQueryKey(redirectUrl, 'action'))
                 params.push(`action=${encodeURIComponent(action)}`)
                 params.push(`action=${encodeURIComponent(action)}`)
-            if (from)
+            if (from && !redirectUrlHasQueryKey(redirectUrl, 'from'))
                 params.push(`from=${encodeURIComponent(from)}`)
                 params.push(`from=${encodeURIComponent(from)}`)
 
 
             if (params.length === 0)
             if (params.length === 0)

+ 5 - 5
apis/User/uniLogin/UnbindSocial.js

@@ -19,15 +19,15 @@ class UnbindSocial extends API {
     }
     }
 
 
     async onRequest(req, res) {
     async onRequest(req, res) {
-        let { uuid, session, social_type } = req.body
-        social_type = normalizeSocialType(social_type)
+        let { uuid, session, type, social_type } = req.body
+        const channelType = normalizeSocialType(type ?? social_type)
 
 
         if ([uuid, session].some(value => value === '' || value === null || value === undefined))
         if ([uuid, session].some(value => value === '' || value === null || value === undefined))
             return res.json({
             return res.json({
                 ...BaseStdResponse.MISSING_PARAMETER
                 ...BaseStdResponse.MISSING_PARAMETER
             })
             })
 
 
-        if (!social_type)
+        if (!channelType)
             return res.json({
             return res.json({
                 ...BaseStdResponse.ERR,
                 ...BaseStdResponse.ERR,
                 msg: '不支持的第三方账号类型'
                 msg: '不支持的第三方账号类型'
@@ -40,7 +40,7 @@ class UnbindSocial extends API {
 
 
         try {
         try {
             const bindings = await getUserSocialBindings(uuid)
             const bindings = await getUserSocialBindings(uuid)
-            if (!bindings.some(binding => binding.social_type === social_type))
+            if (!bindings.some(binding => binding.social_type === channelType))
                 return res.json({
                 return res.json({
                     ...BaseStdResponse.ERR,
                     ...BaseStdResponse.ERR,
                     msg: '当前账号未绑定该第三方账号'
                     msg: '当前账号未绑定该第三方账号'
@@ -59,7 +59,7 @@ class UnbindSocial extends API {
                     msg: '请先设置登录密码或绑定其他第三方账号后再解绑'
                     msg: '请先设置登录密码或绑定其他第三方账号后再解绑'
                 })
                 })
 
 
-            const result = await removeSocialBinding(uuid, social_type)
+            const result = await removeSocialBinding(uuid, channelType)
             if (!result || result.affectedRows !== 1)
             if (!result || result.affectedRows !== 1)
                 return res.json({
                 return res.json({
                     ...BaseStdResponse.ERR,
                     ...BaseStdResponse.ERR,