Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
DCloud
hello_uni-id-pages
提交
c99d592c
H
hello_uni-id-pages
项目概览
DCloud
/
hello_uni-id-pages
通知
1051
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看板
体验新版 GitCode,发现更多精彩内容 >>
提交
c99d592c
编写于
8月 29, 2022
作者:
雪洛
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
feat: auto logout while login, register with token
上级
ce3348ac
变更
4
隐藏空白更改
内联
并排
Showing
4 changed file
with
81 addition
and
43 deletion
+81
-43
uni_modules/uni-id-pages/uniCloud/cloudfunctions/uni-id-co/lib/utils/login.js
...ages/uniCloud/cloudfunctions/uni-id-co/lib/utils/login.js
+15
-1
uni_modules/uni-id-pages/uniCloud/cloudfunctions/uni-id-co/lib/utils/logout.js
...ges/uniCloud/cloudfunctions/uni-id-co/lib/utils/logout.js
+47
-0
uni_modules/uni-id-pages/uniCloud/cloudfunctions/uni-id-co/lib/utils/register.js
...s/uniCloud/cloudfunctions/uni-id-co/lib/utils/register.js
+16
-6
uni_modules/uni-id-pages/uniCloud/cloudfunctions/uni-id-co/module/logout/logout.js
...uniCloud/cloudfunctions/uni-id-co/module/logout/logout.js
+3
-36
未找到文件。
uni_modules/uni-id-pages/uniCloud/cloudfunctions/uni-id-co/lib/utils/login.js
浏览文件 @
c99d592c
...
...
@@ -8,6 +8,9 @@ const {
const
{
ERROR
}
=
require
(
'
../../common/error
'
)
const
{
logout
}
=
require
(
'
./logout
'
)
const
PasswordUtils
=
require
(
'
./password
'
)
async
function
realPreLogin
(
params
=
{})
{
...
...
@@ -173,10 +176,14 @@ async function postLogin (params = {}) {
extraData
,
isThirdParty
=
false
}
=
params
const
{
clientIP
,
uniIdToken
}
=
this
.
getClientInfo
()
const
uid
=
user
.
_id
const
updateData
=
{
last_login_date
:
Date
.
now
(),
last_login_ip
:
this
.
getClientInfo
().
clientIP
,
last_login_ip
:
clientIP
,
...
extraData
}
const
{
...
...
@@ -185,6 +192,13 @@ async function postLogin (params = {}) {
}
=
await
this
.
uniIdCommon
.
createToken
({
uid
})
if
(
uniIdToken
)
{
try
{
await
logout
.
call
(
this
)
}
catch
(
error
)
{}
}
await
userCollection
.
doc
(
uid
).
update
(
updateData
)
await
this
.
middleware
.
uniIdLog
({
data
:
{
...
...
uni_modules/uni-id-pages/uniCloud/cloudfunctions/uni-id-co/lib/utils/logout.js
0 → 100644
浏览文件 @
c99d592c
const
{
dbCmd
,
LOG_TYPE
,
deviceCollection
,
userCollection
}
=
require
(
'
../../common/constants
'
)
async
function
logout
()
{
const
{
uniIdToken
,
deviceId
}
=
this
.
getClientInfo
()
const
{
uid
}
=
await
this
.
uniIdCommon
.
checkToken
(
uniIdToken
,
{
autoRefresh
:
false
}
)
// 删除token
await
userCollection
.
doc
(
uid
).
update
({
token
:
dbCmd
.
pull
(
uniIdToken
)
})
// 仅当device表的device_id和user_id均对应时才进行更新
await
deviceCollection
.
where
({
device_id
:
deviceId
,
user_id
:
uid
}).
update
({
token_expired
:
0
})
await
this
.
middleware
.
uniIdLog
({
data
:
{
user_id
:
uid
},
type
:
LOG_TYPE
.
LOGOUT
})
return
{
errCode
:
0
}
}
module
.
exports
=
{
logout
}
\ No newline at end of file
uni_modules/uni-id-pages/uniCloud/cloudfunctions/uni-id-co/lib/utils/register.js
浏览文件 @
c99d592c
...
...
@@ -12,10 +12,13 @@ const {
getValidInviteCode
,
generateInviteInfo
}
=
require
(
'
./fission
'
)
const
{
logout
}
=
require
(
'
./logout
'
)
const
PasswordUtils
=
require
(
'
./password
'
)
const
merge
=
require
(
'
lodash.merge
'
)
async
function
realPreRegister
(
params
=
{})
{
async
function
realPreRegister
(
params
=
{})
{
const
{
user
}
=
params
...
...
@@ -30,7 +33,7 @@ async function realPreRegister (params = {}) {
}
}
async
function
preRegister
(
params
=
{})
{
async
function
preRegister
(
params
=
{})
{
try
{
await
realPreRegister
.
call
(
this
,
params
)
}
catch
(
error
)
{
...
...
@@ -42,7 +45,7 @@ async function preRegister (params = {}) {
}
}
async
function
preRegisterWithPassword
(
params
=
{})
{
async
function
preRegisterWithPassword
(
params
=
{})
{
const
{
user
,
password
...
...
@@ -69,7 +72,7 @@ async function preRegisterWithPassword (params = {}) {
}
}
async
function
thirdPartyRegister
({
async
function
thirdPartyRegister
({
user
=
{}
}
=
{})
{
return
{
...
...
@@ -78,7 +81,7 @@ async function thirdPartyRegister ({
}
}
async
function
postRegister
(
params
=
{})
{
async
function
postRegister
(
params
=
{})
{
const
{
user
,
extraData
=
{},
...
...
@@ -93,7 +96,8 @@ async function postRegister (params = {}) {
channel
,
scene
,
clientIP
,
osName
osName
,
uniIdToken
}
=
this
.
getClientInfo
()
merge
(
user
,
extraData
)
...
...
@@ -147,6 +151,12 @@ async function postRegister (params = {}) {
user
.
invite_time
=
inviteTime
}
if
(
uniIdToken
)
{
try
{
await
logout
.
call
(
this
)
}
catch
(
error
)
{}
}
const
beforeRegister
=
this
.
hooks
.
beforeRegister
let
userRecord
=
user
if
(
beforeRegister
)
{
...
...
uni_modules/uni-id-pages/uniCloud/cloudfunctions/uni-id-co/module/logout/logout.js
浏览文件 @
c99d592c
const
{
dbCmd
,
LOG_TYPE
,
deviceCollection
,
userCollection
}
=
require
(
'
../../common/constants
'
)
logout
}
=
require
(
'
../../lib/utils/logout
'
)
/**
* 用户退出登录
...
...
@@ -11,37 +8,7 @@ const {
* @returns
*/
module
.
exports
=
async
function
()
{
const
{
uniIdToken
,
deviceId
}
=
this
.
getClientInfo
()
const
{
uid
}
=
await
this
.
uniIdCommon
.
checkToken
(
uniIdToken
,
{
autoRefresh
:
false
}
)
// 删除token
await
userCollection
.
doc
(
uid
).
update
({
token
:
dbCmd
.
pull
(
uniIdToken
)
})
// 仅当device表的device_id和user_id均对应时才进行更新
await
deviceCollection
.
where
({
device_id
:
deviceId
,
user_id
:
uid
}).
update
({
token_expired
:
0
})
await
this
.
middleware
.
uniIdLog
({
data
:
{
user_id
:
uid
},
type
:
LOG_TYPE
.
LOGOUT
})
await
logout
.
call
(
this
)
return
{
errCode
:
0
}
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录