提交 9bf6dc01 编写于 作者: C chenruilong

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

上级 14112b41
const { const {
db,
dbCmd, dbCmd,
userCollection userCollection
} = require('../../common/constants') } = require('../../common/constants')
...@@ -85,6 +84,8 @@ function getUserQueryCondition (userRecord = {}) { ...@@ -85,6 +84,8 @@ function getUserQueryCondition (userRecord = {}) {
username: username.toLowerCase() username: username.toLowerCase()
}) })
} }
} else if (key === 'identities') {
queryItem.identities = dbCmd.elemMatch(value)
} }
condition.push(queryItem) condition.push(queryItem)
} }
......
...@@ -83,10 +83,10 @@ module.exports = async function (params = {}) { ...@@ -83,10 +83,10 @@ module.exports = async function (params = {}) {
username, username,
dcloud_appid: authorizedApp, dcloud_appid: authorizedApp,
nickname, nickname,
role: role, role,
mobile, mobile,
email, email,
tags: tags, tags,
status status
} }
...@@ -132,7 +132,6 @@ module.exports = async function (params = {}) { ...@@ -132,7 +132,6 @@ module.exports = async function (params = {}) {
await userCollection.doc(uid).update(realData) await userCollection.doc(uid).update(realData)
return { return {
errCode: 0 errCode: 0
} }
......
module.exports = { module.exports = {
externalRegister: require('./register'), externalRegister: require('./register'),
externalLogin: require('./login') externalLogin: require('./login'),
updateUserInfoByExternal: require('./update-user-info')
} }
const { preLogin, postLogin } = require('../../lib/utils/login') 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 = {}) { module.exports = async function (params = {}) {
const schema = { const schema = {
unieid: 'username' uid: {
required: false,
type: 'string'
},
externalUid: {
required: false,
type: 'string'
}
} }
this.middleware.validate(params, schema) this.middleware.validate(params, schema)
const { const {
unieid uid,
externalUid
} = params } = params
const user = await preLogin.call(this, { if (!uid && !externalUid) {
user: { throw {
username: unieid 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, { const result = await postLogin.call(this, {
...@@ -24,6 +63,6 @@ module.exports = async function (params = {}) { ...@@ -24,6 +63,6 @@ module.exports = async function (params = {}) {
return { return {
errCode: result.errCode, errCode: result.errCode,
newToken: result.newToken, newToken: result.newToken,
unieid uid: result.uid
} }
} }
const { preRegister, postRegister } = require('../../lib/utils/register') 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 = {}) { module.exports = async function (params = {}) {
const schema = { const schema = {
unieid: 'username', externalUid: 'string',
nickname: { nickname: {
required: false, required: false,
type: 'nickname' type: 'nickname'
...@@ -20,7 +31,7 @@ module.exports = async function (params = {}) { ...@@ -20,7 +31,7 @@ module.exports = async function (params = {}) {
this.middleware.validate(params, schema) this.middleware.validate(params, schema)
const { const {
unieid, externalUid,
avatar, avatar,
gender, gender,
nickname nickname
...@@ -28,25 +39,39 @@ module.exports = async function (params = {}) { ...@@ -28,25 +39,39 @@ module.exports = async function (params = {}) {
await preRegister.call(this, { await preRegister.call(this, {
user: { user: {
username: unieid identities: {
provider: EXTERNAL_DIRECT_CONNECT_PROVIDER,
uid: externalUid
}
} }
}) })
const result = await postRegister.call(this, { const result = await postRegister.call(this, {
user: { user: {
username: unieid,
avatar, avatar,
gender, gender,
nickname nickname,
identities: [
{
provider: EXTERNAL_DIRECT_CONNECT_PROVIDER,
userInfo: {
avatar,
gender,
nickname
},
uid: externalUid
}
]
} }
}) })
return { return {
errCode: result.errCode, errCode: result.errCode,
newToken: result.newToken, newToken: result.newToken,
unieid, externalUid,
avatar, avatar,
gender, gender,
nickname nickname,
uid: result.uid
} }
} }
...@@ -450,7 +450,15 @@ ...@@ -450,7 +450,15 @@
"read": false, "read": false,
"write": 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": [] "required": []
} }
\ No newline at end of file
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册