Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
DCloud
hello_uni-id-pages
提交
62c2c41f
H
hello_uni-id-pages
项目概览
DCloud
/
hello_uni-id-pages
通知
1054
Star
31
Fork
43
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
4
列表
看板
标记
里程碑
合并请求
2
DevOps
流水线
流水线任务
计划
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
H
hello_uni-id-pages
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
4
Issue
4
列表
看板
标记
里程碑
合并请求
2
合并请求
2
Pages
DevOps
DevOps
流水线
流水线任务
计划
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
流水线任务
提交
Issue看板
提交
62c2c41f
编写于
10月 12, 2022
作者:
C
chenruilong
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
feat: 增加解绑第三方账号接口
上级
7ba8f0f0
变更
14
隐藏空白更改
内联
并排
Showing
14 changed file
with
541 addition
and
195 deletion
+541
-195
uni_modules/uni-id-pages/pages/userinfo/userinfo.vue
uni_modules/uni-id-pages/pages/userinfo/userinfo.vue
+232
-185
uni_modules/uni-id-pages/uniCloud/cloudfunctions/uni-id-co/common/constants.js
...ges/uniCloud/cloudfunctions/uni-id-co/common/constants.js
+5
-1
uni_modules/uni-id-pages/uniCloud/cloudfunctions/uni-id-co/common/error.js
...d-pages/uniCloud/cloudfunctions/uni-id-co/common/error.js
+5
-1
uni_modules/uni-id-pages/uniCloud/cloudfunctions/uni-id-co/config/permission.js
...es/uniCloud/cloudfunctions/uni-id-co/config/permission.js
+12
-0
uni_modules/uni-id-pages/uniCloud/cloudfunctions/uni-id-co/index.obj.js
...i-id-pages/uniCloud/cloudfunctions/uni-id-co/index.obj.js
+31
-2
uni_modules/uni-id-pages/uniCloud/cloudfunctions/uni-id-co/lang/en.js
...uni-id-pages/uniCloud/cloudfunctions/uni-id-co/lang/en.js
+4
-1
uni_modules/uni-id-pages/uniCloud/cloudfunctions/uni-id-co/lang/zh-hans.js
...d-pages/uniCloud/cloudfunctions/uni-id-co/lang/zh-hans.js
+4
-1
uni_modules/uni-id-pages/uniCloud/cloudfunctions/uni-id-co/lib/utils/relate.js
...ges/uniCloud/cloudfunctions/uni-id-co/lib/utils/relate.js
+92
-2
uni_modules/uni-id-pages/uniCloud/cloudfunctions/uni-id-co/module/relate/bind-alipay.js
...oud/cloudfunctions/uni-id-co/module/relate/bind-alipay.js
+1
-1
uni_modules/uni-id-pages/uniCloud/cloudfunctions/uni-id-co/module/relate/index.js
.../uniCloud/cloudfunctions/uni-id-co/module/relate/index.js
+5
-1
uni_modules/uni-id-pages/uniCloud/cloudfunctions/uni-id-co/module/relate/unbind-alipay.js
...d/cloudfunctions/uni-id-co/module/relate/unbind-alipay.js
+32
-0
uni_modules/uni-id-pages/uniCloud/cloudfunctions/uni-id-co/module/relate/unbind-apple.js
...ud/cloudfunctions/uni-id-co/module/relate/unbind-apple.js
+32
-0
uni_modules/uni-id-pages/uniCloud/cloudfunctions/uni-id-co/module/relate/unbind-qq.js
...Cloud/cloudfunctions/uni-id-co/module/relate/unbind-qq.js
+46
-0
uni_modules/uni-id-pages/uniCloud/cloudfunctions/uni-id-co/module/relate/unbind-weixin.js
...d/cloudfunctions/uni-id-co/module/relate/unbind-weixin.js
+40
-0
未找到文件。
uni_modules/uni-id-pages/pages/userinfo/userinfo.vue
浏览文件 @
62c2c41f
...
...
@@ -14,6 +14,16 @@
<uni-list-item
v-if=
"hasPwd"
class=
"item"
@
click=
"changePassword"
title=
"修改密码"
link
>
</uni-list-item>
</uni-list>
<uni-list
class=
"mt10"
>
<uni-list-item
@
click=
"bindThirdAccount('Weixin')"
title=
"微信"
link
:rightText=
"userInfo.wx_openid ? '已绑定': '未绑定' "
></uni-list-item>
<uni-list-item
@
click=
"bindThirdAccount('QQ')"
title=
"QQ"
link
:rightText=
"userInfo.qq_openid ? '已绑定': '未绑定' "
></uni-list-item>
<uni-list-item
@
click=
"bindThirdAccount('Alipay')"
title=
"支付宝"
link
:rightText=
"userInfo.ali_openid ? '已绑定': '未绑定' "
></uni-list-item>
<uni-list-item
@
click=
"bindThirdAccount('Apple')"
title=
"Apple"
link
:rightText=
"userInfo.apple_openid ? '已绑定': '未绑定' "
></uni-list-item>
</uni-list>
<uni-list
class=
"mt10"
>
<uni-list-item
@
click=
"deactivate"
title=
"注销账号"
link=
"navigateTo"
></uni-list-item>
</uni-list>
...
...
@@ -30,219 +40,256 @@
</view>
</template>
<
script
>
const
db
=
uniCloud
.
database
();
const
usersTable
=
db
.
collection
(
'
uni-id-users
'
)
const
uniIdCo
=
uniCloud
.
importObject
(
"
uni-id-co
"
)
import
common
from
'
@/uni_modules/uni-id-pages/common/common.js
'
;
export
default
{
data
()
{
return
{
univerifyStyle
:
{
authButton
:
{
"
title
"
:
"
本机号码一键绑定
"
,
// 授权按钮文案
},
otherLoginButton
:
{
"
title
"
:
"
其他号码绑定
"
,
}
},
userInfo
:
{
mobile
:
''
,
nickname
:
''
const
db
=
uniCloud
.
database
();
const
usersTable
=
db
.
collection
(
'
uni-id-users
'
)
const
uniIdCo
=
uniCloud
.
importObject
(
"
uni-id-co
"
)
import
common
from
'
@/uni_modules/uni-id-pages/common/common.js
'
;
export
default
{
data
()
{
return
{
univerifyStyle
:
{
authButton
:
{
"
title
"
:
"
本机号码一键绑定
"
,
// 授权按钮文案
},
hasLogin
:
false
,
hasPwd
:
false
,
showLoginManage
:
false
//通过页面传参隐藏登录&退出登录按钮
}
otherLoginButton
:
{
"
title
"
:
"
其他号码绑定
"
,
}
},
userInfo
:
{
mobile
:
''
,
nickname
:
''
},
hasLogin
:
false
,
hasPwd
:
false
,
showLoginManage
:
false
//通过页面传参隐藏登录&退出登录按钮
}
},
async
onShow
()
{
this
.
univerifyStyle
.
authButton
.
title
=
"
本机号码一键绑定
"
this
.
univerifyStyle
.
otherLoginButton
.
title
=
"
其他号码绑定
"
},
async
onLoad
(
e
)
{
if
(
e
.
showLoginManage
)
{
this
.
showLoginManage
=
true
//通过页面传参隐藏登录&退出登录按钮
}
this
.
getUserInfo
()
//判断当前用户是否有密码,否则就不显示密码修改功能
let
res
=
await
uniIdCo
.
getAccountInfo
()
this
.
hasPwd
=
res
.
isPasswordSet
},
methods
:
{
login
()
{
uni
.
navigateTo
({
url
:
'
/uni_modules/uni-id-pages/pages/login/login-withoutpwd
'
,
complete
:
(
e
)
=>
{
console
.
log
(
e
);
}
})
},
async
onShow
()
{
this
.
univerifyStyle
.
authButton
.
title
=
"
本机号码一键绑定
"
this
.
univerifyStyle
.
otherLoginButton
.
title
=
"
其他号码绑定
"
logout
:
common
.
logout
,
changePassword
()
{
uni
.
navigateTo
({
url
:
'
/uni_modules/uni-id-pages/pages/userinfo/change_pwd/change_pwd
'
,
complete
:
(
e
)
=>
{
console
.
log
(
e
);
}
})
},
async
onLoad
(
e
)
{
if
(
e
.
showLoginManage
){
this
.
showLoginManage
=
true
//通过页面传参隐藏登录&退出登录按钮
}
this
.
getUserInfo
()
//判断当前用户是否有密码,否则就不显示密码修改功能
let
res
=
await
uniIdCo
.
getAccountInfo
()
this
.
hasPwd
=
res
.
isPasswordSet
getUserInfo
(
e
)
{
uni
.
showLoading
({
mask
:
true
});
usersTable
.
where
(
"
'_id' == $cloudEnv_uid
"
).
field
(
'
mobile,nickname,email,wx_openid,wx_unionid,ali_openid,apple_open,qq_openid,qq_unionid
'
).
get
().
then
(
res
=>
{
console
.
log
({
res
});
this
.
userInfo
=
res
.
result
.
data
[
0
]
console
.
log
(
'
this.userInfo
'
,
this
.
userInfo
);
this
.
hasLogin
=
true
}).
catch
(
e
=>
{
this
.
userInfo
=
{}
this
.
hasLogin
=
false
console
.
log
(
e
.
message
,
e
.
errCode
);
}).
finally
(
e
=>
{
// console.log(e);
uni
.
hideLoading
()
})
},
bindMobile
()
{
// #ifdef APP-PLUS
uni
.
preLogin
({
provider
:
'
univerify
'
,
success
:
this
.
univerify
(),
//预登录成功
fail
:
(
res
)
=>
{
// 预登录失败
// 不显示一键登录选项(或置灰)
console
.
log
(
res
)
this
.
bindMobileBySmsCode
()
}
})
// #endif
// #ifdef MP-WEIXIN
this
.
$refs
[
'
bind-mobile-by-sms
'
].
open
()
// #endif
// #ifdef H5
//...去用验证码绑定
this
.
bindMobileBySmsCode
()
// #endif
},
methods
:
{
login
()
{
uni
.
navigateTo
({
url
:
'
/uni_modules/uni-id-pages/pages/login/login-withoutpwd
'
,
complete
:
(
e
)
=>
{
univerify
()
{
uni
.
login
({
"
provider
"
:
'
univerify
'
,
"
univerifyStyle
"
:
this
.
univerifyStyle
,
success
:
async
e
=>
{
console
.
log
(
e
.
authResult
);
uniIdCo
.
bindMobileByUniverify
(
e
.
authResult
).
then
(
res
=>
{
console
.
log
(
res
);
this
.
getUserInfo
()
}).
catch
(
e
=>
{
console
.
log
(
e
);
}
})
},
logout
:
common
.
logout
,
changePassword
(){
uni
.
navigateTo
({
url
:
'
/uni_modules/uni-id-pages/pages/userinfo/change_pwd/change_pwd
'
,
complete
:
(
e
)
=>
{
}).
finally
(
e
=>
{
console
.
log
(
e
);
}
})
},
getUserInfo
(
e
)
{
uni
.
showLoading
({
mask
:
true
});
usersTable
.
where
(
"
'_id' == $cloudEnv_uid
"
).
field
(
'
mobile,nickname,email
'
).
get
().
then
(
res
=>
{
console
.
log
({
res
});
this
.
userInfo
=
res
.
result
.
data
[
0
]
console
.
log
(
'
this.userInfo
'
,
this
.
userInfo
);
this
.
hasLogin
=
true
}).
catch
(
e
=>
{
this
.
userInfo
=
{}
this
.
hasLogin
=
false
console
.
log
(
e
.
message
,
e
.
errCode
);
}).
finally
(
e
=>
{
// console.log(e);
uni
.
hideLoading
()
})
},
bindMobile
()
{
// #ifdef APP-PLUS
uni
.
preLogin
({
provider
:
'
univerify
'
,
success
:
this
.
univerify
(),
//预登录成功
fail
:
(
res
)
=>
{
// 预登录失败
// 不显示一键登录选项(或置灰)
console
.
log
(
res
)
uni
.
closeAuthView
()
})
},
fail
:
(
err
)
=>
{
console
.
log
(
err
);
if
(
err
.
code
==
'
30002
'
||
err
.
code
==
'
30001
'
)
{
this
.
bindMobileBySmsCode
()
}
}
})
},
bindMobileBySmsCode
()
{
uni
.
navigateTo
({
url
:
'
./bind-mobile/bind-mobile
'
,
events
:
{
getUserInfo
:
()
=>
{
this
.
getUserInfo
()
}
},
complete
(
e
)
{
console
.
log
(
e
);
}
})
},
setNickname
(
nickname
)
{
console
.
log
(
nickname
);
if
(
nickname
)
{
usersTable
.
where
(
'
_id==$env.uid
'
).
update
({
nickname
}).
then
(
e
=>
{
console
.
log
(
e
);
if
(
e
.
result
.
updated
)
{
uni
.
showToast
({
title
:
"
更新成功
"
,
icon
:
'
none
'
});
this
.
userInfo
.
nickname
=
nickname
}
else
{
uni
.
showToast
({
title
:
"
没有改变
"
,
icon
:
'
none
'
});
}
})
// #endif
// #ifdef MP-WEIXIN
this
.
$refs
[
'
bind-mobile-by-sms
'
].
open
()
// #endif
this
.
$refs
.
dialog
.
close
()
}
else
{
this
.
$refs
.
dialog
.
open
()
}
},
deactivate
()
{
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
()]
// #ifdef H5
//...去用验证码绑定
this
.
bindMobileBySmsCode
()
// #endif
},
univerify
()
{
if
(
this
.
userInfo
[
bindField
])
{
await
uniIdCo
[
'
unbind
'
+
provider
]()
await
this
.
getUserInfo
()
}
else
{
uni
.
login
({
"
provider
"
:
'
univerify
'
,
"
univerifyStyle
"
:
this
.
univerifyStyl
e
,
provider
:
provider
.
toLowerCase
()
,
onlyAuthorize
:
tru
e
,
success
:
async
e
=>
{
console
.
log
(
e
.
authResult
);
uniIdCo
.
bindMobileByUniverify
(
e
.
authResult
).
then
(
res
=>
{
console
.
log
(
res
);
this
.
getUserInfo
()
}).
catch
(
e
=>
{
console
.
log
(
e
);
}).
finally
(
e
=>
{
console
.
log
(
e
);
uni
.
closeAuthView
()
const
res
=
await
uniIdCo
[
'
bind
'
+
provider
]({
code
:
e
.
code
})
},
fail
:
(
err
)
=>
{
console
.
log
(
err
);
if
(
err
.
code
==
'
30002
'
||
err
.
code
==
'
30001
'
)
{
this
.
bindMobileBySmsCode
()
}
}
})
},
bindMobileBySmsCode
()
{
uni
.
navigateTo
({
url
:
'
./bind-mobile/bind-mobile
'
,
events
:
{
getUserInfo
:
()
=>
{
this
.
getUserInfo
()
if
(
res
.
errCode
)
{
uni
.
showToast
({
title
:
res
.
errMsg
||
'
绑定失败
'
})
}
await
this
.
getUserInfo
()
},
complete
(
e
)
{
console
.
log
(
e
);
fail
:
async
(
err
)
=>
{
console
.
log
(
err
);
uni
.
hideLoading
()
}
})
},
setNickname
(
nickname
)
{
console
.
log
(
nickname
);
if
(
nickname
)
{
usersTable
.
where
(
'
_id==$env.uid
'
).
update
({
nickname
}).
then
(
e
=>
{
console
.
log
(
e
);
if
(
e
.
result
.
updated
)
{
uni
.
showToast
({
title
:
"
更新成功
"
,
icon
:
'
none
'
});
this
.
userInfo
.
nickname
=
nickname
}
else
{
uni
.
showToast
({
title
:
"
没有改变
"
,
icon
:
'
none
'
});
}
})
this
.
$refs
.
dialog
.
close
()
}
else
{
this
.
$refs
.
dialog
.
open
()
}
},
deactivate
(){
uni
.
navigateTo
({
url
:
"
/uni_modules/uni-id-pages/pages/userinfo/deactivate/deactivate
"
})
}
}
}
}
</
script
>
<
style
lang=
"scss"
scoped
>
@import
url("/uni_modules/uni-id-pages/common/login-page.scss")
;
@import
url("/uni_modules/uni-id-pages/common/login-page.scss")
;
.uni-content
{
padding
:
0
;
}
/* #ifndef APP-NVUE */
view
{
display
:
flex
;
box-sizing
:
border-box
;
flex-direction
:
column
;
}
@media
screen
and
(
min-width
:
690px
)
{
.uni-content
{
padding
:
0
;
max-width
:
690px
;
margin-left
:
calc
(
50%
-
345px
);
border
:
none
;
max-height
:
none
;
border-radius
:
0
;
box-shadow
:
none
;
}
}
/* #ifndef APP-NVUE */
view
{
display
:
flex
;
box-sizing
:
border-box
;
flex-direction
:
column
;
}
@media
screen
and
(
min-width
:
690px
)
{
.uni-content
{
padding
:
0
;
max-width
:
690px
;
margin-left
:
calc
(
50%
-
345px
);
border
:
none
;
max-height
:
none
;
border-radius
:
0
;
box-shadow
:
none
;
}
}
/* #endif */
.avatar
{
align-items
:
center
;
justify-content
:
center
;
margin
:
22px
0
;
width
:
100%
;
}
/* #endif */
.avatar
{
align-items
:
center
;
justify-content
:
center
;
margin
:
22px
0
;
width
:
100%
;
}
.item
{
flex
:
1
;
flex-direction
:
row
;
justify-content
:
space-between
;
align-items
:
center
;
}
.item
{
flex
:
1
;
flex-direction
:
row
;
justify-content
:
space-between
;
align-items
:
center
;
}
button
{
margin
:
10%
;
margin-top
:
40px
;
border-radius
:
0
;
background-color
:
#FFFFFF
;
width
:
80%
;
}
button
{
margin
:
10%
;
margin-top
:
40px
;
border-radius
:
0
;
background-color
:
#FFFFFF
;
width
:
80%
;
}
.mt10
{
margin-top
:
10px
;
}
.mt10
{
margin-top
:
10px
;
}
</
style
>
uni_modules/uni-id-pages/uniCloud/cloudfunctions/uni-id-co/common/constants.js
浏览文件 @
62c2c41f
...
...
@@ -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
=
{
...
...
uni_modules/uni-id-pages/uniCloud/cloudfunctions/uni-id-co/common/error.js
浏览文件 @
62c2c41f
...
...
@@ -30,7 +30,11 @@ 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
'
}
function
isUniIdError
(
errCode
)
{
...
...
uni_modules/uni-id-pages/uniCloud/cloudfunctions/uni-id-co/config/permission.js
浏览文件 @
62c2c41f
...
...
@@ -62,5 +62,17 @@ module.exports = {
},
getAccountInfo
:
{
auth
:
true
},
unbindWeixin
:
{
auth
:
true
},
unbindAlipay
:
{
auth
:
true
},
unbindQQ
:
{
auth
:
true
},
unbindApple
:
{
auth
:
true
}
}
uni_modules/uni-id-pages/uniCloud/cloudfunctions/uni-id-co/index.obj.js
浏览文件 @
62c2c41f
...
...
@@ -42,7 +42,11 @@ const {
bindAlipay
,
bindApple
,
bindQQ
,
bindWeixin
bindWeixin
,
unbindWeixin
,
unbindAlipay
,
unbindQQ
,
unbindApple
}
=
require
(
'
./module/relate/index
'
)
const
{
updatePwd
,
...
...
@@ -543,5 +547,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
}
uni_modules/uni-id-pages/uniCloud/cloudfunctions/uni-id-co/lang/en.js
浏览文件 @
62c2c41f
...
...
@@ -36,7 +36,10 @@ const sentence = {
'
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-admin-exist-in-other-apps
'
:
'
Administrator is registered in other consoles
'
'
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-unique-login
'
:
'
This is the only way to login at the moment, please bind your phone number and then try to unbind
'
}
module
.
exports
=
{
...
...
uni_modules/uni-id-pages/uniCloud/cloudfunctions/uni-id-co/lang/zh-hans.js
浏览文件 @
62c2c41f
...
...
@@ -36,7 +36,10 @@ const sentence = {
'
uni-id-invalid-invite-code
'
:
'
邀请码不可用
'
,
'
uni-id-change-inviter-forbidden
'
:
'
禁止修改邀请人
'
,
'
uni-id-bind-conflict
'
:
'
此账号已被绑定
'
,
'
uni-id-admin-exist-in-other-apps
'
:
'
超级管理员已在其他控制台注册
'
'
uni-id-admin-exist-in-other-apps
'
:
'
超级管理员已在其他控制台注册
'
,
'
uni-id-unbind-failed
'
:
'
请先绑定后再解绑
'
,
'
uni-id-unbind-not-supported
'
:
'
不支持解绑
'
,
'
uni-id-unbind-unique-login
'
:
'
这是当前唯一登录方式,请绑定手机号后再尝试解绑
'
}
module
.
exports
=
{
...
...
uni_modules/uni-id-pages/uniCloud/cloudfunctions/uni-id-co/lib/utils/relate.js
浏览文件 @
62c2c41f
...
...
@@ -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,90 @@ 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
&&
!
user
.
mobile
)
{
throw
{
errCode
:
ERROR
.
UNBIND_UNIQUE_LOGIN
}
}
}
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
}
uni_modules/uni-id-pages/uniCloud/cloudfunctions/uni-id-co/module/relate/bind-alipay.js
浏览文件 @
62c2c41f
...
...
@@ -47,7 +47,7 @@ module.exports = async function (params = {}) {
}
=
getAlipayAccountResult
const
bindAccount
=
{
a
pple
_openid
:
openid
a
li
_openid
:
openid
}
await
preBind
.
call
(
this
,
{
uid
,
...
...
uni_modules/uni-id-pages/uniCloud/cloudfunctions/uni-id-co/module/relate/index.js
浏览文件 @
62c2c41f
...
...
@@ -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
'
)
}
uni_modules/uni-id-pages/uniCloud/cloudfunctions/uni-id-co/module/relate/unbind-alipay.js
0 → 100644
浏览文件 @
62c2c41f
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
})
}
uni_modules/uni-id-pages/uniCloud/cloudfunctions/uni-id-co/module/relate/unbind-apple.js
0 → 100644
浏览文件 @
62c2c41f
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
})
}
uni_modules/uni-id-pages/uniCloud/cloudfunctions/uni-id-co/module/relate/unbind-qq.js
0 → 100644
浏览文件 @
62c2c41f
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
})
}
uni_modules/uni-id-pages/uniCloud/cloudfunctions/uni-id-co/module/relate/unbind-weixin.js
0 → 100644
浏览文件 @
62c2c41f
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
})
}
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录