mirror of
https://github.com/dec0dOS/zero-ui.git
synced 2025-02-24 15:35:24 +08:00
23 lines
572 B
JavaScript
23 lines
572 B
JavaScript
|
const express = require("express");
|
||
|
const router = express.Router();
|
||
|
|
||
|
const auth = require("../services/auth");
|
||
|
|
||
|
router.post("/login", async function (req, res) {
|
||
|
if (req.body.username && req.body.password) {
|
||
|
auth.authorize(req.body.username, req.body.password, function (err, user) {
|
||
|
if (user) {
|
||
|
res.send({ token: user["token"] });
|
||
|
} else {
|
||
|
res.status(401).send({
|
||
|
error: err.message,
|
||
|
});
|
||
|
}
|
||
|
});
|
||
|
} else {
|
||
|
res.status(400).send({ error: "Specify username and password" });
|
||
|
}
|
||
|
});
|
||
|
|
||
|
module.exports = router;
|