From e3028713495533fbbf2863ba1115900f779a3598 Mon Sep 17 00:00:00 2001 From: chenruilong Date: Wed, 8 Feb 2023 11:42:48 +0800 Subject: [PATCH] =?UTF-8?q?fix(uni-id-co):=20=E4=BC=98=E5=8C=96=E5=A4=96?= =?UTF-8?q?=E9=83=A8=E7=94=A8=E6=88=B7=E8=81=94=E7=99=BB=E6=95=B0=E6=8D=AE?= =?UTF-8?q?=E7=BB=93=E6=9E=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit (cherry picked from commit 9bf6dc01cdc61a426031de4c224ee823180ce251) --- .../uni-id-co/lib/utils/account.js | 3 +- .../uni-id-co/module/admin/update-user.js | 5 +- .../uni-id-co/module/external/index.js | 3 +- .../uni-id-co/module/external/login.js | 51 ++++++++++++++++--- .../uni-id-co/module/external/register.js | 39 +++++++++++--- .../database/uni-id-users.schema.json | 10 +++- 6 files changed, 92 insertions(+), 19 deletions(-) diff --git a/uni_modules/uni-id-pages/uniCloud/cloudfunctions/uni-id-co/lib/utils/account.js b/uni_modules/uni-id-pages/uniCloud/cloudfunctions/uni-id-co/lib/utils/account.js index 36a7cbf..1fd25f0 100644 --- a/uni_modules/uni-id-pages/uniCloud/cloudfunctions/uni-id-co/lib/utils/account.js +++ b/uni_modules/uni-id-pages/uniCloud/cloudfunctions/uni-id-co/lib/utils/account.js @@ -1,5 +1,4 @@ const { - db, dbCmd, userCollection } = require('../../common/constants') @@ -85,6 +84,8 @@ function getUserQueryCondition (userRecord = {}) { username: username.toLowerCase() }) } + } else if (key === 'identities') { + queryItem.identities = dbCmd.elemMatch(value) } condition.push(queryItem) } diff --git a/uni_modules/uni-id-pages/uniCloud/cloudfunctions/uni-id-co/module/admin/update-user.js b/uni_modules/uni-id-pages/uniCloud/cloudfunctions/uni-id-co/module/admin/update-user.js index 085d64a..ed2f7b6 100644 --- a/uni_modules/uni-id-pages/uniCloud/cloudfunctions/uni-id-co/module/admin/update-user.js +++ b/uni_modules/uni-id-pages/uniCloud/cloudfunctions/uni-id-co/module/admin/update-user.js @@ -83,10 +83,10 @@ module.exports = async function (params = {}) { username, dcloud_appid: authorizedApp, nickname, - role: role, + role, mobile, email, - tags: tags, + tags, status } @@ -132,7 +132,6 @@ module.exports = async function (params = {}) { await userCollection.doc(uid).update(realData) - return { errCode: 0 } diff --git a/uni_modules/uni-id-pages/uniCloud/cloudfunctions/uni-id-co/module/external/index.js b/uni_modules/uni-id-pages/uniCloud/cloudfunctions/uni-id-co/module/external/index.js index fe2ab8b..6fa597f 100644 --- a/uni_modules/uni-id-pages/uniCloud/cloudfunctions/uni-id-co/module/external/index.js +++ b/uni_modules/uni-id-pages/uniCloud/cloudfunctions/uni-id-co/module/external/index.js @@ -1,4 +1,5 @@ module.exports = { externalRegister: require('./register'), - externalLogin: require('./login') + externalLogin: require('./login'), + updateUserInfoByExternal: require('./update-user-info') } diff --git a/uni_modules/uni-id-pages/uniCloud/cloudfunctions/uni-id-co/module/external/login.js b/uni_modules/uni-id-pages/uniCloud/cloudfunctions/uni-id-co/module/external/login.js index 2eccf09..af13013 100644 --- a/uni_modules/uni-id-pages/uniCloud/cloudfunctions/uni-id-co/module/external/login.js +++ b/uni_modules/uni-id-pages/uniCloud/cloudfunctions/uni-id-co/module/external/login.js @@ -1,20 +1,59 @@ const { preLogin, postLogin } = require('../../lib/utils/login') +const { EXTERNAL_DIRECT_CONNECT_PROVIDER } = require('../../common/constants') +const { ERROR } = require('../../common/error') +/** + * 外部用户登录 + * @tutorial https://uniapp.dcloud.net.cn/uniCloud/uni-id-pages.html#external-login + * @param {object} params + * @param {string} params.uid uni-id体系用户id + * @param {string} params.externalUid 业务系统的用户id + * @returns {object} + */ module.exports = async function (params = {}) { const schema = { - unieid: 'username' + uid: { + required: false, + type: 'string' + }, + externalUid: { + required: false, + type: 'string' + } } this.middleware.validate(params, schema) const { - unieid + uid, + externalUid } = params - const user = await preLogin.call(this, { - user: { - username: unieid + if (!uid && !externalUid) { + throw { + errCode: ERROR.PARAM_REQUIRED, + errMsgValue: { + param: 'uid or externalUid' + } + } + } + + let query + if (uid) { + query = { + _id: uid } + } else { + query = { + identities: { + provider: EXTERNAL_DIRECT_CONNECT_PROVIDER, + uid: externalUid + } + } + } + + const user = await preLogin.call(this, { + user: query }) const result = await postLogin.call(this, { @@ -24,6 +63,6 @@ module.exports = async function (params = {}) { return { errCode: result.errCode, newToken: result.newToken, - unieid + uid: result.uid } } diff --git a/uni_modules/uni-id-pages/uniCloud/cloudfunctions/uni-id-co/module/external/register.js b/uni_modules/uni-id-pages/uniCloud/cloudfunctions/uni-id-co/module/external/register.js index ad65c1e..783fe7f 100644 --- a/uni_modules/uni-id-pages/uniCloud/cloudfunctions/uni-id-co/module/external/register.js +++ b/uni_modules/uni-id-pages/uniCloud/cloudfunctions/uni-id-co/module/external/register.js @@ -1,8 +1,19 @@ const { preRegister, postRegister } = require('../../lib/utils/register') +const { EXTERNAL_DIRECT_CONNECT_PROVIDER } = require('../../common/constants') +/** + * 外部注册用户 + * @tutorial https://uniapp.dcloud.net.cn/uniCloud/uni-id-pages.html#external-register + * @param {object} params + * @param {string} params.externalUid 业务系统的用户id + * @param {string} params.nickname 昵称 + * @param {string} params.gender 性别 + * @param {string} params.avatar 头像 + * @returns {object} + */ module.exports = async function (params = {}) { const schema = { - unieid: 'username', + externalUid: 'string', nickname: { required: false, type: 'nickname' @@ -20,7 +31,7 @@ module.exports = async function (params = {}) { this.middleware.validate(params, schema) const { - unieid, + externalUid, avatar, gender, nickname @@ -28,25 +39,39 @@ module.exports = async function (params = {}) { await preRegister.call(this, { user: { - username: unieid + identities: { + provider: EXTERNAL_DIRECT_CONNECT_PROVIDER, + uid: externalUid + } } }) const result = await postRegister.call(this, { user: { - username: unieid, avatar, gender, - nickname + nickname, + identities: [ + { + provider: EXTERNAL_DIRECT_CONNECT_PROVIDER, + userInfo: { + avatar, + gender, + nickname + }, + uid: externalUid + } + ] } }) return { errCode: result.errCode, newToken: result.newToken, - unieid, + externalUid, avatar, gender, - nickname + nickname, + uid: result.uid } } diff --git a/uni_modules/uni-id-pages/uniCloud/database/uni-id-users.schema.json b/uni_modules/uni-id-pages/uniCloud/database/uni-id-users.schema.json index 20a9be9..f2d13c5 100644 --- a/uni_modules/uni-id-pages/uniCloud/database/uni-id-users.schema.json +++ b/uni_modules/uni-id-pages/uniCloud/database/uni-id-users.schema.json @@ -459,7 +459,15 @@ "read": false, "write": false } + }, + "identities": { + "bsonType": "array", + "description": "三方平台身份信息;一个对象代表一个身份,参数支持: provider 身份源, userInfo 三方用户信息, openid 三方openid, unionid 三方unionid, uid 三方uid", + "permission": { + "read": "'READ_UNI_ID_USERS' in auth.permission", + "write": "'CREATE_UNI_ID_USERS' in auth.permission || 'UPDATE_UNI_ID_USERS' in auth.permission" + } } }, "required": [] -} \ No newline at end of file +} -- GitLab