36 lines
862 B
JavaScript
36 lines
862 B
JavaScript
|
import express from "express";
|
||
|
import { ensureLoggedIn } from "connect-ensure-login";
|
||
|
|
||
|
import Me from "../middleware/Me";
|
||
|
|
||
|
import render from "../libs/format";
|
||
|
|
||
|
// eslint-disable-next-line new-cap
|
||
|
const router = express.Router();
|
||
|
|
||
|
router
|
||
|
.route("/")
|
||
|
.get(ensureLoggedIn("/connexion"), async (req, res, next) => {
|
||
|
try {
|
||
|
const page = new Me(req, "mon-compte/index");
|
||
|
|
||
|
page.setPageTitle("Mon compte");
|
||
|
|
||
|
render(res, page);
|
||
|
} catch (err) {
|
||
|
next(err);
|
||
|
}
|
||
|
})
|
||
|
.post(ensureLoggedIn("/connexion"), async (req, res) => {
|
||
|
try {
|
||
|
const page = new Me(req, "mon-compte/index");
|
||
|
|
||
|
await page.updatePassword();
|
||
|
} catch (err) {
|
||
|
req.flash("error", err.toString());
|
||
|
}
|
||
|
res.redirect("/mon-compte");
|
||
|
});
|
||
|
|
||
|
export default router;
|