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 36a7cbf119d722db3a87d617ef89aa7d51a454b9..1fd25f0ecfa029bc7c5319f80f2ebf8c07dca937 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 085d64ab2a16bca1c59230adbdb2f673cf1860bd..ed2f7b632f633702c35236df010b3417ffed74fa 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 fe2ab8b0ed25bb4713c76efeab607c335e5254e4..6fa597f5cf1265dc7b9e209593de51e79abe3aa0 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 2eccf099b56532ac0f2b527a7b10d4bb21c90552..af13013b7027bf13c1cba05aecfab1b1c6a4db17 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 ad65c1ed4d8fbcb3e4da37ee830dbbcd37cb7ae9..783fe7f1c440db4b4aecf2288aae07e17ab3cd27 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 53cc584f1ae6823d49d021dd685e47a538a7d2ab..73432177be18c660da9739c2146ad6d7fa9a9b1e 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 @@ -450,7 +450,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 +}