Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
W
wenHuaBu_adminServer
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
node_server
wenHuaBu_adminServer
Commits
ba6e1fdf
Commit
ba6e1fdf
authored
Mar 21, 2024
by
lixinming
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
no message
parent
9af33140
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
65 additions
and
66 deletions
+65
-66
user.ts
src/biz/member/user.ts
+2
-1
user.ts
src/middleware/user.ts
+19
-14
router.ts
src/routers/member/router.ts
+2
-4
router.ts
src/routers/router.ts
+42
-47
No files found.
src/biz/member/user.ts
View file @
ba6e1fdf
...
@@ -33,7 +33,8 @@ export async function login({loginStr, pwd}) {
...
@@ -33,7 +33,8 @@ export async function login({loginStr, pwd}) {
isAdmin
:
userInfo
.
isAdmin
==
STATE
.
是
,
isAdmin
:
userInfo
.
isAdmin
==
STATE
.
是
,
name
:
userInfo
.
name
,
name
:
userInfo
.
name
,
userId
:
userInfo
.
userId
,
userId
:
userInfo
.
userId
,
token
:
token
token
:
token
,
adminLv
:
userInfo
.
adminLv
};
};
return
{
dataInfo
}
return
{
dataInfo
}
...
...
src/middleware/user.ts
View file @
ba6e1fdf
import
{
nextTick
}
from
"process"
;
import
{
ERRORENUM
}
from
"../config/errorEnum"
;
import
{
ERRORENUM
}
from
"../config/errorEnum"
;
import
{
TABLEENUM
}
from
"../data/models/model"
;
import
{
TABLEENUM
}
from
"../data/models/model"
;
import
{
findOnce
}
from
"../data/select"
;
import
{
findOnce
}
from
"../data/select"
;
...
@@ -18,30 +19,34 @@ export async function checkUser(req, res, next) {
...
@@ -18,30 +19,34 @@ export async function checkUser(req, res, next) {
const
reqToken
=
req
.
headers
.
token
;
const
reqToken
=
req
.
headers
.
token
;
const
userId
=
req
.
headers
.
userid
||
""
;
const
userId
=
req
.
headers
.
userid
||
""
;
if
(
!
reqToken
||
!
userId
)
return
next
(
new
BizError
(
ERRORENUM
.
身份验证失败
,
`userId:
${
userId
}
token:
${
reqToken
}
`
));
//
if (!reqToken || !userId ) return next(new BizError(ERRORENUM.身份验证失败, `userId:${userId} token:${reqToken}`));
let
userInfo
=
await
findOnce
(
TABLEENUM
.
用户表
,
{
userId
});
//
let userInfo = await findOnce(TABLEENUM.用户表, {userId});
if
(
!
userInfo
||
!
userInfo
.
userId
)
return
next
(
new
BizError
(
ERRORENUM
.
身份验证失败
));
//
if (!userInfo || !userInfo.userId) return next(new BizError(ERRORENUM.身份验证失败));
if
(
userInfo
.
token
!=
reqToken
)
return
next
(
new
BizError
(
ERRORENUM
.
身份验证过期
));
//
if (userInfo.token != reqToken) return next(new BizError(ERRORENUM.身份验证过期));
let
checkToken
=
''
;
//
let checkToken = '';
//30分钟更新token
//
//
30分钟更新token
if
(
(
userInfo
.
tokenMs
-
new
Date
().
valueOf
())
>=
(
30
*
60
*
1000
)
)
{
//
if ( (userInfo.tokenMs - new Date().valueOf()) >= (30 * 60 * 1000) ) {
return
next
(
new
BizError
(
ERRORENUM
.
身份验证过期
));
//
return next(new BizError(ERRORENUM.身份验证过期));
}
else
{
//
} else {
checkToken
=
reqToken
;
//
checkToken = reqToken;
await
updateOneData
(
TABLEENUM
.
用户表
,
{
userId
:
userInfo
.
userId
},
{
tokenMs
:
new
Date
().
valueOf
()});
//
await updateOneData(TABLEENUM.用户表, {userId:userInfo.userId}, { tokenMs:new Date().valueOf()});
}
//
}
req
.
headers
.
userId
=
userId
;
req
.
headers
.
userId
=
userId
;
req
.
headers
.
userInfo
=
{
req
.
headers
.
userInfo
=
{
userId
,
userId
,
isAdmin
:
userInfo
.
isAdmin
//
isAdmin:userInfo.isAdmin
}
}
next
();
next
();
}
}
export
async
function
notCheck
(
req
,
res
,
next
)
{
next
();
}
/**
/**
* 中间件 数据维护接口
* 中间件 数据维护接口
...
...
src/routers/member/router.ts
View file @
ba6e1fdf
...
@@ -174,7 +174,7 @@ export const Config = {
...
@@ -174,7 +174,7 @@ export const Config = {
subUrl
:
'/login'
,
subUrl
:
'/login'
,
notMiddleware
:
true
,
notMiddleware
:
true
,
param
:[
param
:[
{
key
:
"lo
l
ginId"
,
type
:
"String"
,
desc
:
"账号"
},
{
key
:
"loginId"
,
type
:
"String"
,
desc
:
"账号"
},
{
key
:
"pwd"
,
type
:
"String"
,
desc
:
"密码"
}
{
key
:
"pwd"
,
type
:
"String"
,
desc
:
"密码"
}
],
],
bindBiz
:
userBiz
.
login
bindBiz
:
userBiz
.
login
...
@@ -630,9 +630,7 @@ export const Config = {
...
@@ -630,9 +630,7 @@ export const Config = {
{
{
apiName
:
"会员信息展示"
,
apiName
:
"会员信息展示"
,
subUrl
:
'/homepage/list'
,
subUrl
:
'/homepage/list'
,
param
:[
param
:[],
{
key
:
"userId"
,
type
:
"String"
,
desc
:
"用户id"
}
],
bindBiz
:
homePageBiz
.
getMemberData
bindBiz
:
homePageBiz
.
getMemberData
},
},
{
{
...
...
src/routers/router.ts
View file @
ba6e1fdf
...
@@ -16,7 +16,7 @@ import * as officalWebsiteRouter from "./officalWebsite/router";
...
@@ -16,7 +16,7 @@ import * as officalWebsiteRouter from "./officalWebsite/router";
import
*
as
orderRouter
from
"./order/router"
;
import
*
as
orderRouter
from
"./order/router"
;
import
*
as
asyncHandler
from
'express-async-handler'
;
import
*
as
asyncHandler
from
'express-async-handler'
;
import
{
payCallback
}
from
"../biz/member/cost"
;
import
{
payCallback
}
from
"../biz/member/cost"
;
import
{
checkUser
}
from
"../middleware/user"
;
import
{
checkUser
,
notCheck
}
from
"../middleware/user"
;
const
Look
=
false
;
//true更新文档
const
Look
=
false
;
//true更新文档
...
@@ -30,9 +30,9 @@ export async function setRouter(httpServer){
...
@@ -30,9 +30,9 @@ export async function setRouter(httpServer){
await
initDoc
(
orderRouter
.
FirstName
,
orderRouter
.
Config
,
orderRouter
.
FirstRouter
);
//会费相关
await
initDoc
(
orderRouter
.
FirstName
,
orderRouter
.
Config
,
orderRouter
.
FirstRouter
);
//会费相关
await
initDoc
(
costRouter
.
FirstName
,
costRouter
.
Config
,
costRouter
.
FirstRouter
);
//支付
await
initDoc
(
costRouter
.
FirstName
,
costRouter
.
Config
,
costRouter
.
FirstRouter
);
//支付
}
}
await
analysisRouter
(
httpServer
,
portalRouter
.
Config
,
portalRouter
.
FirstRouter
,
tru
e
);
//网站编辑
await
analysisRouter
(
httpServer
,
portalRouter
.
Config
,
portalRouter
.
FirstRouter
,
fals
e
);
//网站编辑
await
analysisRouter
(
httpServer
,
publicRouter
.
Config
,
publicRouter
.
FirstRouter
,
false
);
//公用组件
await
analysisRouter
(
httpServer
,
publicRouter
.
Config
,
publicRouter
.
FirstRouter
,
false
);
//公用组件
await
analysisRouter
(
httpServer
,
memberRouter
.
Config
,
memberRouter
.
FirstRouter
,
fals
e
);
//用户路由
await
analysisRouter
(
httpServer
,
memberRouter
.
Config
,
memberRouter
.
FirstRouter
,
tru
e
);
//用户路由
await
analysisRouter
(
httpServer
,
officalWebsiteRouter
.
Config
,
officalWebsiteRouter
.
FirstRouter
,
false
);
//官网路由
await
analysisRouter
(
httpServer
,
officalWebsiteRouter
.
Config
,
officalWebsiteRouter
.
FirstRouter
,
false
);
//官网路由
await
analysisRouter
(
httpServer
,
orderRouter
.
Config
,
orderRouter
.
FirstRouter
,
true
);
//会费相关
await
analysisRouter
(
httpServer
,
orderRouter
.
Config
,
orderRouter
.
FirstRouter
,
true
);
//会费相关
await
analysisRouter
(
httpServer
,
costRouter
.
Config
,
costRouter
.
FirstRouter
,
true
);
//支付
await
analysisRouter
(
httpServer
,
costRouter
.
Config
,
costRouter
.
FirstRouter
,
true
);
//支付
...
@@ -42,55 +42,50 @@ async function analysisRouter(httpServer, config, firstRouter, haveMiddleware) {
...
@@ -42,55 +42,50 @@ async function analysisRouter(httpServer, config, firstRouter, haveMiddleware) {
for
(
let
modelKey
in
config
)
{
for
(
let
modelKey
in
config
)
{
config
[
modelKey
].
forEach
(
info
=>
{
config
[
modelKey
].
forEach
(
info
=>
{
let
{
apiName
,
defaultParam
,
subUrl
,
param
,
bindBiz
,
notMiddleware
}
=
info
;
let
{
apiName
,
defaultParam
,
subUrl
,
param
,
bindBiz
,
notMiddleware
}
=
info
;
if
(
haveMiddleware
)
{
httpServer
.
post
(
firstRouter
+
subUrl
,
haveMiddleware
?
checkUser
:
notCheck
,
async
function
(
req
,
res
)
{
if
(
notMiddleware
)
{
let
chackObjectList
=
[];
httpServer
.
post
(
firstRouter
+
subUrl
,
allRouter
(
apiName
,
defaultParam
,
subUrl
,
param
,
bindBiz
));
let
checkStringMap
=
{};
}
else
httpServer
.
post
(
firstRouter
+
subUrl
,
checkUser
,
allRouter
(
apiName
,
defaultParam
,
subUrl
,
param
,
bindBiz
));
let
stringNotMustHaveKeys
=
[];
}
else
httpServer
.
post
(
firstRouter
+
subUrl
,
allRouter
(
apiName
,
defaultParam
,
subUrl
,
param
,
bindBiz
));
let
funcParam
:
any
=
{};
funcParam
.
userId
=
req
.
headers
.
userId
;
for
(
let
i
=
0
;
i
<
param
.
length
;
i
++
)
{
let
info
:
any
=
param
[
i
];
let
{
key
,
type
}
=
param
[
i
];
if
(
info
.
isNull
)
stringNotMustHaveKeys
.
push
(
key
);
if
(
type
==
'Object'
)
{
chackObjectList
.
push
(
param
[
i
]);
checkStringMap
[
key
]
=
type
;
}
else
checkStringMap
[
key
]
=
type
;
}
/**校验参数 */
if
(
chackObjectList
.
length
)
{
chackObjectList
.
forEach
(
item
=>
{
if
(
!
req
.
body
[
item
.
key
])
throw
new
BizError
(
ERRORENUM
.
参数错误
,
`缺少参数
${
item
.
key
}
`
);
eccFormParam
(
apiName
,
item
.
sub
,
req
.
body
[
item
.
key
]);
funcParam
[
item
.
key
]
=
req
.
body
[
item
.
key
];
});
}
if
(
Object
.
keys
(
checkStringMap
).
length
)
{
let
eccResult
=
eccReqParamater
(
apiName
,
checkStringMap
,
req
.
body
,
stringNotMustHaveKeys
);
for
(
let
key
in
eccResult
)
{
funcParam
[
key
]
=
eccResult
[
key
];
}
}
if
(
defaultParam
)
funcParam
[
"defaultParam"
]
=
defaultParam
;
let
result
=
await
bindBiz
(
funcParam
);
res
.
success
(
result
);
});
});
});
}
}
}
}
function
allRouter
(
apiName
,
defaultParam
,
subUrl
,
param
,
bindBiz
)
{
async
function
allRouter
(
apiName
,
defaultParam
,
subUrl
,
param
,
bindBiz
)
{
return
async
function
(
req
,
res
)
{
let
chackObjectList
=
[];
let
checkStringMap
=
{};
let
stringNotMustHaveKeys
=
[];
let
funcParam
:
any
=
{};
funcParam
.
userId
=
req
.
headers
.
userId
;
for
(
let
i
=
0
;
i
<
param
.
length
;
i
++
)
{
let
info
:
any
=
param
[
i
];
let
{
key
,
type
}
=
param
[
i
];
if
(
info
.
isNull
)
stringNotMustHaveKeys
.
push
(
key
);
if
(
type
==
'Object'
)
{
chackObjectList
.
push
(
param
[
i
]);
checkStringMap
[
key
]
=
type
;
}
else
checkStringMap
[
key
]
=
type
;
}
/**校验参数 */
if
(
chackObjectList
.
length
)
{
chackObjectList
.
forEach
(
item
=>
{
if
(
!
req
.
body
[
item
.
key
])
throw
new
BizError
(
ERRORENUM
.
参数错误
,
`缺少参数
${
item
.
key
}
`
);
eccFormParam
(
apiName
,
item
.
sub
,
req
.
body
[
item
.
key
]);
funcParam
[
item
.
key
]
=
req
.
body
[
item
.
key
];
});
}
if
(
Object
.
keys
(
checkStringMap
).
length
)
{
let
eccResult
=
eccReqParamater
(
apiName
,
checkStringMap
,
req
.
body
,
stringNotMustHaveKeys
);
for
(
let
key
in
eccResult
)
{
funcParam
[
key
]
=
eccResult
[
key
];
}
}
if
(
defaultParam
)
funcParam
[
"defaultParam"
]
=
defaultParam
;
let
result
=
await
bindBiz
(
funcParam
);
res
.
success
(
result
);
}
}
}
export
async
function
setAdditionalRouter
(
httpServer
)
{
export
async
function
setAdditionalRouter
(
httpServer
)
{
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment