提交 328be04d 编写于 作者: 雪洛's avatar 雪洛

feat: before register hook

上级 57d76638
......@@ -108,6 +108,7 @@ module.exports = {
context: this
})
this.config = this.configUtils.getPlatformConfig()
this.hooks = this.configUtils.getHooks()
this.validator = new Validator({
passwordStrength: this.config.passwordStrength || 'medium'
......
const path = require('path')
const fs = require('fs')
const {
getWeixinPlatform
} = require('./weixin')
......@@ -112,6 +114,15 @@ class ConfigUtils {
})
return oauthConfig
}
getHooks () {
const configPath = require.resolve('uni-config-center/uni-id')
const hookPath = path.resolve(configPath, 'hooks/index.js')
if (fs.existsSync(hookPath)) {
return require(hookPath)
}
return {}
}
}
module.exports = ConfigUtils
......@@ -69,10 +69,12 @@ async function preRegisterWithPassword (params = {}) {
}
}
async function thirdPartyRegister () {
async function thirdPartyRegister ({
user = {}
} = {}) {
return {
mobileConfirmed: false,
emailConfirmed: false
mobileConfirmed: !!(user.mobile && user.mobile_confirmed) || false,
emailConfirmed: !!(user.email && user.email_confirmed) || false
}
}
......@@ -145,9 +147,18 @@ async function postRegister (params = {}) {
user.invite_time = inviteTime
}
const beforeRegister = this.hooks.beforeRegister
let userRecord = user
if (beforeRegister) {
userRecord = await beforeRegister({
userRecord,
clientInfo: this.getClientInfo()
})
}
const {
id: uid
} = await userCollection.add(user)
} = await userCollection.add(userRecord)
const {
token,
......@@ -174,7 +185,7 @@ async function postRegister (params = {}) {
isThirdParty
? thirdPartyRegister({
user: {
...user,
...userRecord,
_id: uid
}
})
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册