更新政府端和银行端
This commit is contained in:
29
government-backend/controllers/authController.js
Normal file
29
government-backend/controllers/authController.js
Normal file
@@ -0,0 +1,29 @@
|
||||
const jwt = require('jsonwebtoken')
|
||||
const { JWT_SECRET } = require('../config')
|
||||
|
||||
exports.login = async (req, res) => {
|
||||
try {
|
||||
const { username, password } = req.body
|
||||
|
||||
// 临时模拟登录验证
|
||||
if (username === 'admin' && password === '123456') {
|
||||
const token = jwt.sign({ username }, JWT_SECRET, { expiresIn: '2h' })
|
||||
return res.json({
|
||||
code: 200,
|
||||
message: '登录成功',
|
||||
data: { token }
|
||||
})
|
||||
}
|
||||
|
||||
res.status(401).json({
|
||||
code: 401,
|
||||
message: '用户名或密码错误'
|
||||
})
|
||||
} catch (err) {
|
||||
res.status(500).json({
|
||||
code: 500,
|
||||
message: '服务器错误',
|
||||
error: err.message
|
||||
})
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user