Files
ClassContent/历届学生/学生公司项目/朱祥龙/hyGw/Interceptor/index.js
2024-09-27 02:06:13 +08:00

39 lines
1.0 KiB
JavaScript
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

var db = require("../db/index")
class Interceptor {
adminPageInterceptor(req, res, next) {
if (req.session.user == undefined) {
res.json({
status: 404,
message: '您还未登录, 请访问 /admin/login 登录'
})
} else {
next()
}
}
async adminInterceptor(req, res, next) {
if(req.headers.token != undefined) {
var data = await db.query({
sql: 'SELECT * from user where token = ?',
par: [req.headers.token]
});
if( data.length != 0) {
next()
} else {
res.json({
status: 500,
message: 'token已经失效请重新登录'
})
}
} else {
res.json({
status: 500,
message: '请勿非法访问接口缺少token'
})
}
}
}
module.exports = new Interceptor()