提交 0fe5bd2b 编写于 作者: DCloud_JSON's avatar DCloud_JSON

更新 新增配置check_mobile,用于配置在发起会话和申请加入群聊时,是否校验手机号码

上级 5a7c2ff2
......@@ -5,6 +5,15 @@ const dbCmd = db.command
const $ = dbCmd.aggregate
const md5 = str => crypto.createHash('md5').update(str).digest('hex')
function getConfig(key) {
// 获取 uni-im 配置
const createConfig = require("uni-config-center");
const uniImConfig = createConfig({
pluginId: 'uni-im', // 插件 id
})
return uniImConfig.config(key)
}
function getConversationId({
group_id,
from_uid,
......@@ -77,5 +86,6 @@ module.exports = {
hideUsernameStr,
hideEmailStr,
hideMobileStr,
checkParam
checkParam,
getConfig
}
\ No newline at end of file
......@@ -439,7 +439,9 @@ async function _createOrUpdateConversation(conversation_id, msgData, chat_source
// 不存在,需要先创建会话记录
else if (!senderConversation) {
// 除了云函数之间(包括触发器)调用 和 特殊角色用户,需验证是否绑定了手机号码
const check_mobile = uniImConfig.config('check_mobile')
if (
check_mobile &&
this.getClientInfo().source != 'function' &&
!this.current_user_role.includes('uni-im-admin') &&
!this.current_user_role.includes('staff')
......
// schema扩展相关文档请参阅:https://uniapp.dcloud.net.cn/uniCloud/jql-schema-ext.html
const db = uniCloud.database()
let t = Date.now() + parseInt(Math.random() * 999999)
const utils = require('uni-im-utils')
module.exports = {
trigger: {
async beforeCreate({
......@@ -56,8 +55,8 @@ module.exports = {
throw new Error('你已被拉黑,不能加入此群')
}
// 4. 判断用户是否已经绑定手机号,系统管理员除外
console.log('userInfo',userInfo);
if(!userInfo.role.includes('uni-im-admin') && !userInfo.role.includes('staff')){
const check_mobile = utils.getConfig('check_mobile')
if(check_mobile && !userInfo.role.includes('uni-im-admin') && !userInfo.role.includes('staff')){
let res3 = await db.collection('uni-id-users').where({_id:userInfo.uid}).get()
if(!res3.data[0].mobile_confirmed){
throw new Error('账号未绑定手机号无法加入群聊。请完成绑定后退出本系统并重新登录,再尝试加入群聊。')
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册