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

- 更新依赖的的版本为1.0.26

上级 ee031fe9
...@@ -5,6 +5,7 @@ ...@@ -5,6 +5,7 @@
openApp() //创建在h5端全局悬浮引导用户下载app的功能 openApp() //创建在h5端全局悬浮引导用户下载app的功能
// #endif // #endif
import checkIsAgree from '@/pages/uni-agree/utils/uni-agree.js'; import checkIsAgree from '@/pages/uni-agree/utils/uni-agree.js';
import uniIdPageInit from '@/uni_modules/uni-id-pages/init.js';
export default { export default {
globalData: { globalData: {
searchText: '', searchText: '',
...@@ -18,8 +19,10 @@ ...@@ -18,8 +19,10 @@
this.globalData.$i18n = this.$i18n this.globalData.$i18n = this.$i18n
this.globalData.$t = str => this.$t(str) this.globalData.$t = str => this.$t(str)
initApp(); console.log('uni.getPushClientId',uni.getPushClientId);
initApp();
uniIdPageInit()
// #ifdef APP-PLUS // #ifdef APP-PLUS
//checkIsAgree(); APP端暂时先用原生默认生成的。目前,自定义方式启动vue界面时,原生层已经请求了部分权限这并不符合国家的法规 //checkIsAgree(); APP端暂时先用原生默认生成的。目前,自定义方式启动vue界面时,原生层已经请求了部分权限这并不符合国家的法规
......
## 2.0.5(2022-10-19)
- 更新依赖的`uni-id-pages`的版本为1.0.26
## 2.0.4(2022-09-21) ## 2.0.4(2022-09-21)
- 新增 使用uni-id-pages的账号信息的状态管理功能 - 新增 使用uni-id-pages的账号信息的状态管理功能
## 2.0.3(2022-09-20) ## 2.0.3(2022-09-20)
......
...@@ -47,11 +47,11 @@ export default async function() { ...@@ -47,11 +47,11 @@ export default async function() {
methodName, // 云对象的方法名称 methodName, // 云对象的方法名称
params // 参数列表 params // 参数列表
}) { }) {
console.log('interceptObject',{ // console.log('interceptObject',{
objectName, // 云对象名称 // objectName, // 云对象名称
methodName, // 云对象的方法名称 // methodName, // 云对象的方法名称
params // 参数列表 // params // 参数列表
}); // });
if(objectName == "uni-id-co" && (methodName.includes('loginBy') || ['login','registerUser'].includes(methodName) )){ if(objectName == "uni-id-co" && (methodName.includes('loginBy') || ['login','registerUser'].includes(methodName) )){
console.log('执行登录相关云对象'); console.log('执行登录相关云对象');
params[0].inviteCode = await new Promise((callBack) => { params[0].inviteCode = await new Promise((callBack) => {
...@@ -84,7 +84,7 @@ export default async function() { ...@@ -84,7 +84,7 @@ export default async function() {
}) })
// console.log(params); // console.log(params);
} }
console.log(params); // console.log(params);
}, },
success(e) { success(e) {
console.log(e); console.log(e);
...@@ -94,17 +94,17 @@ export default async function() { ...@@ -94,17 +94,17 @@ export default async function() {
}, },
fail(e){ fail(e){
console.error(e); console.error(e);
if (debug) { // if (debug) {
uni.showModal({ // uni.showModal({
content: JSON.stringify(e), // content: JSON.stringify(e),
showCancel: false // showCancel: false
}); // });
}else{ // }else{
uni.showToast({ // uni.showToast({
title: '系统错误请稍后再试', // title: '系统错误请稍后再试',
icon:'error' // icon:'error'
}); // });
} // }
} }
}) })
......
...@@ -40,6 +40,9 @@ ...@@ -40,6 +40,9 @@
"ios": { "ios": {
}, },
"sdkConfigs": { "sdkConfigs": {
"push": {
"unipush": null
}
} }
} }
}, },
......
//这是应用的配置页面,App.vue挂载到getApp().globalData.config //这是应用的配置页面,App.vue挂载到getApp().globalData.config
export default { export default {
//是否打开调试模式
"debug":false,
"h5": { "h5": {
"url": "https://uni-starter.dcloud.net.cn", // 前端网页托管的域名 "url": "https://uni-starter.dcloud.net.cn", // 前端网页托管的域名
// 在h5端全局悬浮引导用户下载app的功能 更多自定义要求在/common/openApp.js中修改 // 在h5端全局悬浮引导用户下载app的功能 更多自定义要求在/common/openApp.js中修改
...@@ -17,7 +15,7 @@ export default { ...@@ -17,7 +15,7 @@ export default {
"mp": { "mp": {
"weixin": { "weixin": {
//微信小程序原始id,微信小程序分享时 //微信小程序原始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) ## 1.1.1(2022-09-19)
- 修复,输入后回车,change 事件触发两次,[详情](https://ask.dcloud.net.cn/question/152149) - 修复,输入后回车,change 事件触发两次,[详情](https://ask.dcloud.net.cn/question/152149)
## 1.1.0(2022-06-30) ## 1.1.0(2022-06-30)
......
...@@ -18,7 +18,7 @@ ...@@ -18,7 +18,7 @@
<!-- 开启密码时显示小眼睛 --> <!-- 开启密码时显示小眼睛 -->
<uni-icons v-if="isVal" class="content-clear-icon" :class="{'is-textarea-icon':type==='textarea'}" <uni-icons v-if="isVal" class="content-clear-icon" :class="{'is-textarea-icon':type==='textarea'}"
:type="showPassword?'eye-slash-filled':'eye-filled'" :size="22" :type="showPassword?'eye-slash-filled':'eye-filled'" :size="22"
:color="focusShow?'#2979ff':'#c0c4cc'" @click="onEyes"> :color="focusShow ? primaryColor :'#c0c4cc'" @click="onEyes">
</uni-icons> </uni-icons>
</template> </template>
<template v-else-if="suffixIcon"> <template v-else-if="suffixIcon">
...@@ -28,7 +28,7 @@ ...@@ -28,7 +28,7 @@
<template v-else> <template v-else>
<uni-icons v-if="clearable && isVal && !disabled && type !== 'textarea'" class="content-clear-icon" <uni-icons v-if="clearable && isVal && !disabled && type !== 'textarea'" class="content-clear-icon"
:class="{'is-textarea-icon':type==='textarea'}" type="clear" :size="clearSize" :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> </template>
<slot name="right"></slot> <slot name="right"></slot>
</view> </view>
...@@ -59,6 +59,7 @@ ...@@ -59,6 +59,7 @@
* @property {Number } clearSize 清除图标的大小,单位px(默认15) * @property {Number } clearSize 清除图标的大小,单位px(默认15)
* @property {String} prefixIcon 输入框头部图标 * @property {String} prefixIcon 输入框头部图标
* @property {String} suffixIcon 输入框尾部图标 * @property {String} suffixIcon 输入框尾部图标
* @property {String} primaryColor 设置主题色(默认#2979ff)
* @property {Boolean} trim 是否自动去除两端的空格 * @property {Boolean} trim 是否自动去除两端的空格
* @value both 去除两端空格 * @value both 去除两端空格
* @value left 去除左侧空格 * @value left 去除左侧空格
...@@ -177,6 +178,10 @@ ...@@ -177,6 +178,10 @@
type: Boolean, type: Boolean,
default: true default: true
}, },
primaryColor: {
type: String,
default: '#2979ff'
},
styles: { styles: {
type: Object, type: Object,
default () { default () {
...@@ -244,7 +249,7 @@ ...@@ -244,7 +249,7 @@
}) })
}, },
inputContentStyle() { 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 const borderColor = this.inputBorder && this.msg ? '#dd524d' : focusColor
return obj2strStyle({ return obj2strStyle({
'border-color': borderColor || '#e5e5e5', 'border-color': borderColor || '#e5e5e5',
......
{ {
"id": "uni-easyinput", "id": "uni-easyinput",
"displayName": "uni-easyinput 增强输入框", "displayName": "uni-easyinput 增强输入框",
"version": "1.1.1", "version": "1.1.3",
"description": "Easyinput 组件是对原生input组件的增强", "description": "Easyinput 组件是对原生input组件的增强",
"keywords": [ "keywords": [
"uni-ui", "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) ## 1.0.21(2022-09-21)
- 修复 store.hasLogin的值在某些情况下会出错的bug - 修复 store.hasLogin的值在某些情况下会出错的bug
## 1.0.20(2022-09-21) ## 1.0.20(2022-09-21)
......
...@@ -66,7 +66,7 @@ function getPwdRules(pwdName = 'password', rePwdName = 'password2') { ...@@ -66,7 +66,7 @@ function getPwdRules(pwdName = 'password', rePwdName = 'password2') {
}, },
{ {
validateFunction: function(rule, value, data, callback) { validateFunction: function(rule, value, data, callback) {
if (value != data.password) { if (value != data[pwdName]) {
callback(ERROR.normal.rePwdErr) callback(ERROR.normal.rePwdErr)
} }
return true return true
......
...@@ -37,7 +37,7 @@ export const mutations = { ...@@ -37,7 +37,7 @@ export const mutations = {
} else { } else {
try { try {
let res = await usersTable.where("'_id' == $cloudEnv_uid") let res = await usersTable.where("'_id' == $cloudEnv_uid")
.field('mobile,nickname,user_name,email,avatar_file') .field('mobile,nickname,username,email,avatar_file')
.get() .get()
console.log('fromDbData',res.result.data); console.log('fromDbData',res.result.data);
this.setUserInfo(res.result.data[0]) this.setUserInfo(res.result.data[0])
...@@ -69,7 +69,7 @@ export const mutations = { ...@@ -69,7 +69,7 @@ export const mutations = {
uni.$emit('uni-id-pages-logout') uni.$emit('uni-id-pages-logout')
this.setUserInfo({},{cover:true}) this.setUserInfo({},{cover:true})
}, },
loginSuccess(e){ loginSuccess(e = {}){
const { const {
showToast = true, toastText = '登录成功', autoBack = true, uniIdRedirectUrl = '' showToast = true, toastText = '登录成功', autoBack = true, uniIdRedirectUrl = ''
} = e } = e
...@@ -94,7 +94,7 @@ export const mutations = { ...@@ -94,7 +94,7 @@ export const mutations = {
delta++ delta++
} }
}) })
console.log('判断需要返回几层:', pages, delta); // console.log('判断需要返回几层:', delta);
if (uniIdRedirectUrl) { if (uniIdRedirectUrl) {
return uni.reLaunch({ return uni.reLaunch({
url: uniIdRedirectUrl url: uniIdRedirectUrl
......
...@@ -234,7 +234,7 @@ ...@@ -234,7 +234,7 @@
console.log('出乎意料的情况,path:' + path); console.log('出乎意料的情况,path:' + path);
} }
}, },
async login_before(type, navigateBack = true) { async login_before(type, navigateBack = true, options = {}) {
console.log(type); console.log(type);
//提示空实现 //提示空实现
if (["qq", if (["qq",
...@@ -300,7 +300,7 @@ ...@@ -300,7 +300,7 @@
let agreementsRef = this.getParentComponent().$refs.agreements let agreementsRef = this.getParentComponent().$refs.agreements
return agreementsRef.popup(() => { return agreementsRef.popup(() => {
console.log(type, navigateBack); console.log(type, navigateBack);
this.login_before(type, navigateBack) this.login_before(type, navigateBack, options)
}) })
} }
...@@ -331,7 +331,6 @@ ...@@ -331,7 +331,6 @@
} }
// #endif // #endif
uni.showLoading({ uni.showLoading({
mask: true mask: true
}) })
...@@ -397,6 +396,13 @@ ...@@ -397,6 +396,13 @@
} }
}) })
} }
if (type === 'weixinMobile') {
return this.login({
phoneCode: options.phoneNumberCode
}, type)
}
uni.login({ uni.login({
"provider": type, "provider": type,
"onlyAuthorize": true, "onlyAuthorize": true,
...@@ -429,7 +435,7 @@ ...@@ -429,7 +435,7 @@
type type
}); });
//toLowerCase //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",{ const uniIdCo = uniCloud.importObject("uni-id-co",{
customUI:true customUI:true
}) })
...@@ -441,7 +447,7 @@ ...@@ -441,7 +447,7 @@
}); });
// #ifdef MP-WEIXIN // #ifdef MP-WEIXIN
//如果是微信小程序端的微信登录,且为首次登录,就弹出获取微信昵称+头像用于绑定资料 //如果是微信小程序端的微信登录,且为首次登录,就弹出获取微信昵称+头像用于绑定资料
if (type == 'weixin' && result.type == "register") { if (['weixin', 'weixinMobile'].includes(type) && result.type == "register") {
mutations.loginSuccess({ mutations.loginSuccess({
...result, ...result,
showToast: false, showToast: false,
......
...@@ -56,6 +56,7 @@ export default async function() { ...@@ -56,6 +56,7 @@ export default async function() {
} }
// #endif // #endif
/* 注释此代码块原因:与uni-starter中的appinit逻辑一致
//3. 绑定clientDB错误事件 //3. 绑定clientDB错误事件
// clientDB对象 // clientDB对象
const db = uniCloud.database() const db = uniCloud.database()
...@@ -72,9 +73,9 @@ export default async function() { ...@@ -72,9 +73,9 @@ export default async function() {
} }
// 解绑clientDB错误事件 // 解绑clientDB错误事件
//db.off('error', onDBError) //db.off('error', onDBError)
*/
//4. 同步客户端push_clientid至uni-id-device表
//4. 同步客户端push_clientid至device表
if (uniCloud.onRefreshToken) { if (uniCloud.onRefreshToken) {
uniCloud.onRefreshToken(() => { uniCloud.onRefreshToken(() => {
console.log('onRefreshToken'); console.log('onRefreshToken');
...@@ -90,7 +91,11 @@ export default async function() { ...@@ -90,7 +91,11 @@ export default async function() {
console.log('getPushClientId', res); console.log('getPushClientId', res);
}, },
fail(e) { 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", "id": "uni-id-pages",
"displayName": "uni-id-pages", "displayName": "uni-id-pages",
"version": "1.0.21", "version": "1.0.26",
"description": "云端一体简单、统一、可扩展的用户中心页面模版", "description": "云端一体简单、统一、可扩展的用户中心页面模版",
"keywords": [ "keywords": [
"用户管理", "用户管理",
......
...@@ -7,10 +7,11 @@ ...@@ -7,10 +7,11 @@
<!-- 顶部文字 --> <!-- 顶部文字 -->
<text class="title">请选择登录方式</text> <text class="title">请选择登录方式</text>
<!-- 快捷登录框 当url带参数时有效 --> <!-- 快捷登录框 当url带参数时有效 -->
<template v-if="['apple','weixin'].includes(type)"> <template v-if="['apple','weixin', 'weixinMobile'].includes(type)">
<text class="tip">将根据第三方账号服务平台的授权范围获取你的信息</text> <text class="tip">将根据第三方账号服务平台的授权范围获取你的信息</text>
<view class="quickLogin"> <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> <uni-id-pages-agreements scope="register" ref="agreements"></uni-id-pages-agreements>
</view> </view>
</template> </template>
...@@ -98,8 +99,16 @@ ...@@ -98,8 +99,16 @@
//#endif //#endif
}, },
methods: { methods: {
quickLogin() { quickLogin(e) {
this.$refs.uniFabLogin.login_before(this.type) 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() { toSmsPage() {
console.log('toSmsPage',this.agree); console.log('toSmsPage',this.agree);
......
...@@ -53,9 +53,6 @@ ...@@ -53,9 +53,6 @@
mutations mutations
} from '@/uni_modules/uni-id-pages/common/store.js' } from '@/uni_modules/uni-id-pages/common/store.js'
const {
loginSuccess
} = mutations
const uniIdCo = uniCloud.importObject("uni-id-co") const uniIdCo = uniCloud.importObject("uni-id-co")
export default { export default {
mixins: [mixin], mixins: [mixin],
...@@ -118,7 +115,7 @@ ...@@ -118,7 +115,7 @@
submitForm(params) { submitForm(params) {
uniIdCo.registerUser(this.formData).then(e => { uniIdCo.registerUser(this.formData).then(e => {
console.log(e); console.log(e);
loginSuccess() this.loginSuccess(e)
}) })
.catch(e => { .catch(e => {
console.log(e); console.log(e);
......
...@@ -30,11 +30,11 @@ ...@@ -30,11 +30,11 @@
</view> </view>
<view v-if="isShowPhotoBtn" @tap="uploadImage"> <view v-if="isShowPhotoBtn" @tap="uploadImage">
<slot name="photo" v-if="$slots.photo" /> <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>
<view v-if="isShowRotateBtn" @tap="rotate"> <view v-if="isShowRotateBtn" @tap="rotate">
<slot name="rotate" v-if="$slots.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>
<view v-if="isShowConfirmBtn" @tap="confirm"> <view v-if="isShowConfirmBtn" @tap="confirm">
<slot name="confirm" v-if="$slots.confirm" /> <slot name="confirm" v-if="$slots.confirm" />
......
...@@ -160,6 +160,41 @@ ...@@ -160,6 +160,41 @@
uni.navigateTo({ uni.navigateTo({
url:"/uni_modules/uni-id-pages/pages/userinfo/deactivate/deactivate" 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 = { ...@@ -52,7 +52,11 @@ const LOG_TYPE = {
BIND_WEIXIN: 'bind-weixin', BIND_WEIXIN: 'bind-weixin',
BIND_QQ: 'bind-qq', BIND_QQ: 'bind-qq',
BIND_APPLE: 'bind-apple', 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 = { const SMS_SCENE = {
......
...@@ -30,7 +30,12 @@ const ERROR = { ...@@ -30,7 +30,12 @@ const ERROR = {
SET_INVITE_CODE_FAILED: 'uni-id-set-invite-code-failed', SET_INVITE_CODE_FAILED: 'uni-id-set-invite-code-failed',
INVALID_INVITE_CODE: 'uni-id-invalid-invite-code', INVALID_INVITE_CODE: 'uni-id-invalid-invite-code',
CHANGE_INVITER_FORBIDDEN: 'uni-id-change-inviter-forbidden', 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) { function isUniIdError (errCode) {
......
...@@ -171,6 +171,13 @@ function getNonceStr (length = 16) { ...@@ -171,6 +171,13 @@ function getNonceStr (length = 16) {
return str.substring(0, length) 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 = { module.exports = {
getType, getType,
isValidString, isValidString,
......
...@@ -62,5 +62,17 @@ module.exports = { ...@@ -62,5 +62,17 @@ module.exports = {
}, },
getAccountInfo: { getAccountInfo: {
auth: true auth: true
},
unbindWeixin: {
auth: true
},
unbindAlipay: {
auth: true
},
unbindQQ: {
auth: true
},
unbindApple: {
auth: true
} }
} }
...@@ -29,7 +29,8 @@ const { ...@@ -29,7 +29,8 @@ const {
loginByWeixin, loginByWeixin,
loginByAlipay, loginByAlipay,
loginByQQ, loginByQQ,
loginByApple loginByApple,
loginByWeixinMobile
} = require('./module/login/index') } = require('./module/login/index')
const { const {
logout logout
...@@ -41,7 +42,11 @@ const { ...@@ -41,7 +42,11 @@ const {
bindAlipay, bindAlipay,
bindApple, bindApple,
bindQQ, bindQQ,
bindWeixin bindWeixin,
unbindWeixin,
unbindAlipay,
unbindQQ,
unbindApple
} = require('./module/relate/index') } = require('./module/relate/index')
const { const {
updatePwd, updatePwd,
...@@ -74,7 +79,7 @@ const { ...@@ -74,7 +79,7 @@ const {
} = require('./module/dev/index') } = require('./module/dev/index')
module.exports = { module.exports = {
async _before() { async _before () {
const clientInfo = this.getClientInfo() const clientInfo = this.getClientInfo()
/** /**
* 检查clientInfo,无appId和uniPlatform时本云对象无法正常运行 * 检查clientInfo,无appId和uniPlatform时本云对象无法正常运行
...@@ -157,7 +162,7 @@ module.exports = { ...@@ -157,7 +162,7 @@ module.exports = {
// 挂载uni-captcha到this上,方便后续调用 // 挂载uni-captcha到this上,方便后续调用
this.uniCaptcha = uniCaptcha this.uniCaptcha = uniCaptcha
Object.defineProperty(this, 'uniOpenBridge', { Object.defineProperty(this, 'uniOpenBridge', {
get() { get () {
return require('uni-open-bridge-common') return require('uni-open-bridge-common')
} }
}) })
...@@ -181,7 +186,7 @@ module.exports = { ...@@ -181,7 +186,7 @@ module.exports = {
// 通用权限校验模块 // 通用权限校验模块
await this.middleware.accessControl() await this.middleware.accessControl()
}, },
_after(error, result) { _after (error, result) {
if (error) { if (error) {
// 处理中间件内抛出的标准响应对象 // 处理中间件内抛出的标准响应对象
if (error.errCode && getType(error) === 'object') { if (error.errCode && getType(error) === 'object') {
...@@ -217,6 +222,10 @@ module.exports = { ...@@ -217,6 +222,10 @@ module.exports = {
* @param {String} params.nickname 昵称 * @param {String} params.nickname 昵称
* @param {Array} params.authorizedApp 允许登录的AppID列表 * @param {Array} params.authorizedApp 允许登录的AppID列表
* @param {Array} params.role 用户角色列表 * @param {Array} params.role 用户角色列表
* @param {String} params.mobile 手机号
* @param {String} params.email 邮箱
* @param {Array} params.tags 用户标签
* @param {Number} params.status 用户状态
* @returns * @returns
*/ */
addUser, addUser,
...@@ -359,6 +368,7 @@ module.exports = { ...@@ -359,6 +368,7 @@ module.exports = {
* @returns * @returns
*/ */
loginByApple, loginByApple,
loginByWeixinMobile,
/** /**
* 用户退出登录 * 用户退出登录
* @tutorial https://uniapp.dcloud.net.cn/uniCloud/uni-id-pages.html#logout * @tutorial https://uniapp.dcloud.net.cn/uniCloud/uni-id-pages.html#logout
...@@ -541,5 +551,30 @@ module.exports = { ...@@ -541,5 +551,30 @@ module.exports = {
* @tutorial https://uniapp.dcloud.net.cn/uniCloud/uni-id-pages.html#get-supported-login-type * @tutorial https://uniapp.dcloud.net.cn/uniCloud/uni-id-pages.html#get-supported-login-type
* @returns * @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 = { ...@@ -12,7 +12,7 @@ const sentence = {
'uni-id-account-audit-failed': 'Account audit failed', 'uni-id-account-audit-failed': 'Account audit failed',
'uni-id-account-closed': 'Account has been closed', 'uni-id-account-closed': 'Account has been closed',
'uni-id-captcha-required': 'Captcha required', '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-password-error-exceed-limit': 'The number of password errors is excessive',
'uni-id-invalid-username': 'Invalid username', 'uni-id-invalid-username': 'Invalid username',
'uni-id-invalid-password': 'invalid password', 'uni-id-invalid-password': 'invalid password',
...@@ -35,7 +35,12 @@ const sentence = { ...@@ -35,7 +35,12 @@ const sentence = {
'uni-id-set-invite-code-failed': 'Set invite code failed', 'uni-id-set-invite-code-failed': 'Set invite code failed',
'uni-id-invalid-invite-code': 'Invalid invite code', 'uni-id-invalid-invite-code': 'Invalid invite code',
'uni-id-change-inviter-forbidden': 'Change inviter is not allowed', '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 = { module.exports = {
......
...@@ -12,7 +12,7 @@ const sentence = { ...@@ -12,7 +12,7 @@ const sentence = {
'uni-id-account-audit-failed': '此账号审核失败', 'uni-id-account-audit-failed': '此账号审核失败',
'uni-id-account-closed': '此账号已注销', 'uni-id-account-closed': '此账号已注销',
'uni-id-captcha-required': '请输入图形验证码', 'uni-id-captcha-required': '请输入图形验证码',
'uni-id-password-error': '用户名或密码错误', 'uni-id-password-error': '密码错误',
'uni-id-password-error-exceed-limit': '密码错误次数过多,请稍后再试', 'uni-id-password-error-exceed-limit': '密码错误次数过多,请稍后再试',
'uni-id-invalid-username': '用户名不合法', 'uni-id-invalid-username': '用户名不合法',
'uni-id-invalid-password': '密码不合法', 'uni-id-invalid-password': '密码不合法',
...@@ -35,7 +35,12 @@ const sentence = { ...@@ -35,7 +35,12 @@ const sentence = {
'uni-id-set-invite-code-failed': '设置邀请码失败', 'uni-id-set-invite-code-failed': '设置邀请码失败',
'uni-id-invalid-invite-code': '邀请码不可用', 'uni-id-invalid-invite-code': '邀请码不可用',
'uni-id-change-inviter-forbidden': '禁止修改邀请人', '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 = { module.exports = {
......
...@@ -86,4 +86,26 @@ module.exports = class Auth { ...@@ -86,4 +86,26 @@ module.exports = class Auth {
avatar 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 = {}) { ...@@ -219,7 +219,8 @@ async function postLogin (params = {}) {
user user
}) })
: {} : {}
) ),
passwordConfirmed: !!user.password
} }
} }
......
...@@ -5,8 +5,15 @@ const { ...@@ -5,8 +5,15 @@ const {
ERROR ERROR
} = require('../../common/error') } = require('../../common/error')
const { const {
userCollection userCollection, dbCmd, USER_IDENTIFIER
} = require('../../common/constants') } = require('../../common/constants')
const {
getUserIdentifier
} = require('../../lib/utils/account')
const {
batchFindObjctValue
} = require('../../common/utils')
const merge = require('lodash.merge') const merge = require('lodash.merge')
/** /**
...@@ -56,7 +63,100 @@ async function postBind ({ ...@@ -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 = { module.exports = {
preBind, preBind,
postBind postBind,
preUnBind,
postUnBind
} }
...@@ -45,7 +45,7 @@ async function sendSmsCode ({ ...@@ -45,7 +45,7 @@ async function sendSmsCode ({
action = this.t('verify-mobile') action = this.t('verify-mobile')
break break
} }
const sceneConfig = smsConfig.scene || {} const sceneConfig = (smsConfig.scene || {})[scene] || {}
if (!templateId) { if (!templateId) {
templateId = sceneConfig.templateId templateId = sceneConfig.templateId
} }
......
...@@ -177,10 +177,22 @@ async function getWeixinCache ({ ...@@ -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 = { module.exports = {
decryptWeixinData, decryptWeixinData,
getWeixinPlatform, getWeixinPlatform,
generateWeixinCache, generateWeixinCache,
getWeixinCache, getWeixinCache,
saveWeixinUserKey saveWeixinUserKey,
getWeixinAccessToken
} }
...@@ -15,5 +15,6 @@ module.exports = { ...@@ -15,5 +15,6 @@ module.exports = {
loginByEmailLink: require('./login-by-email-link'), loginByEmailLink: require('./login-by-email-link'),
loginByEmailCode: require('./login-by-email-code'), loginByEmailCode: require('./login-by-email-code'),
loginByFacebook: require('./login-by-facebook'), loginByFacebook: require('./login-by-facebook'),
loginByGoogle: require('./login-by-google') loginByGoogle: require('./login-by-google'),
loginByWeixinMobile: require('./login-by-weixin-mobile')
} }
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册