Archived
1
0
Fork 0
This repository has been archived on 2024-02-17. You can view files and clone it, but cannot push or open issues or pull requests.
SOD/routes/profile.js

35 lines
1.2 KiB
JavaScript
Raw Normal View History

2020-08-17 17:58:55 +02:00
let express = require("express");
let router = express.Router();
let sessionCheck = require("../middlewares/sessionCheck");
let models = require("../models");
2020-08-20 14:50:59 +02:00
let userUpdate = require("./utils/userUpdate");
2020-08-25 15:40:06 +02:00
let emailCheck = require("./utils/emailCheck");
let error = require("./utils/error");
2020-08-17 17:58:55 +02:00
router.get("/", sessionCheck(0), async (req, res) => {
res.render("profile", {
2020-08-17 19:13:00 +02:00
title: "SOD - Profile",
2020-08-17 17:58:55 +02:00
departments: await models.Department.findAll(),
2020-08-18 17:54:00 +02:00
orders: await models.Order.findAll({
2020-08-17 17:58:55 +02:00
where: {UserUsername: req.session.user.username},
include: models.Sandwich,
order: ["date"]
})
});
}).post("/", sessionCheck(0), async (req, res) => {
let user = await models.User.findByPk(req.session.user.username);
2020-08-20 14:50:59 +02:00
user = await userUpdate(req, res, user);
if (user) {
req.session.user = user;
res.redirect("/profile");
}
2020-08-25 15:40:06 +02:00
}).get("/resend", sessionCheck(0), async (req, res) => {
if (!req.session.user.emailVerified)
await emailCheck(req, res, await models.User.findByPk(req.session.user.username), () => res.redirect("/profile"));
else
return error(req, res, "Can't' resend email", 400, "Email already verified");
2020-08-17 17:58:55 +02:00
});
module.exports = router;