提交 98774f75 编写于 作者: DCloud_JSON's avatar DCloud_JSON 提交者: study夏羽

- 更新依赖的的版本为1.0.26

上级 ee031fe9
......@@ -5,6 +5,7 @@
openApp() //创建在h5端全局悬浮引导用户下载app的功能
// #endif
import checkIsAgree from '@/pages/uni-agree/utils/uni-agree.js';
import uniIdPageInit from '@/uni_modules/uni-id-pages/init.js';
export default {
globalData: {
searchText: '',
......@@ -18,8 +19,10 @@
this.globalData.$i18n = this.$i18n
this.globalData.$t = str => this.$t(str)
initApp();
console.log('uni.getPushClientId',uni.getPushClientId);
initApp();
uniIdPageInit()
// #ifdef APP-PLUS
//checkIsAgree(); APP端暂时先用原生默认生成的。目前,自定义方式启动vue界面时,原生层已经请求了部分权限这并不符合国家的法规
......
## 2.0.5(2022-10-19)
- 更新依赖的`uni-id-pages`的版本为1.0.26
## 2.0.4(2022-09-21)
- 新增 使用uni-id-pages的账号信息的状态管理功能
## 2.0.3(2022-09-20)
......
......@@ -47,11 +47,11 @@ export default async function() {
methodName, // 云对象的方法名称
params // 参数列表
}) {
console.log('interceptObject',{
objectName, // 云对象名称
methodName, // 云对象的方法名称
params // 参数列表
});
// console.log('interceptObject',{
// objectName, // 云对象名称
// methodName, // 云对象的方法名称
// params // 参数列表
// });
if(objectName == "uni-id-co" && (methodName.includes('loginBy') || ['login','registerUser'].includes(methodName) )){
console.log('执行登录相关云对象');
params[0].inviteCode = await new Promise((callBack) => {
......@@ -84,7 +84,7 @@ export default async function() {
})
// console.log(params);
}
console.log(params);
// console.log(params);
},
success(e) {
console.log(e);
......@@ -94,17 +94,17 @@ export default async function() {
},
fail(e){
console.error(e);
if (debug) {
uni.showModal({
content: JSON.stringify(e),
showCancel: false
});
}else{
uni.showToast({
title: '系统错误请稍后再试',
icon:'error'
});
}
// if (debug) {
// uni.showModal({
// content: JSON.stringify(e),
// showCancel: false
// });
// }else{
// uni.showToast({
// title: '系统错误请稍后再试',
// icon:'error'
// });
// }
}
})
......
......@@ -40,6 +40,9 @@
"ios": {
},
"sdkConfigs": {
"push": {
"unipush": null
}
}
}
},
......
//这是应用的配置页面,App.vue挂载到getApp().globalData.config
export default {
//是否打开调试模式
"debug":false,
"h5": {
"url": "https://uni-starter.dcloud.net.cn", // 前端网页托管的域名
// 在h5端全局悬浮引导用户下载app的功能 更多自定义要求在/common/openApp.js中修改
......@@ -17,7 +15,7 @@ export default {
"mp": {
"weixin": {
//微信小程序原始id,微信小程序分享时
"id": "gh_33446d7f7a26"
"id": ""
}
},
//关于应用
......
## 1.1.3(2022-09-22)
- 修复,引入 uni.scss 引入默认主题色报错的问题
## 1.1.2(2022-09-22)
- 增加主题色 primaryColor 配置选项
## 1.1.1(2022-09-19)
- 修复,输入后回车,change 事件触发两次,[详情](https://ask.dcloud.net.cn/question/152149)
## 1.1.0(2022-06-30)
......
......@@ -18,7 +18,7 @@
<!-- 开启密码时显示小眼睛 -->
<uni-icons v-if="isVal" class="content-clear-icon" :class="{'is-textarea-icon':type==='textarea'}"
:type="showPassword?'eye-slash-filled':'eye-filled'" :size="22"
:color="focusShow?'#2979ff':'#c0c4cc'" @click="onEyes">
:color="focusShow ? primaryColor :'#c0c4cc'" @click="onEyes">
</uni-icons>
</template>
<template v-else-if="suffixIcon">
......@@ -28,7 +28,7 @@
<template v-else>
<uni-icons v-if="clearable && isVal && !disabled && type !== 'textarea'" class="content-clear-icon"
:class="{'is-textarea-icon':type==='textarea'}" type="clear" :size="clearSize"
:color="msg?'#dd524d':(focusShow?'#2979ff':'#c0c4cc')" @click="onClear"></uni-icons>
:color="msg?'#dd524d':(focusShow? primaryColor :'#c0c4cc')" @click="onClear"></uni-icons>
</template>
<slot name="right"></slot>
</view>
......@@ -59,6 +59,7 @@
* @property {Number } clearSize 清除图标的大小,单位px(默认15)
* @property {String} prefixIcon 输入框头部图标
* @property {String} suffixIcon 输入框尾部图标
* @property {String} primaryColor 设置主题色(默认#2979ff)
* @property {Boolean} trim 是否自动去除两端的空格
* @value both 去除两端空格
* @value left 去除左侧空格
......@@ -177,6 +178,10 @@
type: Boolean,
default: true
},
primaryColor: {
type: String,
default: '#2979ff'
},
styles: {
type: Object,
default () {
......@@ -244,7 +249,7 @@
})
},
inputContentStyle() {
const focusColor = this.focusShow ? '#2979ff' : this.styles.borderColor
const focusColor = this.focusShow ? this.primaryColor : this.styles.borderColor
const borderColor = this.inputBorder && this.msg ? '#dd524d' : focusColor
return obj2strStyle({
'border-color': borderColor || '#e5e5e5',
......
{
"id": "uni-easyinput",
"displayName": "uni-easyinput 增强输入框",
"version": "1.1.1",
"version": "1.1.3",
"description": "Easyinput 组件是对原生input组件的增强",
"keywords": [
"uni-ui",
......
## 1.0.26(2022-10-18)
- 修复 uni-id-pages 导入时异常的Bug
## 1.0.25(2022-10-14)
- uni-id-co 增加 微信授权手机号登录方式 [文档](https://uniapp.dcloud.net.cn/uniCloud/uni-id-pages.html#login-by-weixin-mobile)
- uni-id-co 增加 解绑第三方平台账号 [文档](https://uniapp.dcloud.net.cn/uniCloud/uni-id-pages.html#unbind-third-account)
- uni-id-co 微信绑定手机号支持通过`getPhoneNumber`事件回调的`code`绑定 [文档](https://uniapp.dcloud.net.cn/uniCloud/uni-id-pages.html#bind-mobile-by-mp-weixin)
- 修复 sendSmsCode 接口未在参数内传递 templateId 时 未能从配置文件读取 templateId 的Bug
## 1.0.24(2022-10-08)
- 修复 报uni-id-users表schema内错误的bug
## 1.0.23(2022-10-08)
- 修复 vue3下vite编译发行打包失败
- 修复 某些情况下注册账号,报TypeErroe:Cannot read properties of undefined (reading ’showToast‘)的错误
## 1.0.22(2022-09-23)
- 修复 某些情况下,修改密码报“两次输入密码不一致”的bug
## 1.0.21(2022-09-21)
- 修复 store.hasLogin的值在某些情况下会出错的bug
## 1.0.20(2022-09-21)
......
......@@ -66,7 +66,7 @@ function getPwdRules(pwdName = 'password', rePwdName = 'password2') {
},
{
validateFunction: function(rule, value, data, callback) {
if (value != data.password) {
if (value != data[pwdName]) {
callback(ERROR.normal.rePwdErr)
}
return true
......
......@@ -37,7 +37,7 @@ export const mutations = {
} else {
try {
let res = await usersTable.where("'_id' == $cloudEnv_uid")
.field('mobile,nickname,user_name,email,avatar_file')
.field('mobile,nickname,username,email,avatar_file')
.get()
console.log('fromDbData',res.result.data);
this.setUserInfo(res.result.data[0])
......@@ -69,7 +69,7 @@ export const mutations = {
uni.$emit('uni-id-pages-logout')
this.setUserInfo({},{cover:true})
},
loginSuccess(e){
loginSuccess(e = {}){
const {
showToast = true, toastText = '登录成功', autoBack = true, uniIdRedirectUrl = ''
} = e
......@@ -94,7 +94,7 @@ export const mutations = {
delta++
}
})
console.log('判断需要返回几层:', pages, delta);
// console.log('判断需要返回几层:', delta);
if (uniIdRedirectUrl) {
return uni.reLaunch({
url: uniIdRedirectUrl
......
......@@ -234,7 +234,7 @@
console.log('出乎意料的情况,path:' + path);
}
},
async login_before(type, navigateBack = true) {
async login_before(type, navigateBack = true, options = {}) {
console.log(type);
//提示空实现
if (["qq",
......@@ -300,7 +300,7 @@
let agreementsRef = this.getParentComponent().$refs.agreements
return agreementsRef.popup(() => {
console.log(type, navigateBack);
this.login_before(type, navigateBack)
this.login_before(type, navigateBack, options)
})
}
......@@ -331,7 +331,6 @@
}
// #endif
uni.showLoading({
mask: true
})
......@@ -397,6 +396,13 @@
}
})
}
if (type === 'weixinMobile') {
return this.login({
phoneCode: options.phoneNumberCode
}, type)
}
uni.login({
"provider": type,
"onlyAuthorize": true,
......@@ -429,7 +435,7 @@
type
});
//toLowerCase
let action = 'loginBy' + type.trim().toLowerCase().replace(type[0], type[0].toUpperCase())
let action = 'loginBy' + type.trim().replace(type[0], type[0].toUpperCase())
const uniIdCo = uniCloud.importObject("uni-id-co",{
customUI:true
})
......@@ -441,7 +447,7 @@
});
// #ifdef MP-WEIXIN
//如果是微信小程序端的微信登录,且为首次登录,就弹出获取微信昵称+头像用于绑定资料
if (type == 'weixin' && result.type == "register") {
if (['weixin', 'weixinMobile'].includes(type) && result.type == "register") {
mutations.loginSuccess({
...result,
showToast: false,
......
......@@ -56,6 +56,7 @@ export default async function() {
}
// #endif
/* 注释此代码块原因:与uni-starter中的appinit逻辑一致
//3. 绑定clientDB错误事件
// clientDB对象
const db = uniCloud.database()
......@@ -72,9 +73,9 @@ export default async function() {
}
// 解绑clientDB错误事件
//db.off('error', onDBError)
*/
//4. 同步客户端push_clientid至device表
//4. 同步客户端push_clientid至uni-id-device表
if (uniCloud.onRefreshToken) {
uniCloud.onRefreshToken(() => {
console.log('onRefreshToken');
......@@ -90,7 +91,11 @@ export default async function() {
console.log('getPushClientId', res);
},
fail(e) {
console.log(e)
console.error(e,
"uni-id-pages 默认在刷新token(登录、注销、切换用户)后获取push客户端标识同步至uni-id-device表;",
"\n",
"如果你不使用push模块,请注释或删除,路径:/uni-starter/uni_modules/uni-id-pages/init.js 第79-103行代码"
)
}
})
}
......
{
"id": "uni-id-pages",
"displayName": "uni-id-pages",
"version": "1.0.21",
"version": "1.0.26",
"description": "云端一体简单、统一、可扩展的用户中心页面模版",
"keywords": [
"用户管理",
......
......@@ -7,10 +7,11 @@
<!-- 顶部文字 -->
<text class="title">请选择登录方式</text>
<!-- 快捷登录框 当url带参数时有效 -->
<template v-if="['apple','weixin'].includes(type)">
<template v-if="['apple','weixin', 'weixinMobile'].includes(type)">
<text class="tip">将根据第三方账号服务平台的授权范围获取你的信息</text>
<view class="quickLogin">
<image @click="quickLogin" :src="imgSrc" mode="widthFix" class="quickLoginBtn"></image>
<image v-if="type !== 'weixinMobile'" @click="quickLogin" :src="imgSrc" mode="widthFix" class="quickLoginBtn"></image>
<button v-else type="primary" open-type="getPhoneNumber" @getphonenumber="quickLogin">微信授权手机号登录</button>
<uni-id-pages-agreements scope="register" ref="agreements"></uni-id-pages-agreements>
</view>
</template>
......@@ -98,8 +99,16 @@
//#endif
},
methods: {
quickLogin() {
this.$refs.uniFabLogin.login_before(this.type)
quickLogin(e) {
let options = {}
if (e.detail?.code) {
options.phoneNumberCode = e.detail.code
}
if (this.type === 'weixinMobile' && !e.detail?.code) return
this.$refs.uniFabLogin.login_before(this.type, true, options)
},
toSmsPage() {
console.log('toSmsPage',this.agree);
......
......@@ -53,9 +53,6 @@
mutations
} from '@/uni_modules/uni-id-pages/common/store.js'
const {
loginSuccess
} = mutations
const uniIdCo = uniCloud.importObject("uni-id-co")
export default {
mixins: [mixin],
......@@ -118,7 +115,7 @@
submitForm(params) {
uniIdCo.registerUser(this.formData).then(e => {
console.log(e);
loginSuccess()
this.loginSuccess(e)
})
.catch(e => {
console.log(e);
......
......@@ -30,11 +30,11 @@
</view>
<view v-if="isShowPhotoBtn" @tap="uploadImage">
<slot name="photo" v-if="$slots.photo" />
<image v-else src="uni_modules/uni-id-pages/static/limeClipper/photo.svg" />
<image v-else src="./images/photo.svg" />
</view>
<view v-if="isShowRotateBtn" @tap="rotate">
<slot name="rotate" v-if="$slots.rotate" />
<image v-else src="uni_modules/uni-id-pages/static/limeClipper/rotate.svg" data-type="inverse" />
<image v-else src="./images/rotate.svg" data-type="inverse" />
</view>
<view v-if="isShowConfirmBtn" @tap="confirm">
<slot name="confirm" v-if="$slots.confirm" />
......
......@@ -160,6 +160,41 @@
uni.navigateTo({
url:"/uni_modules/uni-id-pages/pages/userinfo/deactivate/deactivate"
})
},
async bindThirdAccount(provider) {
const uniIdCo = uniCloud.importObject("uni-id-co")
const bindField = {
weixin: 'wx_openid',
alipay: 'ali_openid',
apple: 'apple_openid',
qq: 'qq_openid'
}[provider.toLowerCase()]
if (this.userInfo[bindField]) {
await uniIdCo['unbind' + provider]()
await mutations.updateUserInfo()
} else {
uni.login({
provider: provider.toLowerCase(),
onlyAuthorize: true,
success: async e => {
const res = await uniIdCo['bind' + provider]({
code: e.code
})
if (res.errCode) {
uni.showToast({
title: res.errMsg || '绑定失败'
})
}
await mutations.updateUserInfo()
},
fail: async (err) => {
console.log(err);
uni.hideLoading()
}
})
}
}
}
}
......
......@@ -52,7 +52,11 @@ const LOG_TYPE = {
BIND_WEIXIN: 'bind-weixin',
BIND_QQ: 'bind-qq',
BIND_APPLE: 'bind-apple',
BIND_ALIPAY: 'bind-alipay'
BIND_ALIPAY: 'bind-alipay',
UNBIND_WEIXIN: 'unbind-weixin',
UNBIND_QQ: 'unbind-qq',
UNBIND_ALIPAY: 'unbind-alipay',
UNBIND_APPLE: 'unbind-apple'
}
const SMS_SCENE = {
......
......@@ -30,7 +30,12 @@ const ERROR = {
SET_INVITE_CODE_FAILED: 'uni-id-set-invite-code-failed',
INVALID_INVITE_CODE: 'uni-id-invalid-invite-code',
CHANGE_INVITER_FORBIDDEN: 'uni-id-change-inviter-forbidden',
BIND_CONFLICT: 'uni-id-bind-conflict'
BIND_CONFLICT: 'uni-id-bind-conflict',
UNBIND_FAIL: 'uni-id-unbind-failed',
UNBIND_NOT_SUPPORTED: 'uni-id-unbind-not-supported',
UNBIND_UNIQUE_LOGIN: 'uni-id-unbind-unique-login',
UNBIND_PASSWORD_NOT_EXISTS: 'uni-id-unbind-password-not-exists',
UNBIND_MOBILE_NOT_EXISTS: 'uni-id-unbind-mobile-not-exists'
}
function isUniIdError (errCode) {
......
......@@ -171,6 +171,13 @@ function getNonceStr (length = 16) {
return str.substring(0, length)
}
try {
require('lodash.merge')
} catch (error) {
console.error('uni-id-co缺少依赖,请在uniCloud/cloudfunctions/common/uni-id-co目录执行 npm install 安装依赖')
throw error
}
module.exports = {
getType,
isValidString,
......
......@@ -62,5 +62,17 @@ module.exports = {
},
getAccountInfo: {
auth: true
},
unbindWeixin: {
auth: true
},
unbindAlipay: {
auth: true
},
unbindQQ: {
auth: true
},
unbindApple: {
auth: true
}
}
......@@ -29,7 +29,8 @@ const {
loginByWeixin,
loginByAlipay,
loginByQQ,
loginByApple
loginByApple,
loginByWeixinMobile
} = require('./module/login/index')
const {
logout
......@@ -41,7 +42,11 @@ const {
bindAlipay,
bindApple,
bindQQ,
bindWeixin
bindWeixin,
unbindWeixin,
unbindAlipay,
unbindQQ,
unbindApple
} = require('./module/relate/index')
const {
updatePwd,
......@@ -74,7 +79,7 @@ const {
} = require('./module/dev/index')
module.exports = {
async _before() {
async _before () {
const clientInfo = this.getClientInfo()
/**
* 检查clientInfo,无appId和uniPlatform时本云对象无法正常运行
......@@ -157,7 +162,7 @@ module.exports = {
// 挂载uni-captcha到this上,方便后续调用
this.uniCaptcha = uniCaptcha
Object.defineProperty(this, 'uniOpenBridge', {
get() {
get () {
return require('uni-open-bridge-common')
}
})
......@@ -181,7 +186,7 @@ module.exports = {
// 通用权限校验模块
await this.middleware.accessControl()
},
_after(error, result) {
_after (error, result) {
if (error) {
// 处理中间件内抛出的标准响应对象
if (error.errCode && getType(error) === 'object') {
......@@ -217,6 +222,10 @@ module.exports = {
* @param {String} params.nickname 昵称
* @param {Array} params.authorizedApp 允许登录的AppID列表
* @param {Array} params.role 用户角色列表
* @param {String} params.mobile 手机号
* @param {String} params.email 邮箱
* @param {Array} params.tags 用户标签
* @param {Number} params.status 用户状态
* @returns
*/
addUser,
......@@ -359,6 +368,7 @@ module.exports = {
* @returns
*/
loginByApple,
loginByWeixinMobile,
/**
* 用户退出登录
* @tutorial https://uniapp.dcloud.net.cn/uniCloud/uni-id-pages.html#logout
......@@ -541,5 +551,30 @@ module.exports = {
* @tutorial https://uniapp.dcloud.net.cn/uniCloud/uni-id-pages.html#get-supported-login-type
* @returns
*/
getSupportedLoginType
getSupportedLoginType,
/**
* 解绑微信
* @tutorial https://uniapp.dcloud.net.cn/uniCloud/uni-id-pages.html#unbind-weixin
* @returns
*/
unbindWeixin,
/**
* 解绑支付宝
* @tutorial https://uniapp.dcloud.net.cn/uniCloud/uni-id-pages.html#unbind-alipay
* @returns
*/
unbindAlipay,
/**
* 解绑QQ
* @tutorial https://uniapp.dcloud.net.cn/uniCloud/uni-id-pages.html#unbind-qq
* @returns
*/
unbindQQ,
/**
* 解绑Apple
* @tutorial https://uniapp.dcloud.net.cn/uniCloud/uni-id-pages.html#unbind-apple
* @returns
*/
unbindApple
}
......@@ -12,7 +12,7 @@ const sentence = {
'uni-id-account-audit-failed': 'Account audit failed',
'uni-id-account-closed': 'Account has been closed',
'uni-id-captcha-required': 'Captcha required',
'uni-id-password-error': 'Username or password error',
'uni-id-password-error': 'Password error',
'uni-id-password-error-exceed-limit': 'The number of password errors is excessive',
'uni-id-invalid-username': 'Invalid username',
'uni-id-invalid-password': 'invalid password',
......@@ -35,7 +35,12 @@ const sentence = {
'uni-id-set-invite-code-failed': 'Set invite code failed',
'uni-id-invalid-invite-code': 'Invalid invite code',
'uni-id-change-inviter-forbidden': 'Change inviter is not allowed',
'uni-id-bind-conflict': 'This account has been bound'
'uni-id-bind-conflict': 'This account has been bound',
'uni-id-admin-exist-in-other-apps': 'Administrator is registered in other consoles',
'uni-id-unbind-failed': 'Please bind first and then unbind',
'uni-id-unbind-not-supported': 'Unbinding is not supported',
'uni-id-unbind-mobile-not-exists': 'This is the only way to login at the moment, please bind your phone number and then try to unbind',
'uni-id-unbind-password-not-exists': 'Please set a password first'
}
module.exports = {
......
......@@ -12,7 +12,7 @@ const sentence = {
'uni-id-account-audit-failed': '此账号审核失败',
'uni-id-account-closed': '此账号已注销',
'uni-id-captcha-required': '请输入图形验证码',
'uni-id-password-error': '用户名或密码错误',
'uni-id-password-error': '密码错误',
'uni-id-password-error-exceed-limit': '密码错误次数过多,请稍后再试',
'uni-id-invalid-username': '用户名不合法',
'uni-id-invalid-password': '密码不合法',
......@@ -35,7 +35,12 @@ const sentence = {
'uni-id-set-invite-code-failed': '设置邀请码失败',
'uni-id-invalid-invite-code': '邀请码不可用',
'uni-id-change-inviter-forbidden': '禁止修改邀请人',
'uni-id-bind-conflict': '此账号已被绑定'
'uni-id-bind-conflict': '此账号已被绑定',
'uni-id-admin-exist-in-other-apps': '超级管理员已在其他控制台注册',
'uni-id-unbind-failed': '请先绑定后再解绑',
'uni-id-unbind-not-supported': '不支持解绑',
'uni-id-unbind-mobile-not-exists': '这是当前唯一登录方式,请绑定手机号后再尝试解绑',
'uni-id-unbind-password-not-exists': '请先设置密码在尝试解绑'
}
module.exports = {
......
......@@ -86,4 +86,26 @@ module.exports = class Auth {
avatar
}
}
async getPhoneNumber (accessToken, code) {
const url = `/wxa/business/getuserphonenumber?access_token=${accessToken}`
const { phoneInfo } = await this._requestWxOpenapi({
name: 'getPhoneNumber',
url,
data: {
code
},
options: {
method: 'POST',
dataAsQueryString: false,
headers: {
'content-type': 'application/json'
}
}
})
return {
purePhoneNumber: phoneInfo.purePhoneNumber
}
}
}
......@@ -219,7 +219,8 @@ async function postLogin (params = {}) {
user
})
: {}
)
),
passwordConfirmed: !!user.password
}
}
......
......@@ -5,8 +5,15 @@ const {
ERROR
} = require('../../common/error')
const {
userCollection
userCollection, dbCmd, USER_IDENTIFIER
} = require('../../common/constants')
const {
getUserIdentifier
} = require('../../lib/utils/account')
const {
batchFindObjctValue
} = require('../../common/utils')
const merge = require('lodash.merge')
/**
......@@ -56,7 +63,100 @@ async function postBind ({
}
}
async function preUnBind ({
uid,
unBindAccount,
logType
}) {
const notUnBind = ['username', 'mobile', 'email']
const userIdentifier = getUserIdentifier(unBindAccount)
const condition = Object.keys(userIdentifier).reduce((res, key) => {
if (userIdentifier[key]) {
if (notUnBind.includes(key)) {
throw {
errCode: ERROR.UNBIND_NOT_SUPPORTED
}
}
res.push({
[key]: userIdentifier[key]
})
}
return res
}, [])
const currentUnBindAccount = Object.keys(userIdentifier).reduce((res, key) => {
if (userIdentifier[key]) {
res.push(key)
}
return res
}, [])
const { data: users } = await userCollection.where(dbCmd.and(
{ _id: uid },
dbCmd.or(condition)
)).get()
if (users.length <= 0) {
await this.middleware.uniIdLog({
data: {
user_id: uid
},
type: logType,
success: false
})
throw {
errCode: ERROR.UNBIND_FAIL
}
}
const [user] = users
const otherAccounts = batchFindObjctValue(user, Object.keys(USER_IDENTIFIER).filter(key => !notUnBind.includes(key) && !currentUnBindAccount.includes(key)))
let hasOtherAccountBind = false
for (const key in otherAccounts) {
if (otherAccounts[key]) {
hasOtherAccountBind = true
break
}
}
// 如果没有其他第三方登录方式
if (!hasOtherAccountBind) {
// 存在用户名或者邮箱但是没有设置过没密码就提示设置密码
if ((user.username || user.email) && !user.password) {
throw {
errCode: ERROR.UNBIND_PASSWORD_NOT_EXISTS
}
}
// 账号任何登录方式都没有就优先绑定手机号
if (!user.mobile) {
throw {
errCode: ERROR.UNBIND_MOBILE_NOT_EXISTS
}
}
}
}
async function postUnBind ({
uid,
unBindAccount,
logType
}) {
await userCollection.doc(uid).update(unBindAccount)
await this.middleware.uniIdLog({
data: {
user_id: uid
},
type: logType
})
return {
errCode: 0
}
}
module.exports = {
preBind,
postBind
postBind,
preUnBind,
postUnBind
}
......@@ -45,7 +45,7 @@ async function sendSmsCode ({
action = this.t('verify-mobile')
break
}
const sceneConfig = smsConfig.scene || {}
const sceneConfig = (smsConfig.scene || {})[scene] || {}
if (!templateId) {
templateId = sceneConfig.templateId
}
......
......@@ -177,10 +177,22 @@ async function getWeixinCache ({
})
}
async function getWeixinAccessToken () {
const weixinPlatform = getWeixinPlatform.call(this)
const appId = this.getClientInfo().appId
const cache = await this.uniOpenBridge.getAccessToken({
dcloudAppid: appId,
platform: 'weixin-' + weixinPlatform
})
return cache.access_token
}
module.exports = {
decryptWeixinData,
getWeixinPlatform,
generateWeixinCache,
getWeixinCache,
saveWeixinUserKey
saveWeixinUserKey,
getWeixinAccessToken
}
......@@ -15,5 +15,6 @@ module.exports = {
loginByEmailLink: require('./login-by-email-link'),
loginByEmailCode: require('./login-by-email-code'),
loginByFacebook: require('./login-by-facebook'),
loginByGoogle: require('./login-by-google')
loginByGoogle: require('./login-by-google'),
loginByWeixinMobile: require('./login-by-weixin-mobile')
}
const {
initWeixin
} = require('../../lib/third-party/index')
const {
getWeixinPlatform,
getWeixinAccessToken,
generateWeixinCache,
saveWeixinUserKey
} = require('../../lib/utils/weixin')
const {
ERROR
} = require('../../common/error')
const {
preUnifiedLogin,
postUnifiedLogin
} = require('../../lib/utils/unified-login')
const {
LOG_TYPE
} = require('../../common/constants')
const {
preBind,
postBind
} = require('../../lib/utils/relate')
/**
* 微信授权手机号登录
* @tutorial https://uniapp.dcloud.net.cn/uniCloud/uni-id-pages.html#login-by-weixin-mobile
* @param {Object} params
* @param {String} params.phoneCode 微信手机号返回的code
* @param {String} params.inviteCode 邀请码
* @returns
*/
module.exports = async function (params = {}) {
const schema = {
phoneCode: 'string',
inviteCode: {
type: 'string',
required: false
}
}
this.middleware.validate(params, schema)
const { phoneCode, inviteCode } = params
const weixinApi = initWeixin.call(this)
let mobile
try {
const accessToken = await getWeixinAccessToken.call(this)
const mobileRes = await weixinApi.getPhoneNumber(accessToken, phoneCode)
mobile = mobileRes.purePhoneNumber
} catch (error) {
console.error(error)
await this.middleware.uniIdLog({
success: false,
type: LOG_TYPE.LOGIN
})
throw {
errCode: ERROR.GET_THIRD_PARTY_ACCOUNT_FAILED
}
}
const { type, user } = await preUnifiedLogin.call(this, {
user: {
mobile
}
})
let extraData = {
mobile_confirmed: 1
}
if (type === 'login') {
// 绑定手机号
if (!user.mobile_confirmed) {
const bindAccount = {
mobile
}
await preBind.call(this, {
uid: user._id,
bindAccount,
logType: LOG_TYPE.BIND_MOBILE
})
await postBind.call(this, {
uid: user._id,
bindAccount,
extraData: {
mobile_confirmed: 1
},
logType: LOG_TYPE.BIND_MOBILE
})
extraData = {
...extraData,
...bindAccount
}
}
}
return postUnifiedLogin.call(this, {
user,
extraData: {
...extraData
},
isThirdParty: false,
type,
inviteCode
})
}
......@@ -37,10 +37,20 @@ module.exports = async function (params = {}) {
role: 'admin'
}).limit(1).get()
if (getAdminRes.data.length > 0) {
const [admin] = getAdminRes.data
const appId = this.getClientInfo().appId
if (!admin.dcloud_appid || (admin.dcloud_appid && admin.dcloud_appid.includes(appId))) {
return {
errCode: ERROR.ADMIN_EXISTS,
errMsg: this.t('uni-id-admin-exists')
}
} else {
return {
errCode: ERROR.ADMIN_EXISTS,
errMsg: this.t('uni-id-admin-exist-in-other-apps')
}
}
}
const {
user,
......
......@@ -47,7 +47,7 @@ module.exports = async function (params = {}) {
} = getAlipayAccountResult
const bindAccount = {
apple_openid: openid
ali_openid: openid
}
await preBind.call(this, {
uid,
......
......@@ -7,8 +7,10 @@ const {
} = require('../../common/constants')
const {
decryptWeixinData,
getWeixinCache
getWeixinCache, getWeixinAccessToken
} = require('../../lib/utils/weixin')
const { initWeixin } = require('../../lib/third-party')
const { ERROR } = require('../../common/error')
/**
* 通过微信绑定手机号
......@@ -16,6 +18,7 @@ const {
* @param {Object} params
* @param {String} params.encryptedData 微信获取手机号返回的加密信息
* @param {String} params.iv 微信获取手机号返回的初始向量
* @param {String} params.code 微信获取手机号返回的code
* @returns
*/
module.exports = async function (params = {}) {
......@@ -26,16 +29,43 @@ module.exports = async function (params = {}) {
* 因此此接口不应直接使用客户端login获取的code,只能使用缓存的sessionKey
*/
const schema = {
encryptedData: 'string',
iv: 'string'
encryptedData: {
required: false,
type: 'string'
},
iv: {
required: false,
type: 'string'
},
code: {
required: false,
type: 'string'
}
}
const {
encryptedData,
iv
iv,
code
} = params
this.middleware.validate(params, schema)
if ((!encryptedData && !iv) && !code) {
return {
errCode: ERROR.INVALID_PARAM
}
}
const uid = this.authInfo.uid
let mobile
if (code) {
// 区分客户端类型 小程序还是App
const accessToken = await getWeixinAccessToken.call(this)
const weixinApi = initWeixin.call(this)
const res = await weixinApi.getPhoneNumber(accessToken, code)
mobile = res.purePhoneNumber
} else {
const sessionKey = await getWeixinCache.call(this, {
uid,
key: 'session_key'
......@@ -43,14 +73,15 @@ module.exports = async function (params = {}) {
if (!sessionKey) {
throw new Error('Session key not found')
}
const {
purePhoneNumber: mobile
} = decryptWeixinData.call(this, {
const res = decryptWeixinData.call(this, {
encryptedData,
sessionKey,
iv
})
mobile = res.purePhoneNumber
}
const bindAccount = {
mobile
}
......
......@@ -5,5 +5,9 @@ module.exports = {
bindAlipay: require('./bind-alipay'),
bindApple: require('./bind-apple'),
bindQQ: require('./bind-qq'),
bindWeixin: require('./bind-weixin')
bindWeixin: require('./bind-weixin'),
unbindWeixin: require('./unbind-weixin'),
unbindAlipay: require('./unbind-alipay'),
unbindQQ: require('./unbind-qq'),
unbindApple: require('./unbind-apple')
}
const {
preUnBind,
postUnBind
} = require('../../lib/utils/relate')
const {
LOG_TYPE, dbCmd
} = require('../../common/constants')
/**
* 解绑支付宝
* @tutorial https://uniapp.dcloud.net.cn/uniCloud/uni-id-pages.html#unbind-alipay
* @returns
*/
module.exports = async function () {
const { uid } = this.authInfo
await preUnBind.call(this, {
uid,
unBindAccount: {
ali_openid: dbCmd.exists(true)
},
logType: LOG_TYPE.UNBIND_ALIPAY
})
return await postUnBind.call(this, {
uid,
unBindAccount: {
ali_openid: dbCmd.remove()
},
logType: LOG_TYPE.UNBIND_ALIPAY
})
}
const {
preUnBind,
postUnBind
} = require('../../lib/utils/relate')
const {
LOG_TYPE, dbCmd
} = require('../../common/constants')
/**
* 解绑apple
* @tutorial https://uniapp.dcloud.net.cn/uniCloud/uni-id-pages.html#unbind-apple
* @returns
*/
module.exports = async function () {
const { uid } = this.authInfo
await preUnBind.call(this, {
uid,
unBindAccount: {
apple_openid: dbCmd.exists(true)
},
logType: LOG_TYPE.UNBIND_APPLE
})
return await postUnBind.call(this, {
uid,
unBindAccount: {
apple_openid: dbCmd.remove()
},
logType: LOG_TYPE.UNBIND_APPLE
})
}
const {
preUnBind,
postUnBind
} = require('../../lib/utils/relate')
const {
LOG_TYPE, dbCmd
} = require('../../common/constants')
const {
getQQPlatform
} = require('../../lib/utils/qq')
/**
* 解绑QQ
* @tutorial https://uniapp.dcloud.net.cn/uniCloud/uni-id-pages.html#unbind-qq
* @returns
*/
module.exports = async function () {
const { uid } = this.authInfo
const { appId } = this.getClientInfo()
const qqPlatform = getQQPlatform.call(this)
await preUnBind.call(this, {
uid,
unBindAccount: {
qq_openid: dbCmd.or([
{
[qqPlatform]: dbCmd.exists(true)
},
{
[`${qqPlatform}_${appId}`]: dbCmd.exists(true)
}
]),
qq_unionid: dbCmd.exists(true)
},
logType: LOG_TYPE.UNBIND_QQ
})
return await postUnBind.call(this, {
uid,
unBindAccount: {
qq_openid: dbCmd.remove(),
qq_unionid: dbCmd.remove()
},
logType: LOG_TYPE.UNBIND_QQ
})
}
const {
preUnBind,
postUnBind
} = require('../../lib/utils/relate')
const {
LOG_TYPE, dbCmd
} = require('../../common/constants')
const {
getWeixinPlatform
} = require('../../lib/utils/weixin')
/**
* 解绑微信
* @tutorial https://uniapp.dcloud.net.cn/uniCloud/uni-id-pages.html#unbind-weixin
* @returns
*/
module.exports = async function () {
const { uid } = this.authInfo
const weixinPlatform = getWeixinPlatform.call(this)
await preUnBind.call(this, {
uid,
unBindAccount: {
wx_openid: {
[weixinPlatform]: dbCmd.exists(true)
},
wx_unionid: dbCmd.exists(true)
},
logType: LOG_TYPE.UNBIND_WEIXIN
})
return await postUnBind.call(this, {
uid,
unBindAccount: {
wx_openid: dbCmd.remove(),
wx_unionid: dbCmd.remove()
},
logType: LOG_TYPE.UNBIND_WEIXIN
})
}
{
"name": "uni-id-co",
"version": "1.0.19",
"version": "1.0.26",
"description": "",
"main": "index.js",
"keywords": [],
......@@ -13,5 +13,7 @@
"uni-id-common": "file:../../../../uni-id-common/uniCloud/cloudfunctions/common/uni-id-common",
"uni-open-bridge-common": "file:../../../../uni-open-bridge-common/uniCloud/cloudfunctions/common/uni-open-bridge-common"
},
"extensions": {}
"extensions": {
"uni-cloud-sms": {}
}
}
{
"bsonType": "object",
"required": ["username", "password"],
"permission": {
"read": true,
"create": "'CREATE_UNI_ID_USERS' in auth.permission",
......@@ -15,28 +14,36 @@
"bsonType": "string",
"description": "支付宝平台openid",
"permission": {
"write": false,
"read": "doc._id == auth.uid"
"read": "'READ_UNI_ID_USERS' in auth.permission",
"write": "'CREATE_UNI_ID_USERS' in auth.permission || 'UPDATE_UNI_ID_USERS' in auth.permission"
}
},
"apple_openid": {
"bsonType": "string",
"description": "苹果登录openid",
"permission": {
"write": false,
"read": "doc._id == auth.uid"
"read": "'READ_UNI_ID_USERS' in auth.permission",
"write": "'CREATE_UNI_ID_USERS' in auth.permission || 'UPDATE_UNI_ID_USERS' in auth.permission"
}
},
"avatar": {
"bsonType": "string",
"description": "头像地址",
"title": "头像地址",
"trim": "both"
"trim": "both",
"permission": {
"read": "doc._id == auth.uid || 'READ_UNI_ID_USERS' in auth.permission",
"write": "doc._id == auth.uid || 'CREATE_UNI_ID_USERS' in auth.permission || 'UPDATE_UNI_ID_USERS' in auth.permission"
}
},
"avatar_file": {
"bsonType": "file",
"description": "用file类型方便使用uni-file-picker组件",
"title": "头像文件"
"title": "头像文件",
"permission": {
"read": "doc._id == auth.uid || 'READ_UNI_ID_USERS' in auth.permission",
"write": "doc._id == auth.uid || 'CREATE_UNI_ID_USERS' in auth.permission || 'UPDATE_UNI_ID_USERS' in auth.permission"
}
},
"comment": {
"bsonType": "string",
......@@ -44,8 +51,8 @@
"title": "备注",
"trim": "both",
"permission": {
"write": false,
"read": false
"read": "'READ_UNI_ID_USERS' in auth.permission",
"write": "'CREATE_UNI_ID_USERS' in auth.permission || 'UPDATE_UNI_ID_USERS' in auth.permission"
}
},
"dcloud_appid": {
......@@ -53,8 +60,8 @@
"description": "允许登录的客户端的appid列表",
"foreignKey": "opendb-app-list.appid",
"permission": {
"write": false,
"read": "doc._id == auth.uid"
"read": "'READ_UNI_ID_USERS' in auth.permission",
"write": "'CREATE_UNI_ID_USERS' in auth.permission || 'UPDATE_UNI_ID_USERS' in auth.permission"
}
},
"department_id": {
......@@ -68,8 +75,8 @@
"enumType": "tree",
"title": "部门",
"permission": {
"write": false,
"read": "doc._id == auth.uid"
"read": "doc._id == auth.uid || 'READ_UNI_ID_USERS' in auth.permission",
"write": "'CREATE_UNI_ID_USERS' in auth.permission || 'UPDATE_UNI_ID_USERS' in auth.permission"
}
},
"email": {
......@@ -79,8 +86,8 @@
"title": "邮箱",
"trim": "both",
"permission": {
"write": false,
"read": "doc._id == auth.uid"
"read": "doc._id == auth.uid || 'READ_UNI_ID_USERS' in auth.permission",
"write": "'CREATE_UNI_ID_USERS' in auth.permission || 'UPDATE_UNI_ID_USERS' in auth.permission"
}
},
"email_confirmed": {
......@@ -98,8 +105,8 @@
],
"title": "邮箱验证状态",
"permission": {
"write": false,
"read": "doc._id == auth.uid"
"read": "doc._id == auth.uid || 'READ_UNI_ID_USERS' in auth.permission",
"write": "'CREATE_UNI_ID_USERS' in auth.permission || 'UPDATE_UNI_ID_USERS' in auth.permission"
}
},
"gender": {
......@@ -121,16 +128,16 @@
],
"title": "性别",
"permission": {
"write": false,
"read": "doc._id == auth.uid"
"read": "doc._id == auth.uid || 'READ_UNI_ID_USERS' in auth.permission",
"write": "'CREATE_UNI_ID_USERS' in auth.permission || 'UPDATE_UNI_ID_USERS' in auth.permission"
}
},
"invite_time": {
"bsonType": "timestamp",
"description": "受邀时间",
"permission": {
"write": false,
"read": "doc._id == auth.uid"
"read": "doc._id == auth.uid || 'READ_UNI_ID_USERS' in auth.permission",
"write": "'CREATE_UNI_ID_USERS' in auth.permission || 'UPDATE_UNI_ID_USERS' in auth.permission"
}
},
"inviter_uid": {
......@@ -138,24 +145,24 @@
"description": "用户全部上级邀请者",
"trim": "both",
"permission": {
"write": false,
"read": "doc._id == auth.uid"
"read": "doc._id == auth.uid || 'READ_UNI_ID_USERS' in auth.permission",
"write": "'CREATE_UNI_ID_USERS' in auth.permission || 'UPDATE_UNI_ID_USERS' in auth.permission"
}
},
"last_login_date": {
"bsonType": "timestamp",
"description": "最后登录时间",
"permission": {
"write": false,
"read": "doc._id == auth.uid"
"read": "doc._id == auth.uid || 'READ_UNI_ID_USERS' in auth.permission",
"write": "'CREATE_UNI_ID_USERS' in auth.permission || 'UPDATE_UNI_ID_USERS' in auth.permission"
}
},
"last_login_ip": {
"bsonType": "string",
"description": "最后登录时 IP 地址",
"permission": {
"write": false,
"read": "doc._id == auth.uid"
"read": "doc._id == auth.uid || 'READ_UNI_ID_USERS' in auth.permission",
"write": "'CREATE_UNI_ID_USERS' in auth.permission || 'UPDATE_UNI_ID_USERS' in auth.permission"
}
},
"mobile": {
......@@ -165,8 +172,8 @@
"title": "手机号码",
"trim": "both",
"permission": {
"write": false,
"read": "doc._id == auth.uid"
"read": "doc._id == auth.uid || 'READ_UNI_ID_USERS' in auth.permission",
"write": "'CREATE_UNI_ID_USERS' in auth.permission || 'UPDATE_UNI_ID_USERS' in auth.permission"
}
},
"mobile_confirmed": {
......@@ -184,49 +191,49 @@
],
"title": "手机号验证状态",
"permission": {
"write": false,
"read": "doc._id == auth.uid"
"read": "doc._id == auth.uid || 'READ_UNI_ID_USERS' in auth.permission",
"write": "'CREATE_UNI_ID_USERS' in auth.permission || 'UPDATE_UNI_ID_USERS' in auth.permission"
}
},
"my_invite_code": {
"bsonType": "string",
"description": "用户自身邀请码",
"permission": {
"write": false,
"read": "doc._id == auth.uid"
"read": "doc._id == auth.uid || 'READ_UNI_ID_USERS' in auth.permission",
"write": "'CREATE_UNI_ID_USERS' in auth.permission || 'UPDATE_UNI_ID_USERS' in auth.permission"
}
},
"nickname": {
"bsonType": "string",
"description": "用户昵称",
"title": "昵称",
"trim": "both"
"trim": "both",
"permission": {
"read": "doc._id == auth.uid || 'READ_UNI_ID_USERS' in auth.permission",
"write": "doc._id == auth.uid || 'CREATE_UNI_ID_USERS' in auth.permission || 'UPDATE_UNI_ID_USERS' in auth.permission"
}
},
"password": {
"bsonType": "password",
"description": "密码,加密存储",
"title": "密码",
"trim": "both",
"permission": {
"write": false,
"read": false
}
"trim": "both"
},
"password_secret_version": {
"bsonType": "int",
"description": "密码使用的passwordSecret版本",
"title": "passwordSecret",
"permission": {
"write": false,
"read": false
"read": false,
"write": false
}
},
"realname_auth": {
"bsonType": "object",
"description": "实名认证信息",
"permission": {
"write": false,
"read": "doc._id == auth.uid"
"read": "doc._id == auth.uid || 'READ_UNI_ID_USERS' in auth.permission",
"write": "'CREATE_UNI_ID_USERS' in auth.permission || 'UPDATE_UNI_ID_USERS' in auth.permission"
},
"properties": {
"auth_date": {
......@@ -291,16 +298,22 @@
"bsonType": "timestamp",
"description": "注册时间",
"forceDefaultValue": {
"$env": "now",
"read": "doc._id == auth.uid"
"$env": "now"
},
"permission": {
"read": "doc._id == auth.uid || 'READ_UNI_ID_USERS' in auth.permission",
"write": "'CREATE_UNI_ID_USERS' in auth.permission || 'UPDATE_UNI_ID_USERS' in auth.permission"
}
},
"register_ip": {
"bsonType": "string",
"description": "注册时 IP 地址",
"forceDefaultValue": {
"$env": "clientIP",
"read": "doc._id == auth.uid"
"$env": "clientIP"
},
"permission": {
"read": "doc._id == auth.uid || 'READ_UNI_ID_USERS' in auth.permission",
"write": "'CREATE_UNI_ID_USERS' in auth.permission || 'UPDATE_UNI_ID_USERS' in auth.permission"
}
},
"role": {
......@@ -312,8 +325,8 @@
},
"foreignKey": "uni-id-roles.role_id",
"permission": {
"write": false,
"read": "doc._id == auth.uid"
"read": "doc._id == auth.uid || 'READ_UNI_ID_USERS' in auth.permission",
"write": "'CREATE_UNI_ID_USERS' in auth.permission || 'UPDATE_UNI_ID_USERS' in auth.permission"
},
"title": "角色"
},
......@@ -321,8 +334,8 @@
"bsonType": "int",
"description": "用户积分,积分变更记录可参考:uni-id-scores表定义",
"permission": {
"write": false,
"read": "doc._id == auth.uid"
"read": "doc._id == auth.uid || 'READ_UNI_ID_USERS' in auth.permission",
"write": "'CREATE_UNI_ID_USERS' in auth.permission || 'UPDATE_UNI_ID_USERS' in auth.permission"
}
},
"status": {
......@@ -330,8 +343,8 @@
"defaultValue": 0,
"description": "用户状态:0 正常 1 禁用 2 审核中 3 审核拒绝",
"permission": {
"write": false,
"read": "doc._id == auth.uid"
"read": "doc._id == auth.uid || 'READ_UNI_ID_USERS' in auth.permission",
"write": "'CREATE_UNI_ID_USERS' in auth.permission || 'UPDATE_UNI_ID_USERS' in auth.permission"
},
"enum": [{
"text": "正常",
......@@ -356,7 +369,8 @@
"bsonType": "array",
"description": "用户token",
"permission": {
"read": "doc._id == auth.uid"
"read": "'READ_UNI_ID_USERS' in auth.permission",
"write": "'CREATE_UNI_ID_USERS' in auth.permission || 'UPDATE_UNI_ID_USERS' in auth.permission"
}
},
"username": {
......@@ -365,7 +379,8 @@
"title": "用户名",
"trim": "both",
"permission": {
"write": false
"read": "doc._id == auth.uid || 'READ_UNI_ID_USERS' in auth.permission",
"write": "'CREATE_UNI_ID_USERS' in auth.permission || 'UPDATE_UNI_ID_USERS' in auth.permission"
}
},
"wx_openid": {
......@@ -390,16 +405,16 @@
}
},
"permission": {
"write": false,
"read": "doc._id == auth.uid"
"read": "'READ_UNI_ID_USERS' in auth.permission",
"write": "'CREATE_UNI_ID_USERS' in auth.permission || 'UPDATE_UNI_ID_USERS' in auth.permission"
}
},
"wx_unionid": {
"bsonType": "string",
"description": "微信unionid",
"permission": {
"write": false,
"read": "doc._id == auth.uid"
"read": "'READ_UNI_ID_USERS' in auth.permission",
"write": "'CREATE_UNI_ID_USERS' in auth.permission || 'UPDATE_UNI_ID_USERS' in auth.permission"
}
},
"qq_openid": {
......@@ -416,17 +431,26 @@
}
},
"permission": {
"write": false,
"read": "doc._id == auth.uid"
"read": "'READ_UNI_ID_USERS' in auth.permission",
"write": "'CREATE_UNI_ID_USERS' in auth.permission || 'UPDATE_UNI_ID_USERS' in auth.permission"
}
},
"qq_unionid": {
"bsonType": "string",
"description": "QQ unionid",
"permission": {
"write": false,
"read": "doc._id == auth.uid"
"read": "'READ_UNI_ID_USERS' in auth.permission",
"write": "'CREATE_UNI_ID_USERS' in auth.permission || 'UPDATE_UNI_ID_USERS' in auth.permission"
}
},
"third_party": {
"bsonType": "object",
"description": "三方平台凭证",
"permission": {
"read": false,
"write": false
}
}
},
"required": []
}
\ No newline at end of file
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册