tskredens/src/routes/auth.ts

37 lines
1.2 KiB
TypeScript
Raw Normal View History

2019-09-26 15:52:58 +02:00
// Copyright (C) 2019 ModZero <modzero@modzero.xyz>
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU Affero General Public License as
// published by the Free Software Foundation, either version 3 of the
// License, or (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU Affero General Public License for more details.
//
// You should have received a copy of the GNU Affero General Public License
// along with this program. If not, see <http://www.gnu.org/licenses/>.
2019-09-26 20:19:57 +02:00
import { db } from "@kredens/db";
2019-09-26 15:52:58 +02:00
import express from "express";
const router = express.Router();
2019-10-07 01:46:38 +02:00
router.get("/", async (req, res, next) => {
res.render("login", {
csrfToken: req.csrfToken()
});
});
2019-09-26 15:52:58 +02:00
router.post("/", async (req, res, next) => {
const userID = await db.users.login(req.body.email, req.body.password);
if (userID.isSome()) {
res.send(`Hi, ${userID.some()}`);
} else {
res.send(`Go away.`);
}
});
export default router;