首次完整推送,
V:1.20240808.006
This commit is contained in:
@ -0,0 +1,35 @@
|
||||
const {
|
||||
CAPTCHA_SCENE
|
||||
} = require('../../common/constants')
|
||||
const {
|
||||
ERROR
|
||||
} = require('../../common/error')
|
||||
|
||||
/**
|
||||
* 创建图形验证码
|
||||
* @tutorial https://uniapp.dcloud.net.cn/uniCloud/uni-id-pages.html#create-captcha
|
||||
* @param {Object} params
|
||||
* @param {String} params.scene 图形验证码使用场景
|
||||
* @returns
|
||||
*/
|
||||
module.exports = async function (params = {}) {
|
||||
const schema = {
|
||||
scene: 'string'
|
||||
}
|
||||
this.middleware.validate(params, schema)
|
||||
|
||||
const { deviceId, platform } = this.getUniversalClientInfo()
|
||||
const {
|
||||
scene
|
||||
} = params
|
||||
if (!(Object.values(CAPTCHA_SCENE).includes(scene))) {
|
||||
throw {
|
||||
errCode: ERROR.INVALID_PARAM
|
||||
}
|
||||
}
|
||||
return this.uniCaptcha.create({
|
||||
deviceId,
|
||||
scene,
|
||||
uniPlatform: platform
|
||||
})
|
||||
}
|
@ -0,0 +1,7 @@
|
||||
module.exports = {
|
||||
createCaptcha: require('./create-captcha'),
|
||||
refreshCaptcha: require('./refresh-captcha'),
|
||||
sendSmsCode: require('./send-sms-code'),
|
||||
sendEmailLink: require('./send-email-link'),
|
||||
sendEmailCode: require('./send-email-code')
|
||||
}
|
@ -0,0 +1,36 @@
|
||||
const {
|
||||
CAPTCHA_SCENE
|
||||
} = require('../../common/constants')
|
||||
const {
|
||||
ERROR
|
||||
} = require('../../common/error')
|
||||
|
||||
/**
|
||||
* 刷新图形验证码
|
||||
* @tutorial https://uniapp.dcloud.net.cn/uniCloud/uni-id-pages.html#refresh-captcha
|
||||
* @param {Object} params
|
||||
* @param {String} params.scene 图形验证码使用场景
|
||||
* @returns
|
||||
*/
|
||||
module.exports = async function (params = {}) {
|
||||
const schema = {
|
||||
scene: 'string'
|
||||
}
|
||||
this.middleware.validate(params, schema)
|
||||
|
||||
const { deviceId, platform } = this.getUniversalClientInfo()
|
||||
|
||||
const {
|
||||
scene
|
||||
} = params
|
||||
if (!(Object.values(CAPTCHA_SCENE).includes(scene))) {
|
||||
throw {
|
||||
errCode: ERROR.INVALID_PARAM
|
||||
}
|
||||
}
|
||||
return this.uniCaptcha.refresh({
|
||||
deviceId,
|
||||
scene,
|
||||
uniPlatform: platform
|
||||
})
|
||||
}
|
@ -0,0 +1,60 @@
|
||||
const {
|
||||
verifyCaptcha
|
||||
} = require('../../lib/utils/captcha')
|
||||
const {
|
||||
EMAIL_SCENE
|
||||
} = require('../../common/constants')
|
||||
const {
|
||||
ERROR
|
||||
} = require('../../common/error')
|
||||
/**
|
||||
* 发送邮箱验证码,可用于登录、注册、绑定邮箱、修改密码等操作
|
||||
* @tutorial
|
||||
* @param {Object} params
|
||||
* @param {String} params.email 邮箱
|
||||
* @param {String} params.captcha 图形验证码
|
||||
* @param {String} params.scene 使用场景
|
||||
* @returns
|
||||
*/
|
||||
module.exports = async function (params = {}) {
|
||||
const schema = {
|
||||
email: 'email',
|
||||
captcha: 'string',
|
||||
scene: 'string'
|
||||
}
|
||||
this.middleware.validate(params, schema)
|
||||
|
||||
const {
|
||||
email,
|
||||
captcha,
|
||||
scene
|
||||
} = params
|
||||
|
||||
if (!(Object.values(EMAIL_SCENE).includes(scene))) {
|
||||
throw {
|
||||
errCode: ERROR.INVALID_PARAM
|
||||
}
|
||||
}
|
||||
|
||||
await verifyCaptcha.call(this, {
|
||||
scene: 'send-email-code',
|
||||
captcha
|
||||
})
|
||||
|
||||
// -- 测试代码
|
||||
await require('../../lib/utils/verify-code')
|
||||
.setEmailVerifyCode.call(this, {
|
||||
email,
|
||||
code: '123456',
|
||||
expiresIn: 180,
|
||||
scene
|
||||
})
|
||||
return {
|
||||
errCode: 'uni-id-invalid-mail-template',
|
||||
errMsg: `已启动测试模式,直接使用:123456作为邮箱验证码即可。\n如果是正式项目,需自行实现发送邮件的相关功能`
|
||||
}
|
||||
// -- 测试代码
|
||||
|
||||
|
||||
//发送邮件--需自行实现
|
||||
}
|
@ -0,0 +1,12 @@
|
||||
/**
|
||||
* 发送邮箱链接,可用于登录、注册、绑定邮箱、修改密码等操作
|
||||
* @tutorial
|
||||
* @param {Object} params
|
||||
* @param {String} params.email 邮箱
|
||||
* @param {String} params.scene 使用场景
|
||||
* @returns
|
||||
*/
|
||||
module.exports = async function (params = {}) {
|
||||
// 此接口暂未实现,欢迎向我们提交pr
|
||||
throw new Error('api[sendEmailLink] is not yet implemented')
|
||||
}
|
@ -0,0 +1,71 @@
|
||||
const {
|
||||
sendSmsCode
|
||||
} = require('../../lib/utils/sms')
|
||||
const {
|
||||
verifyCaptcha
|
||||
} = require('../../lib/utils/captcha')
|
||||
const {
|
||||
SMS_SCENE
|
||||
} = require('../../common/constants')
|
||||
const {
|
||||
ERROR
|
||||
} = require('../../common/error')
|
||||
|
||||
/**
|
||||
* 发送短信验证码
|
||||
* @tutorial https://uniapp.dcloud.net.cn/uniCloud/uni-id-pages.html#send-sms-code
|
||||
* @param {Object} params
|
||||
* @param {String} params.mobile 手机号
|
||||
* @param {String} params.captcha 图形验证码
|
||||
* @param {String} params.scene 短信验证码使用场景
|
||||
* @returns
|
||||
*/
|
||||
module.exports = async function (params = {}) {
|
||||
const schema = {
|
||||
mobile: 'mobile',
|
||||
captcha: 'string',
|
||||
scene: 'string'
|
||||
}
|
||||
this.middleware.validate(params, schema)
|
||||
const {
|
||||
mobile,
|
||||
captcha,
|
||||
scene
|
||||
} = params
|
||||
if (!(Object.values(SMS_SCENE).includes(scene))) {
|
||||
throw {
|
||||
errCode: ERROR.INVALID_PARAM
|
||||
}
|
||||
}
|
||||
await verifyCaptcha.call(this, {
|
||||
scene: 'send-sms-code',
|
||||
captcha
|
||||
})
|
||||
|
||||
// -- 测试代码
|
||||
const {
|
||||
templateId
|
||||
} = (this.config.service &&
|
||||
this.config.service.sms &&
|
||||
this.config.service.sms.scene &&
|
||||
this.config.service.sms.scene[scene]) || {}
|
||||
if (!templateId || !templateId.replace(/[^0-9a-zA-Z]/g, '')) {
|
||||
await require('../../lib/utils/verify-code')
|
||||
.setMobileVerifyCode.call(this, {
|
||||
mobile: params.mobile,
|
||||
code: '123456',
|
||||
expiresIn: 180,
|
||||
scene
|
||||
})
|
||||
return {
|
||||
errCode: 'uni-id-invalid-sms-template-id',
|
||||
errMsg: `未找到scene=${scene},的短信模版templateId。\n已启动测试模式,直接使用:123456作为短信验证码即可。\n如果是正式项目,请在路径:/common/uni-config-center/uni-id/config.json中service->sms中配置密钥等信息\n更多详情:https://uniapp.dcloud.io/uniCloud/uni-id.html#config`
|
||||
}
|
||||
}
|
||||
// -- 测试代码
|
||||
|
||||
return sendSmsCode.call(this, {
|
||||
mobile,
|
||||
scene
|
||||
})
|
||||
}
|
Reference in New Issue
Block a user