Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
DCloud
uni-starter
提交
e26e86ac
U
uni-starter
项目概览
DCloud
/
uni-starter
通知
4671
Star
228
Fork
210
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
3
列表
看板
标记
里程碑
合并请求
0
DevOps
流水线
流水线任务
计划
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
U
uni-starter
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
3
Issue
3
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
DevOps
DevOps
流水线
流水线任务
计划
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
流水线任务
提交
Issue看板
提交
e26e86ac
编写于
1月 25, 2022
作者:
DCloud_JSON
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
- 保存到改用异步方法,方便通过拦截器执行更新后的操作 - 新增通过拦截器监听更新,调用云函数刷新刷新设备信息token有效期的API - 删除留言板示例 - 修复图片验证码样式问题
上级
c26635f7
变更
23
显示空白变更内容
内联
并排
Showing
23 changed file
with
379 addition
and
579 deletion
+379
-579
README.md
README.md
+0
-1
changelog.md
changelog.md
+5
-0
common/appInit.js
common/appInit.js
+107
-65
lang/en.js
lang/en.js
+0
-9
lang/zh-Hans.js
lang/zh-Hans.js
+0
-9
package.json
package.json
+2
-3
pages.json
pages.json
+0
-19
pages/ucenter/guestbook/guestbook.vue
pages/ucenter/guestbook/guestbook.vue
+0
-223
pages/ucenter/login-page/pwd-login/pwd-login.vue
pages/ucenter/login-page/pwd-login/pwd-login.vue
+1
-1
pages/ucenter/ucenter.vue
pages/ucenter/ucenter.vue
+0
-4
store/modules/user.js
store/modules/user.js
+11
-4
uni-starter.config.js
uni-starter.config.js
+0
-1
uniCloud-aliyun/database/JQL数据库管理.jql
uniCloud-aliyun/database/JQL数据库管理.jql
+1
-1
uniCloud-aliyun/database/guestbook.schema.json
uniCloud-aliyun/database/guestbook.schema.json
+0
-57
uni_modules/uni-config-center/uniCloud/cloudfunctions/common/uni-config-center/push/config.json
.../cloudfunctions/common/uni-config-center/push/config.json
+6
-6
uni_modules/uni-config-center/uniCloud/cloudfunctions/common/uni-config-center/uni-push/config.json
...udfunctions/common/uni-config-center/uni-push/config.json
+9
-0
uni_modules/uni-id-cf/changelog.md
uni_modules/uni-id-cf/changelog.md
+8
-2
uni_modules/uni-id-cf/package.json
uni_modules/uni-id-cf/package.json
+2
-2
uni_modules/uni-id-cf/uniCloud/cloudfunctions/uni-id-cf/index.js
...ules/uni-id-cf/uniCloud/cloudfunctions/uni-id-cf/index.js
+221
-169
uni_modules/uni-id/changelog.md
uni_modules/uni-id/changelog.md
+3
-0
uni_modules/uni-id/package.json
uni_modules/uni-id/package.json
+1
-1
uni_modules/uni-id/uniCloud/cloudfunctions/common/uni-id/index.js
...les/uni-id/uniCloud/cloudfunctions/common/uni-id/index.js
+1
-1
uni_modules/uni-id/uniCloud/cloudfunctions/common/uni-id/package.json
...uni-id/uniCloud/cloudfunctions/common/uni-id/package.json
+1
-1
未找到文件。
README.md
浏览文件 @
e26e86ac
...
...
@@ -163,7 +163,6 @@ uni-starter服务端使用[uni-config-center](https://ext.dcloud.net.cn/plugin?i
"
/pages/common/webview/webview
"
,
"
/pages/grid/grid
"
,
"
/pages/ucenter/ucenter
"
,
"
/pages/ucenter/guestbook/guestbook
"
,
"
/pages/ucenter/about/about
"
,
"
/pages/ucenter/settings/settings
"
]
...
...
changelog.md
浏览文件 @
e26e86ac
## 1.1.29(2022-01-25)
-
保存
`uni_id_token`
到
`storage`
改用异步方法,方便通过拦截器执行
`token`
更新后的操作
-
新增通过拦截器监听
`uni_id_token`
更新,调用云函数刷新刷新设备信息token有效期的API
`renewDeviceTokenExpired`
-
删除留言板示例
-
修复图片验证码样式问题
## 1.1.28(2022-01-12)
删除list页第37行多了个
`?`
引起的报错
## 1.1.27(2022-01-11)
...
...
common/appInit.js
浏览文件 @
e26e86ac
...
...
@@ -88,8 +88,7 @@ export default async function() {
'
TOKEN_INVALID
'
,
'
TOKEN_INVALID_TOKEN_EXPIRED
'
,
'
TOKEN_INVALID_WRONG_TOKEN
'
,
'
TOKEN_INVALID_ANONYMOUS_USER
'
,
'
TOKEN_INVALID_ANONYMOUS_USER
'
].
includes
(
code
))
{
uni
.
navigateTo
({
url
:
'
/pages/ucenter/login-page/index/index
'
...
...
@@ -115,75 +114,43 @@ export default async function() {
})
})
uni
.
addInterceptor
(
'
setStorage
'
,
{
invoke
(
args
)
{
if
(
args
.
data
&&
args
.
key
==
'
uni_id_token
'
)
{
let
oldToken
=
uni
.
getStorageSync
(
'
uni_id_token
'
)
if
(
oldToken
.
length
){
console
.
log
(
'
监听到token更新,就刷新push_clientid的有效期
'
);
uniCloud
.
callFunction
({
name
:
'
uni-id-cf
'
,
data
:{
"
action
"
:
"
renewDeviceTokenExpiredxpired
"
,
"
params
"
:
{
push_clientid
}
},
complete
:
(
e
)
=>
{
console
.
log
(
e
);
}
})
}
}
// console.log('interceptor-complete', args)
},
complete
(
e
)
{
// console.log(e);
}
})
const
Debug
=
false
;
//拦截器封装callFunction
let
callFunctionOption
;
uniCloud
.
addInterceptor
(
'
callFunction
'
,
{
async
invoke
(
option
)
{
// #ifdef APP-PLUS
// 判断如果是执行登录(无论是哪种登录方式),就记录用户的相关设备id
// 注意:注册可能不仅仅走register接口,还有登录并注册的接口
if
(
option
.
name
==
'
uni-id-cf
'
&&
(
option
.
data
.
action
==
'
register
'
||
option
.
data
.
action
.
slice
(
0
,
5
)
==
'
login
'
)
)
{
let
oaid
=
await
new
Promise
((
callBack
,
fail
)
=>
{
if
(
uni
.
getSystemInfoSync
().
platform
==
"
android
"
)
{
plus
.
device
.
getOAID
({
success
:
function
(
e
)
{
callBack
(
e
.
oaid
)
// console.log('getOAID success: '+JSON.stringify(e));
},
fail
:
function
(
e
)
{
callBack
()
console
.
log
(
'
getOAID failed:
'
+
JSON
.
stringify
(
e
));
}
});
}
else
{
callBack
()
}
})
let
imei
=
await
new
Promise
((
callBack
,
fail
)
=>
{
if
(
uni
.
getSystemInfoSync
().
platform
==
"
android
"
)
{
plus
.
device
.
getInfo
({
success
:
function
(
e
)
{
callBack
(
e
.
imei
)
// console.log('getOAID success: '+JSON.stringify(e));
},
fail
:
function
(
e
)
{
callBack
()
console
.
log
(
'
getOAID failed:
'
+
JSON
.
stringify
(
e
));
}
});
}
else
{
callBack
()
}
})
let
push_clientid
=
''
,
idfa
=
plus
.
storage
.
getItem
(
'
idfa
'
)
||
''
;
//idfa有需要的用户在应用首次启动时自己获取存储到storage中
try
{
push_clientid
=
plus
.
push
.
getClientInfo
().
clientid
}
catch
(
e
)
{
uni
.
showModal
({
content
:
'
获取推送标识失败。如果你的应用不需要推送功能,请注释掉本代码块
'
,
showCancel
:
false
,
confirmText
:
"
好的
"
});
console
.
log
(
e
)
}
let
deviceInfo
=
{
push_clientid
,
// 获取匿名设备标识符
imei
,
oaid
,
idfa
}
//console.log("重新登录/注册,获取设备id", deviceInfo);
option
.
data
.
deviceInfo
=
deviceInfo
// #ifndef H5
//注册可能不仅仅走register接口,还有登录并注册的接口
option
.
data
.
deviceInfo
=
await
getDeviceInfo
()
console
.
log
(
"
重新登录/注册,获取设备id
"
,
option
.
data
.
deviceInfo
);
option
.
data
.
inviteCode
=
await
new
Promise
((
callBack
)
=>
{
uni
.
getClipboardData
({
success
:
function
(
res
)
{
...
...
@@ -206,9 +173,7 @@ export default async function() {
}
});
})
// #endif
}
// #endif
// console.log(JSON.stringify(option));
callFunctionOption
=
option
},
...
...
@@ -261,7 +226,6 @@ export default async function() {
});
},
success
:
(
e
)
=>
{
// console.log(e);
const
{
token
,
tokenExpired
...
...
@@ -455,3 +419,81 @@ function initAppVersion() {
// 检查更新
// #endif
}
async
function
getDeviceInfo
()
{
let
deviceInfo
=
{
"
uuid
"
:
''
,
"
vendor
"
:
''
,
"
push_clientid
"
:
''
,
"
imei
"
:
''
,
"
oaid
"
:
''
,
"
idfa
"
:
''
,
"
model
"
:
''
,
"
platform
"
:
''
,
}
const
{
model
,
platform
,
}
=
uni
.
getSystemInfoSync
();
Object
.
assign
(
deviceInfo
,
{
model
,
platform
});
// #ifdef APP-PLUS
const
oaid
=
await
new
Promise
((
callBack
,
fail
)
=>
{
if
(
deviceInfo
.
platform
==
"
android
"
)
{
plus
.
device
.
getOAID
({
success
:
function
(
e
)
{
callBack
(
e
.
oaid
)
// console.log('getOAID success: '+JSON.stringify(e));
},
fail
:
function
(
e
)
{
callBack
()
console
.
log
(
'
getOAID failed:
'
+
JSON
.
stringify
(
e
));
}
});
}
else
{
callBack
()
}
}),
{
imei
,
uuid
}
=
await
new
Promise
((
callBack
,
fail
)
=>
{
plus
.
device
.
getInfo
({
success
:
function
(
e
)
{
callBack
(
e
)
// console.log('getOAID success: '+JSON.stringify(e));
},
fail
:
function
(
e
)
{
callBack
()
console
.
log
(
'
getOAID failed:
'
+
JSON
.
stringify
(
e
));
}
});
}),
idfa
=
plus
.
storage
.
getItem
(
'
idfa
'
)
||
''
,
//idfa有需要的用户在应用首次启动时自己获取存储到storage中
vendor
=
plus
.
device
.
vendor
;
try
{
deviceInfo
.
push_clientid
=
uni
.
getStorageSync
(
'
cid
'
)
//先都走在线
// deviceInfo.push_clientid = plus.push.getClientInfo().clientid
}
catch
(
e
)
{
uni
.
showModal
({
content
:
'
获取推送标识失败。如果你的应用不需要推送功能,请注释掉本代码块
'
,
showCancel
:
false
,
confirmText
:
"
好的
"
});
console
.
log
(
e
)
}
Object
.
assign
(
deviceInfo
,
{
imei
,
uuid
,
idfa
,
vendor
});
// #endif
// #ifndef APP-PLUS
deviceInfo
.
push_clientid
=
uni
.
getStorageSync
(
'
cid
'
)
// #endif
return
deviceInfo
}
\ No newline at end of file
lang/en.js
浏览文件 @
e26e86ac
...
...
@@ -58,7 +58,6 @@ export default {
readArticles
:
"
Read Articles
"
,
myScore
:
"
My Score
"
,
invite
:
"
Invite Friends
"
,
guestBook
:
"
Guest Book Example
"
,
feedback
:
"
Problems And Feedback
"
,
settings
:
"
Settings
"
,
about
:
"
About
"
,
...
...
@@ -98,14 +97,6 @@ export default {
toSet
:
"
Go to settings
"
,
error
:
"
error
"
,
},
guestbook
:
{
navigationBarTitle
:
"
Message board
"
,
msgContent
:
"
post message content
"
,
notAvailable
:
"
not available for visitors who are not logged in
"
,
send
:
"
send
"
,
addSucceeded
:
"
Successfully added
"
,
noPermission
:
"
You don't have permission for this operation
"
,
},
uniFeedback
:
{
navigationBarTitle
:
"
Problems and feedback
"
,
msgTitle
:
"
Message content
"
,
...
...
lang/zh-Hans.js
浏览文件 @
e26e86ac
...
...
@@ -59,7 +59,6 @@ export default {
readArticles
:
"
阅读过的文章
"
,
myScore
:
"
我的积分
"
,
invite
:
"
分销推荐
"
,
guestBook
:
"
留言板示例
"
,
feedback
:
"
问题与反馈
"
,
settings
:
"
设置
"
,
checkUpdate
:
"
检查更新
"
,
...
...
@@ -99,14 +98,6 @@ export default {
toSet
:
"
前往设置
"
,
error
:
"
错误
"
,
},
guestbook
:{
navigationBarTitle
:
"
留言板
"
,
msgContent
:
"
发表留言内容
"
,
notAvailable
:
"
未登录游客不可用
"
,
send
:
"
发送
"
,
addSucceeded
:
"
新增成功
"
,
noPermission
:
"
你没有该操作权限
"
,
},
uniFeedback
:{
navigationBarTitle
:
"
问题与反馈
"
,
msgTitle
:
"
留言内容
"
,
...
...
package.json
浏览文件 @
e26e86ac
{
"id"
:
"uni-starter"
,
"displayName"
:
"uni-starter"
,
"version"
:
"1.1.2
8
"
,
"version"
:
"1.1.2
9
"
,
"description"
:
"云端一体应用快速开发基本项目模版"
,
"keywords"
:
[
"login"
,
"登录"
,
"搜索"
,
"uni-id实例"
,
"留言板"
,
""
"留言板"
],
"repository"
:
"https://codechina.csdn.net/dcloud/uni-starter.git"
,
"engines"
:
{
...
...
pages.json
浏览文件 @
e26e86ac
...
...
@@ -169,25 +169,6 @@
"navigationBarTitleText"
:
"意见反馈"
,
"enablePullDownRefresh"
:
false
}
},
{
"path"
:
"pages/ucenter/guestbook/guestbook"
,
"style"
:
{
"navigationBarTitleText"
:
"留言板"
,
"enablePullDownRefresh"
:
false
,
"app-plus"
:
{
"titleNView"
:
{
"buttons"
:
[{
"text"
:
"切换"
,
"fontSize"
:
"12px"
},
{
"text"
:
"注销"
,
"fontSize"
:
"12px"
}
]
}
}
}
}
],
"globalStyle"
:
{
...
...
pages/ucenter/guestbook/guestbook.vue
已删除
100644 → 0
浏览文件 @
c26635f7
<
template
>
<view
class=
"page"
>
<unicloud-db
ref=
"udb"
class=
"content"
v-slot:default=
"
{data,pagination,hasMore, loading, error}"
collection="guestbook,uni-id-users" :where="udbWhere" field="user_id.nickname,user_id._id,user_id.avatar_file,text,_id,state">
<view
v-if=
"error"
>
{{
error
.
message
}}
</view>
<view
v-else
>
<view
v-for=
"(item,index) in data"
:key=
"index"
class=
"item"
>
<view
class=
"main"
>
<cloud-image
:src=
"item.user_id[0].avatar_file.url"
></cloud-image>
<view>
<text
class=
"nickname"
>
{{
item
.
user_id
[
0
].
nickname
}}
</text>
<text>
{{
item
.
text
}}
</text>
</view>
</view>
<view
class=
"handle"
>
<switch
:checked=
"item.state"
@
change=
"setState(item,$event)"
/>
<uni-icons
@
click=
"deleteItem(item._id)"
type=
"trash"
size=
"18"
color=
"#c9c3cd"
/>
</view>
</view>
<uni-load-state
:state=
"
{data,pagination,hasMore,loading}">
</uni-load-state>
</view>
</unicloud-db>
<view
class=
"submit-box"
>
<cloud-image
class=
"userImg"
width=
"60rpx"
height=
"60rpx"
v-if=
"userInfo.avatar_file&&userInfo.avatar_file.url"
:src=
"userInfo.avatar_file.url"
></cloud-image>
<image
class=
"userImg"
v-else
src=
"/static/uni-center/grey.png"
mode=
"widthFix"
/>
<input
class=
"input-box"
v-model=
"text"
:disabled=
"!hasLogin"
:placeholder=
"hasLogin?$t('guestbook.msgContent'):$t('guestbook.notAvailable')"
/>
<button
@
click=
"text?send():''"
class=
"btn"
:class=
"
{active:text}">
{{
$t
(
'
guestbook.send
'
)
}}
</button>
</view>
</view>
</
template
>
<
script
>
const
db
=
uniCloud
.
database
();
const
guestbookTable
=
db
.
collection
(
'
guestbook
'
)
import
{
mapMutations
,
mapGetters
}
from
'
vuex
'
;
export
default
{
computed
:
{
...
mapGetters
({
userInfo
:
'
user/info
'
,
hasLogin
:
'
user/hasLogin
'
}),
udbWhere
(){
if
(
this
.
hasLogin
){
if
(
this
.
uniIDHasRole
(
'
AUDITOR
'
)
){
return
''
}
else
{
return
'
state==true || user_id._id==$cloudEnv_uid
'
}
}
else
{
return
'
"state"==true
'
}
}
},
data
()
{
return
{
text
:
""
}
},
onLoad
()
{
uni
.
setNavigationBarTitle
({
title
:
this
.
$t
(
'
guestbook.navigationBarTitle
'
)
})
},
methods
:
{
setState
(
item
,
e
)
{
item
.
state
=
e
.
detail
.
value
console
.
log
(
item
,
e
);
this
.
$refs
.
udb
.
update
(
item
.
_id
,{
state
:
item
.
state
},{
needConfirm
:
false
,
toastTitle
:
this
.
$t
(
'
common
'
).
updateSucceeded
,
// toast提示语
success
:
(
res
)
=>
{
// 新增成功后的回调
let
{
code
,
message
}
=
res
console
.
log
(
code
,
message
);
},
fail
:
(
err
)
=>
{
// 新增失败后的回调
let
{
message
}
=
err
console
.
log
(
err
);
// 判断没有权限
uni
.
showToast
({
title
:
this
.
$t
(
'
guestbook.noPermission
'
),
icon
:
'
none
'
});
this
.
$nextTick
(()
=>
{
item
.
state
=
!
e
.
detail
.
value
})
},
complete
:
()
=>
{
// 完成后的回调
}
})
},
deleteItem
(
id
)
{
this
.
$refs
.
udb
.
remove
(
id
,
{
complete
:
e
=>
{
console
.
log
(
e
);
}
})
},
send
()
{
this
.
$refs
.
udb
.
add
({
text
:
this
.
text
},{
toastTitle
:
this
.
$t
(
'
guestbook.addSucceeded
'
),
// toast提示语
success
:
(
res
)
=>
{
// 新增成功后的回调
let
{
code
,
message
}
=
res
console
.
log
(
code
,
message
);
this
.
text
=
''
this
.
$refs
.
udb
.
refresh
()
//{clear:true}
},
fail
:
(
err
)
=>
{
// 新增失败后的回调
let
{
message
}
=
err
console
.
log
(
err
);
},
complete
:
()
=>
{
// 完成后的回调
}
})
},
...
mapMutations
({
logout
:
'
user/logout
'
}),
},
onNavigationBarButtonTap
(
e
)
{
console
.
log
(
e
);
if
(
e
.
index
){
this
.
logout
()
}
else
{
uni
.
navigateTo
({
url
:
"
/pages/ucenter/login-page/index/index
"
})
}
}
}
</
script
>
<
style
>
view
{
display
:
flex
;
flex-direction
:
column
;
box-sizing
:
border-box
;
}
.content
{
padding-bottom
:
110px
;
}
.item
{
flex-direction
:
row
;
justify-content
:
space-between
;
padding
:
10
rpx
;
width
:
730
rpx
;
margin-left
:
10
rpx
;
border-radius
:
10px
;
margin-top
:
10px
;
}
.item
.main
,
.item
.handle
{
flex-direction
:
row
;
align-items
:
center
;
}
.item
.main
text
{
padding
:
0
10
rpx
;
color
:
#666666
;
font-size
:
24
rpx
;
}
.item
.main
.nickname
{
font-weight
:
600
;
}
.item
.handle
switch
{
transform
:
scale
(
0.6
);
}
.submit-box
{
position
:
fixed
;
flex-direction
:
row
;
align-items
:
center
;
bottom
:
0
;
padding
:
20
rpx
15
rpx
;
width
:
750
rpx
;
border-top
:
solid
1px
#efecf2
;
background-color
:
#ffffff
;
height
:
56px
;
}
.userImg
{
width
:
60
rpx
;
height
:
60
rpx
;
border-radius
:
100px
;
background-color
:
#f0eef4
;
}
.submit-box
.input-box
{
background-color
:
#f8f8f8
;
padding
:
15
rpx
;
flex-grow
:
1
;
margin
:
20
rpx
;
border-radius
:
6px
;
font-size
:
24
rpx
;
}
.submit-box
.btn
{
height
:
30px
;
line-height
:
30px
;
font-size
:
24
rpx
;
width
:
80
rpx
;
padding
:
0
;
color
:
#888888
;
}
.submit-box
.btn
::after
{
display
:
none
;
}
.submit-box
.btn.active
{
background-color
:
#007aff
;
color
:
#FFFFFF
;
}
</
style
>
\ No newline at end of file
pages/ucenter/login-page/pwd-login/pwd-login.vue
浏览文件 @
e26e86ac
...
...
@@ -155,7 +155,7 @@
justify-content
:
flex-end
;
}
.captcha-img
{
margin
:
15px
15px
0
0
;
margin
:
0
15px
10px
0
;
width
:
250
rpx
;
}
.captcha
{
...
...
pages/ucenter/ucenter.vue
浏览文件 @
e26e86ac
...
...
@@ -113,10 +113,6 @@
// #endif
],
[{
"
title
"
:
this
.
$t
(
'
mine.guestBook
'
),
"
to
"
:
'
/pages/ucenter/guestbook/guestbook
'
,
"
icon
"
:
"
chat
"
},{
"
title
"
:
this
.
$t
(
'
mine.feedback
'
),
"
to
"
:
'
/uni_modules/uni-feedback/pages/opendb-feedback/opendb-feedback
'
,
"
icon
"
:
"
help
"
...
...
store/modules/user.js
浏览文件 @
e26e86ac
...
...
@@ -24,15 +24,22 @@ let state = {
console
.
log
(
'
state.info
'
,
state
.
info
);
//存储最新的用户数据到本地持久化存储
uni
.
setStorageSync
(
'
userInfo
'
,
state
.
info
);
uni
.
setStorageSync
(
'
uni_id_token
'
,
state
.
info
.
token
)
if
(
info
.
token
){
uni
.
setStorage
({
key
:
'
uni_id_token
'
,
data
:
state
.
info
.
token
,
complete
(
e
){
// console.log('setStorage-------',e);
}
});
uni
.
setStorageSync
(
'
uni_id_token_expired
'
,
state
.
info
.
tokenExpired
)
}
},
logout
(
state
)
{
state
.
info
=
{};
state
.
hasLogin
=
false
;
uni
.
setStorageSync
(
'
userInfo
'
,
{});
uni
.
setStorageSync
(
'
uni_id_token
'
,
'
'
);
uni
.
removeStorageSync
(
'
uni_id_token
'
);
uni
.
setStorageSync
(
'
uni_id_token_expired
'
,
0
)
}
},
...
...
uni-starter.config.js
浏览文件 @
e26e86ac
...
...
@@ -40,7 +40,6 @@ export default {
"
/pages/common/webview/webview
"
,
"
/pages/grid/grid
"
,
"
/pages/ucenter/ucenter
"
,
"
/pages/ucenter/guestbook/guestbook
"
,
"
/pages/ucenter/about/about
"
,
"
/pages/ucenter/settings/settings
"
],
...
...
uniCloud-aliyun/database/JQL数据库管理.jql
浏览文件 @
e26e86ac
...
...
@@ -9,4 +9,4 @@
// 详细JQL语法,请参考 https://uniapp.dcloud.net.cn/uniCloud/clientdb?id=jsquery
// 下面示例查询uni-id-users表的所有数据
db.collection('
guestbook,
uni-id-users').where('user_id._id=="610a6daa506cc7000100c07f"').get();
db.collection('uni-id-users').where('user_id._id=="610a6daa506cc7000100c07f"').get();
uniCloud-aliyun/database/guestbook.schema.json
已删除
100644 → 0
浏览文件 @
c26635f7
//
文档教程:
https://uniapp.dcloud.net.cn/uniCloud/schema
{
"bsonType"
:
"object"
,
"required"
:
[],
"permission"
:
{
"read"
:
"doc.state || auth.uid == doc.user_id || 'AUDITOR' in auth.role"
,
"create"
:
"auth.uid != null"
,
"update"
:
"'AUDITOR' in auth.role"
,
"delete"
:
"auth.uid == doc.user_id"
},
"properties"
:
{
"_id"
:
{
"description"
:
"ID,系统自动生成"
,
"permission"
:{
"write"
:
false
}
},
"text"
:
{
"bsonType"
:
"string"
,
"permission"
:{
"write"
:
false
}
},
"user_id"
:
{
"forceDefaultValue"
:
{
"$env"
:
"uid"
},
"foreignKey"
:
"uni-id-users._id"
,
"permission"
:{
"write"
:
false
}
},
"ip"
:
{
"forceDefaultValue"
:
{
"$env"
:
"clientIP"
},
"permission"
:{
"write"
:
false
}
},
"create_time"
:
{
"forceDefaultValue"
:
{
"$env"
:
"now"
},
"permission"
:{
"write"
:
false
}
},
"state"
:
{
"bsonType"
:
"bool"
,
"forceDefaultValue"
:
false
,
"permission"
:{
"write"
:
true
}
}
}
}
\ No newline at end of file
uni_modules/uni-config-center/uniCloud/cloudfunctions/common/uni-config-center/push/config.json
浏览文件 @
e26e86ac
{
"goEasy"
:
{
"commonKey"
:
"
BC-01f554db12604b46ae8373907e28794d
"
,
"clientKey"
:
"
PC-bfb6b6517e7f4c4f8b9285911fd3be27
"
,
"subscribeKey"
:
"
BS-ac71890d8612459bb4b22429cf406be3
"
,
"restKey"
:
"
PR-77f4630e731e4b5f8078aea77268cba4
"
,
"secretKey"
:
"
4bfeca3985504b3d
"
,
"restHost"
:
"
rest-hangzhou.goeasy.io
"
"commonKey"
:
""
,
"clientKey"
:
""
,
"subscribeKey"
:
""
,
"restKey"
:
""
,
"secretKey"
:
""
,
"restHost"
:
""
}
}
uni_modules/uni-config-center/uniCloud/cloudfunctions/common/uni-config-center/uni-push/config.json
0 → 100644
浏览文件 @
e26e86ac
{
"getui"
:
{
"appId"
:
"dCgnx0otCL8rjloSyynDu7"
,
"appkey"
:
"YGUYb5yPMN67rNyElDZv7A"
,
"appSecret"
:
"b0zAa92FrG6HT9Hsqk2CR8"
,
"mastersecret"
:
"nNXpI9MHkS8hZjdmQUD9H3"
,
"packageName"
:
"io.dcloud.hellouniapp"
}
}
uni_modules/uni-id-cf/changelog.md
浏览文件 @
e26e86ac
## 1.0.12(2022-01-24)
-
优化设备信息存储逻辑
-
新增刷新设备信息token有效期的API
`renewDeviceTokenExpired`
## 1.0.11(2022-01-19)
-
新增 getNeedCaptcha 接口
-
优化 调整 login 接口的代码结构
## 1.0.10(2022-01-08)
-
修复 限制只有 admin 用户可管理用户标签(不支持非 admin 用户操作managerMultiTag 接口)
## 1.0.9(2021-12-01)
...
...
@@ -17,8 +23,8 @@
## 1.0.3(2021-07-02)
-
框架设定非 admin 不能创建用户, 用户可自定义
## 1.0.2(2021-07-01)
1.
发送短信验证码api,默认注释掉:虚拟发送短信验证码的代码块。
2.
统一action名称为驼峰法
-
发送短信验证码api,默认注释掉:虚拟发送短信验证码的代码块。
-
统一action名称为驼峰法
## 1.0.1(2021-06-28)
修复resetPwdBySmsCode接口,未注册过的用户也能调用的问题
## 1.0.0(2021-06-21)
...
...
uni_modules/uni-id-cf/package.json
浏览文件 @
e26e86ac
{
"id"
:
"uni-id-cf"
,
"displayName"
:
"uni-id-cf"
,
"version"
:
"1.0.1
0
"
,
"version"
:
"1.0.1
2
"
,
"description"
:
"封装uni-id常用接口的云函数,快速实现简单、统一、可扩展的用户管理功能"
,
"keywords"
:
[
"uni-id-cf"
,
...
...
uni_modules/uni-id-cf/uniCloud/cloudfunctions/uni-id-cf/index.js
浏览文件 @
e26e86ac
...
...
@@ -8,7 +8,11 @@ const uniIdConfig = createConfig({
const
db
=
uniCloud
.
database
()
const
dbCmd
=
db
.
command
const
usersDB
=
db
.
collection
(
'
uni-id-users
'
)
const
deviceDB
=
db
.
collection
(
'
uni-id-device
'
)
exports
.
main
=
async
(
event
,
context
)
=>
{
console
.
log
({
context
});
//UNI_WYQ:这里的uniID换成新的,保证多人访问不会冲突
uniID
=
uniID
.
createInstance
({
context
...
...
@@ -26,11 +30,11 @@ exports.main = async (event, context) => {
inviteCode
}
=
event
;
const
deviceInfo
=
event
.
deviceInfo
||
{};
let
params
=
event
.
params
||
{};
let
params
=
event
.
params
||
{},
tokenExpired
;
/*
2.在某些操作之前我们要对用户对身份进行校验(也就是要检查用户的token)再将得到的uid写入params.uid
校验用到的方法是uniID.checkToken 详情:https://uniapp.dcloud.io/uniCloud/uni-id?id=checktoken
讨论,我们假设一个这样的场景,代码如下。
如:
uniCloud.callFunction({
...
...
@@ -44,9 +48,9 @@ exports.main = async (event, context) => {
用户就这样轻易地伪造了他人的uid传递给服务端,有一句话叫:前端传来的数据都是不可信任的
所以这里我们需要将uniID.checkToken返回的uid写入到params.uid
*/
let
noCheckAction
=
[
'
register
'
,
'
checkToken
'
,
'
login
'
,
'
logout
'
,
'
sendSmsCode
'
,
'
create
Captcha
'
,
'
verifyCaptcha
'
,
'
refreshCaptcha
'
,
'
inviteLogin
'
,
'
loginByWeixin
'
,
'
loginByUniverify
'
,
'
loginByApple
'
,
'
loginBySms
'
,
'
resetPwdBySmsCode
'
,
'
registerAdmin
'
let
noCheckAction
=
[
'
register
'
,
'
checkToken
'
,
'
login
'
,
'
logout
'
,
'
sendSmsCode
'
,
'
getNeed
Captcha
'
,
'
createCaptcha
'
,
'
verifyCaptcha
'
,
'
refreshCaptcha
'
,
'
inviteLogin
'
,
'
loginByWeixin
'
,
'
loginBy
Univerify
'
,
'
loginBy
Apple
'
,
'
loginBySms
'
,
'
resetPwdBySmsCode
'
,
'
registerAdmin
'
]
if
(
!
noCheckAction
.
includes
(
action
))
{
if
(
!
uniIdToken
)
{
...
...
@@ -60,6 +64,7 @@ exports.main = async (event, context) => {
return
payload
}
params
.
uid
=
payload
.
uid
tokenExpired
=
payload
.
tokenExpired
}
//禁止前台用户传递角色
...
...
@@ -73,7 +78,7 @@ exports.main = async (event, context) => {
}
// 3.注册成功后触发。
async
function
registerSuccess
(
uid
)
{
async
function
registerSuccess
(
res
)
{
//用户接受邀请
if
(
inviteCode
)
{
await
uniID
.
acceptInvite
({
...
...
@@ -82,18 +87,15 @@ exports.main = async (event, context) => {
});
}
//添加当前用户设备信息
await
db
.
collection
(
'
uni-id-device
'
).
add
({
...
deviceInfo
,
user_id
:
uid
})
await
addDeviceInfo
(
res
)
}
//4.记录成功登录的日志方法
const
loginLog
=
async
(
res
=
{})
=>
{
const
now
=
Date
.
now
()
const
uniIdLogCollection
=
db
.
collection
(
'
uni-id-log
'
)
let
logData
=
{
deviceId
:
params
.
deviceId
||
context
.
DEVICEID
,
ip
:
params
.
ip
||
context
.
CLIENTIP
,
deviceId
:
context
.
DEVICEID
,
ip
:
context
.
CLIENTIP
,
type
:
res
.
type
,
ua
:
context
.
CLIENTUA
,
create_date
:
now
...
...
@@ -106,17 +108,31 @@ exports.main = async (event, context) => {
delete
res
.
userInfo
.
password
}
if
(
res
.
type
==
'
register
'
)
{
await
registerSuccess
(
res
.
uid
)
await
registerSuccess
(
res
)
}
else
{
if
(
Object
.
keys
(
deviceInfo
).
length
)
{
// console.log(979797, {
// deviceInfo,
// user_id: res
// });
//更新当前用户设备信息
await
db
.
collection
(
'
uni-id-device
'
).
where
({
user_id
:
res
.
uid
}).
update
(
deviceInfo
)
console
.
log
(
context
.
DEVICEID
);
//避免重复新增设备信息,先判断是否已存在
let
getDeviceRes
=
await
deviceDB
.
where
({
device_id
:
context
.
DEVICEID
}).
get
()
if
(
getDeviceRes
.
data
.
length
==
0
)
{
await
addDeviceInfo
(
res
)
}
else
{
await
deviceDB
.
where
({
device_id
:
context
.
DEVICEID
,
}).
update
({
...
deviceInfo
,
tokenExpired
:
res
.
tokenExpired
,
"
user_id
"
:
res
.
uid
,
"
device_id
"
:
context
.
DEVICEID
,
"
ua
"
:
context
.
CLIENTUA
,
"
platform
"
:
context
.
PLATFORM
,
"
create_date
"
:
Date
.
now
(),
"
last_active_date
"
:
Date
.
now
(),
"
last_active_ip
"
:
context
.
CLIENTIP
})
}
}
}
}
else
{
...
...
@@ -125,8 +141,55 @@ exports.main = async (event, context) => {
return
await
uniIdLogCollection
.
add
(
logData
)
}
async
function
addDeviceInfo
({
uid
,
tokenExpired
})
{
return
await
deviceDB
.
add
({
...
deviceInfo
,
tokenExpired
,
"
user_id
"
:
uid
,
"
device_id
"
:
context
.
DEVICEID
,
"
ua
"
:
context
.
CLIENTUA
,
"
platform
"
:
context
.
PLATFORM
,
"
create_date
"
:
Date
.
now
(),
"
last_active_date
"
:
Date
.
now
(),
"
last_active_ip
"
:
context
.
CLIENTIP
})
}
//5.防止恶意破解登录,连续登录失败一定次数后,需要用户提供验证码
const
isNeedCaptcha
=
async
()
=>
{
//当用户最近“2小时内(recordDate)”登录失败达到2次(recordSize)时。要求用户提交验证码
const
now
=
Date
.
now
(),
recordDate
=
120
*
60
*
1000
,
recordSize
=
2
;
const
uniIdLogCollection
=
db
.
collection
(
'
uni-id-log
'
)
let
recentRecord
=
await
uniIdLogCollection
.
where
({
deviceId
:
params
.
deviceId
||
context
.
DEVICEID
,
create_date
:
dbCmd
.
gt
(
now
-
recordDate
),
type
:
'
login
'
})
.
orderBy
(
'
create_date
'
,
'
desc
'
)
.
limit
(
recordSize
)
.
get
();
return
recentRecord
.
data
.
filter
(
item
=>
item
.
state
===
0
).
length
===
recordSize
;
}
let
res
=
{}
switch
(
action
)
{
//根据action的值执行对应的操作
case
'
renewDeviceTokenExpired
'
:
let
aa
=
await
deviceDB
.
where
({
user_id
:
params
.
uid
,
"
device_id
"
:
context
.
DEVICEID
}).
update
({
user_id
:
params
.
uid
,
push_clientid
:
params
.
push_clientid
,
tokenExpired
})
console
.
log
(
aa
);
return
aa
break
;
case
'
refreshSessionKey
'
:
let
getSessionKey
=
await
uniID
.
code2SessionWeixin
({
code
:
params
.
code
...
...
@@ -221,30 +284,19 @@ exports.main = async (event, context) => {
inviteCode
});
if
(
res
.
code
===
0
)
{
await
registerSuccess
(
res
.
uid
)
await
registerSuccess
(
res
)
}
break
;
case
'
login
'
:
//防止黑客恶意破解登录,连续登录失败一定次数后,需要用户提供验证码
const
getNeedCaptcha
=
async
()
=>
{
//当用户最近“2小时内(recordDate)”登录失败达到2次(recordSize)时。要求用户提交验证码
const
now
=
Date
.
now
(),
recordDate
=
120
*
60
*
1000
,
recordSize
=
2
;
const
uniIdLogCollection
=
db
.
collection
(
'
uni-id-log
'
)
let
recentRecord
=
await
uniIdLogCollection
.
where
({
deviceId
:
params
.
deviceId
||
context
.
DEVICEID
,
create_date
:
dbCmd
.
gt
(
now
-
recordDate
),
type
:
'
login
'
})
.
orderBy
(
'
create_date
'
,
'
desc
'
)
.
limit
(
recordSize
)
.
get
();
return
recentRecord
.
data
.
filter
(
item
=>
item
.
state
===
0
).
length
===
recordSize
;
case
'
getNeedCaptcha
'
:
{
const
needCaptcha
=
await
isNeedCaptcha
()
res
.
needCaptcha
=
needCaptcha
break
;
}
case
'
login
'
:
let
passed
=
false
;
let
needCaptcha
=
await
get
NeedCaptcha
();
let
needCaptcha
=
await
is
NeedCaptcha
();
console
.
log
(
'
needCaptcha
'
,
needCaptcha
);
if
(
needCaptcha
)
{
res
=
await
uniCaptcha
.
verify
({
...
...
@@ -261,7 +313,7 @@ exports.main = async (event, context) => {
});
res
.
type
=
'
login
'
await
loginLog
(
res
);
needCaptcha
=
await
get
NeedCaptcha
();
needCaptcha
=
await
is
NeedCaptcha
();
}
res
.
needCaptcha
=
needCaptcha
;
...
...
uni_modules/uni-id/changelog.md
浏览文件 @
e26e86ac
## 3.3.12(2022-01-15)
-
新增 preferedAppPlatform 配置用于解决uni-app vue2版本vue3版本获取platform不一致的问题
[
详情
](
https://uniapp.dcloud.net.cn/uniCloud/uni-id?id=prefered-app-platform
)
-
修复 checkToken 未返回自定义token内容的Bug
## 3.3.11(2022-01-11)
-
修复用户名密码登录时多个应用出现重复用户名登录报错的Bug
## 3.3.10(2022-01-07)
...
...
uni_modules/uni-id/package.json
浏览文件 @
e26e86ac
{
"id"
:
"uni-id"
,
"displayName"
:
"uni-id"
,
"version"
:
"3.3.1
1
"
,
"version"
:
"3.3.1
2
"
,
"description"
:
"简单、统一、可扩展的用户中心"
,
"keywords"
:
[
"uniid"
,
...
...
uni_modules/uni-id/uniCloud/cloudfunctions/common/uni-id/index.js
浏览文件 @
e26e86ac
因为 它太大了无法显示 source diff 。你可以改为
查看blob
。
uni_modules/uni-id/uniCloud/cloudfunctions/common/uni-id/package.json
浏览文件 @
e26e86ac
{
"name"
:
"uni-id"
,
"version"
:
"3.3.1
1
"
,
"version"
:
"3.3.1
2
"
,
"description"
:
"uni-id for uniCloud"
,
"main"
:
"index.js"
,
"homepage"
:
"https://uniapp.dcloud.io/uniCloud/uni-id"
,
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录