Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
DCloud
hello_uni-id-pages
提交
cbb92559
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看板
提交
cbb92559
编写于
12月 11, 2023
作者:
雪洛
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
feat: 移除一键登录、短信的调用凭据
上级
dcb60caa
变更
3
隐藏空白更改
内联
并排
Showing
3 changed file
with
176 addition
and
179 deletion
+176
-179
uni_modules/uni-id-pages/uniCloud/cloudfunctions/uni-id-co/lib/utils/sms.js
...-pages/uniCloud/cloudfunctions/uni-id-co/lib/utils/sms.js
+79
-81
uni_modules/uni-id-pages/uniCloud/cloudfunctions/uni-id-co/lib/utils/univerify.js
.../uniCloud/cloudfunctions/uni-id-co/lib/utils/univerify.js
+27
-27
uni_modules/uni-id-pages/uniCloud/cloudfunctions/uni-id-co/module/dev/get-supported-login-type.js
...unctions/uni-id-co/module/dev/get-supported-login-type.js
+70
-71
未找到文件。
uni_modules/uni-id-pages/uniCloud/cloudfunctions/uni-id-co/lib/utils/sms.js
浏览文件 @
cbb92559
const
{
setMobileVerifyCode
}
=
require
(
'
./verify-code
'
)
const
{
getVerifyCode
}
=
require
(
'
../../common/utils
'
)
/**
* 发送短信
* @param {object} param
* @param {string} param.mobile 手机号
* @param {object} param.code 可选,验证码
* @param {object} param.scene 短信场景
* @param {object} param.templateId 可选,短信模板id
* @returns
*/
async
function
sendSmsCode
({
mobile
,
code
,
scene
,
templateId
}
=
{})
{
const
requiredParams
=
[
'
name
'
,
'
smsKey
'
,
'
smsSecret
'
,
'
codeExpiresIn
'
]
const
smsConfig
=
(
this
.
config
.
service
&&
this
.
config
.
service
.
sms
)
||
{}
for
(
let
i
=
0
;
i
<
requiredParams
.
length
;
i
++
)
{
const
key
=
requiredParams
[
i
]
if
(
!
smsConfig
[
key
])
{
throw
new
Error
(
`Missing config param: service.sms.
${
key
}
`
)
}
}
if
(
!
code
)
{
code
=
getVerifyCode
()
}
let
action
switch
(
scene
)
{
case
'
login-by-sms
'
:
action
=
this
.
t
(
'
login
'
)
break
default
:
action
=
this
.
t
(
'
verify-mobile
'
)
break
}
const
sceneConfig
=
(
smsConfig
.
scene
||
{})[
scene
]
||
{}
if
(
!
templateId
)
{
templateId
=
sceneConfig
.
templateId
}
if
(
!
templateId
)
{
throw
new
Error
(
'
"templateId" is required
'
)
}
const
codeExpiresIn
=
sceneConfig
.
codeExpiresIn
||
smsConfig
.
codeExpiresIn
await
setMobileVerifyCode
.
call
(
this
,
{
mobile
,
code
,
expiresIn
:
codeExpiresIn
,
scene
})
await
uniCloud
.
sendSms
({
smsKey
:
smsConfig
.
smsKey
,
smsSecret
:
smsConfig
.
smsSecret
,
phone
:
mobile
,
templateId
,
data
:
{
name
:
smsConfig
.
name
,
code
,
action
,
expMinute
:
''
+
Math
.
round
(
codeExpiresIn
/
60
)
}
})
return
{
errCode
:
0
}
}
module
.
exports
=
{
sendSmsCode
}
const
{
setMobileVerifyCode
}
=
require
(
'
./verify-code
'
)
const
{
getVerifyCode
}
=
require
(
'
../../common/utils
'
)
/**
* 发送短信
* @param {object} param
* @param {string} param.mobile 手机号
* @param {object} param.code 可选,验证码
* @param {object} param.scene 短信场景
* @param {object} param.templateId 可选,短信模板id
* @returns
*/
async
function
sendSmsCode
({
mobile
,
code
,
scene
,
templateId
}
=
{})
{
const
requiredParams
=
[
'
name
'
,
'
codeExpiresIn
'
]
const
smsConfig
=
(
this
.
config
.
service
&&
this
.
config
.
service
.
sms
)
||
{}
for
(
let
i
=
0
;
i
<
requiredParams
.
length
;
i
++
)
{
const
key
=
requiredParams
[
i
]
if
(
!
smsConfig
[
key
])
{
throw
new
Error
(
`Missing config param: service.sms.
${
key
}
`
)
}
}
if
(
!
code
)
{
code
=
getVerifyCode
()
}
let
action
switch
(
scene
)
{
case
'
login-by-sms
'
:
action
=
this
.
t
(
'
login
'
)
break
default
:
action
=
this
.
t
(
'
verify-mobile
'
)
break
}
const
sceneConfig
=
(
smsConfig
.
scene
||
{})[
scene
]
||
{}
if
(
!
templateId
)
{
templateId
=
sceneConfig
.
templateId
}
if
(
!
templateId
)
{
throw
new
Error
(
'
"templateId" is required
'
)
}
const
codeExpiresIn
=
sceneConfig
.
codeExpiresIn
||
smsConfig
.
codeExpiresIn
await
setMobileVerifyCode
.
call
(
this
,
{
mobile
,
code
,
expiresIn
:
codeExpiresIn
,
scene
})
await
uniCloud
.
sendSms
({
smsKey
:
smsConfig
.
smsKey
,
smsSecret
:
smsConfig
.
smsSecret
,
phone
:
mobile
,
templateId
,
data
:
{
name
:
smsConfig
.
name
,
code
,
action
,
expMinute
:
''
+
Math
.
round
(
codeExpiresIn
/
60
)
}
})
return
{
errCode
:
0
}
}
module
.
exports
=
{
sendSmsCode
}
uni_modules/uni-id-pages/uniCloud/cloudfunctions/uni-id-co/lib/utils/univerify.js
浏览文件 @
cbb92559
async
function
getPhoneNumber
({
// eslint-disable-next-line camelcase
access_token
,
openid
}
=
{})
{
const
requiredParams
=
[
'
apiKey
'
,
'
apiSecret
'
]
const
univerifyConfig
=
(
this
.
config
.
service
&&
this
.
config
.
service
.
univerify
)
||
{}
for
(
let
i
=
0
;
i
<
requiredParams
.
length
;
i
++
)
{
const
key
=
requiredParams
[
i
]
if
(
!
univerifyConfig
[
key
])
{
throw
new
Error
(
`Missing config param: service.univerify.
${
key
}
`
)
}
}
return
uniCloud
.
getPhoneNumber
({
provider
:
'
univerify
'
,
appid
:
this
.
getUniversalClientInfo
().
appId
,
apiKey
:
univerifyConfig
.
apiKey
,
apiSecret
:
univerifyConfig
.
apiSecret
,
// eslint-disable-next-line camelcase
access_token
,
openid
})
}
module
.
exports
=
{
getPhoneNumber
}
async
function
getPhoneNumber
({
// eslint-disable-next-line camelcase
access_token
,
openid
}
=
{})
{
const
requiredParams
=
[
]
const
univerifyConfig
=
(
this
.
config
.
service
&&
this
.
config
.
service
.
univerify
)
||
{}
for
(
let
i
=
0
;
i
<
requiredParams
.
length
;
i
++
)
{
const
key
=
requiredParams
[
i
]
if
(
!
univerifyConfig
[
key
])
{
throw
new
Error
(
`Missing config param: service.univerify.
${
key
}
`
)
}
}
return
uniCloud
.
getPhoneNumber
({
provider
:
'
univerify
'
,
appid
:
this
.
getUniversalClientInfo
().
appId
,
apiKey
:
univerifyConfig
.
apiKey
,
apiSecret
:
univerifyConfig
.
apiSecret
,
// eslint-disable-next-line camelcase
access_token
,
openid
})
}
module
.
exports
=
{
getPhoneNumber
}
uni_modules/uni-id-pages/uniCloud/cloudfunctions/uni-id-co/module/dev/get-supported-login-type.js
浏览文件 @
cbb92559
function
isMobileCodeSupported
()
{
const
config
=
this
.
config
return
!!
(
config
.
service
&&
config
.
service
.
sms
&&
config
.
service
.
sms
.
smsKey
)
}
function
isUniverifySupport
()
{
const
config
=
this
.
config
return
!!
(
config
.
service
&&
config
.
service
.
univerify
&&
config
.
service
.
univerify
.
apiKey
)
}
function
isWeixinSupported
()
{
this
.
configUtils
.
getOauthConfig
({
provider
:
'
weixin
'
})
return
true
}
function
isQQSupported
()
{
this
.
configUtils
.
getOauthConfig
({
provider
:
'
qq
'
})
return
true
}
function
isAppleSupported
()
{
this
.
configUtils
.
getOauthConfig
({
provider
:
'
apple
'
})
return
true
}
function
isAlipaySupported
()
{
this
.
configUtils
.
getOauthConfig
({
provider
:
'
alipay
'
})
return
true
}
const
loginTypeTester
=
{
'
mobile-code
'
:
isMobileCodeSupported
,
univerify
:
isUniverifySupport
,
weixin
:
isWeixinSupported
,
qq
:
isQQSupported
,
apple
:
isAppleSupported
,
alipay
:
isAlipaySupported
}
/**
* 获取支持的登录方式
* @tutorial https://uniapp.dcloud.net.cn/uniCloud/uni-id-pages.html#get-supported-login-type
* @returns
*/
module
.
exports
=
async
function
()
{
const
supportedLoginType
=
[
'
username-password
'
,
'
mobile-password
'
,
'
email-password
'
]
for
(
const
type
in
loginTypeTester
)
{
try
{
if
(
loginTypeTester
[
type
].
call
(
this
))
{
supportedLoginType
.
push
(
type
)
}
}
catch
(
error
)
{
}
}
return
{
errCode
:
0
,
errMsg
:
''
,
supportedLoginType
}
}
function
isMobileCodeSupported
()
{
const
config
=
this
.
config
return
!!
(
config
.
service
&&
config
.
service
.
sms
&&
config
.
service
.
sms
.
smsKey
)
}
function
isUniverifySupport
()
{
return
true
}
function
isWeixinSupported
()
{
this
.
configUtils
.
getOauthConfig
({
provider
:
'
weixin
'
})
return
true
}
function
isQQSupported
()
{
this
.
configUtils
.
getOauthConfig
({
provider
:
'
qq
'
})
return
true
}
function
isAppleSupported
()
{
this
.
configUtils
.
getOauthConfig
({
provider
:
'
apple
'
})
return
true
}
function
isAlipaySupported
()
{
this
.
configUtils
.
getOauthConfig
({
provider
:
'
alipay
'
})
return
true
}
const
loginTypeTester
=
{
'
mobile-code
'
:
isMobileCodeSupported
,
univerify
:
isUniverifySupport
,
weixin
:
isWeixinSupported
,
qq
:
isQQSupported
,
apple
:
isAppleSupported
,
alipay
:
isAlipaySupported
}
/**
* 获取支持的登录方式
* @tutorial https://uniapp.dcloud.net.cn/uniCloud/uni-id-pages.html#get-supported-login-type
* @returns
*/
module
.
exports
=
async
function
()
{
const
supportedLoginType
=
[
'
username-password
'
,
'
mobile-password
'
,
'
email-password
'
]
for
(
const
type
in
loginTypeTester
)
{
try
{
if
(
loginTypeTester
[
type
].
call
(
this
))
{
supportedLoginType
.
push
(
type
)
}
}
catch
(
error
)
{
}
}
return
{
errCode
:
0
,
errMsg
:
''
,
supportedLoginType
}
}
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录