From 880f2b80db79428c0ac13850c4f8132b441c06ea Mon Sep 17 00:00:00 2001 From: chenruilong Date: Fri, 25 Nov 2022 15:31:52 +0800 Subject: [PATCH] =?UTF-8?q?feat(uni-id-co):=20=E6=96=B0=E5=A2=9E=20?= =?UTF-8?q?=E5=A4=96=E9=83=A8=E7=B3=BB=E7=BB=9F=E8=81=94=E7=99=BB=E6=8E=A5?= =?UTF-8?q?=E5=8F=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../cloudfunctions/uni-id-co/index.obj.js | 28 +++++++++- .../uni-id-co/module/external/index.js | 4 ++ .../uni-id-co/module/external/login.js | 29 +++++++++++ .../uni-id-co/module/external/register.js | 52 +++++++++++++++++++ 4 files changed, 112 insertions(+), 1 deletion(-) create mode 100644 uni_modules/uni-id-pages/uniCloud/cloudfunctions/uni-id-co/module/external/index.js create mode 100644 uni_modules/uni-id-pages/uniCloud/cloudfunctions/uni-id-co/module/external/login.js create mode 100644 uni_modules/uni-id-pages/uniCloud/cloudfunctions/uni-id-co/module/external/register.js diff --git a/uni_modules/uni-id-pages/uniCloud/cloudfunctions/uni-id-co/index.obj.js b/uni_modules/uni-id-pages/uniCloud/cloudfunctions/uni-id-co/index.obj.js index 8ead4f6..7d92eda 100644 --- a/uni_modules/uni-id-pages/uniCloud/cloudfunctions/uni-id-co/index.obj.js +++ b/uni_modules/uni-id-pages/uniCloud/cloudfunctions/uni-id-co/index.obj.js @@ -81,6 +81,11 @@ const { getSupportedLoginType } = require('./module/dev/index') +const { + externalRegister, + externalLogin +} = require('./module/external') + module.exports = { async _before () { // 支持 callFunction 与 URL化 @@ -189,6 +194,9 @@ module.exports = { this.response = {} + // 请求鉴权验证 + await this.middleware.verifyRequestSign() + // 通用权限校验模块 await this.middleware.accessControl() }, @@ -586,5 +594,23 @@ module.exports = { /** * 安全网络握手,目前仅处理微信小程序安全网络握手 */ - secureNetworkHandshakeByWeixin + secureNetworkHandshakeByWeixin, + /** + * 设置密码 + * @tutorial https://uniapp.dcloud.net.cn/uniCloud/uni-id-pages.html#set-pwd + * @returns + */ + setPwd, + /** + * 外部用户注册,将自身系统的用户账号导入uniId,为其创建一个对应uniId的账号(unieid),使得该账号可以使用依赖uniId的系统及功能。 + * @tutorial https://uniapp.dcloud.net.cn/uniCloud/uni-id-pages.html#external-register + * @returns + */ + externalRegister, + /** + * 外部用户登录,使用unieid即可登录 + * @tutorial https://uniapp.dcloud.net.cn/uniCloud/uni-id-pages.html#external-login + * @returns + * */ + externalLogin } diff --git a/uni_modules/uni-id-pages/uniCloud/cloudfunctions/uni-id-co/module/external/index.js b/uni_modules/uni-id-pages/uniCloud/cloudfunctions/uni-id-co/module/external/index.js new file mode 100644 index 0000000..fe2ab8b --- /dev/null +++ b/uni_modules/uni-id-pages/uniCloud/cloudfunctions/uni-id-co/module/external/index.js @@ -0,0 +1,4 @@ +module.exports = { + externalRegister: require('./register'), + externalLogin: require('./login') +} diff --git a/uni_modules/uni-id-pages/uniCloud/cloudfunctions/uni-id-co/module/external/login.js b/uni_modules/uni-id-pages/uniCloud/cloudfunctions/uni-id-co/module/external/login.js new file mode 100644 index 0000000..2eccf09 --- /dev/null +++ b/uni_modules/uni-id-pages/uniCloud/cloudfunctions/uni-id-co/module/external/login.js @@ -0,0 +1,29 @@ +const { preLogin, postLogin } = require('../../lib/utils/login') + +module.exports = async function (params = {}) { + const schema = { + unieid: 'username' + } + + this.middleware.validate(params, schema) + + const { + unieid + } = params + + const user = await preLogin.call(this, { + user: { + username: unieid + } + }) + + const result = await postLogin.call(this, { + user + }) + + return { + errCode: result.errCode, + newToken: result.newToken, + unieid + } +} diff --git a/uni_modules/uni-id-pages/uniCloud/cloudfunctions/uni-id-co/module/external/register.js b/uni_modules/uni-id-pages/uniCloud/cloudfunctions/uni-id-co/module/external/register.js new file mode 100644 index 0000000..ad65c1e --- /dev/null +++ b/uni_modules/uni-id-pages/uniCloud/cloudfunctions/uni-id-co/module/external/register.js @@ -0,0 +1,52 @@ +const { preRegister, postRegister } = require('../../lib/utils/register') + +module.exports = async function (params = {}) { + const schema = { + unieid: 'username', + nickname: { + required: false, + type: 'nickname' + }, + gender: { + required: false, + type: 'number' + }, + avatar: { + required: false, + type: 'string' + } + } + + this.middleware.validate(params, schema) + + const { + unieid, + avatar, + gender, + nickname + } = params + + await preRegister.call(this, { + user: { + username: unieid + } + }) + + const result = await postRegister.call(this, { + user: { + username: unieid, + avatar, + gender, + nickname + } + }) + + return { + errCode: result.errCode, + newToken: result.newToken, + unieid, + avatar, + gender, + nickname + } +} -- GitLab