提交 e2445e17 编写于 作者: C chenruilong

fix(uni-id-co): 优化外部用户联登数据结构

(cherry picked from commit 9bf6dc01)
上级 d9820861
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)
}
......
......@@ -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
}
......
module.exports = {
externalRegister: require('./register'),
externalLogin: require('./login')
externalLogin: require('./login'),
updateUserInfoByExternal: require('./update-user-info')
}
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
}
}
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,
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
}
}
......@@ -459,6 +459,14 @@
"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": []
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册