Werk hoofdapplicatie bij
Legt de bestaande wijzigingen in de hoofdworktree vast voordat de laatste worktree wordt gemerged.\n\nCo-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
This commit is contained in:
@@ -10,20 +10,23 @@ class AuthController {
|
||||
|
||||
registerForm(req, res) {
|
||||
|
||||
res.render("auth/register", {
|
||||
title: "Registreren"
|
||||
});
|
||||
res.locals.title = "Registreren";
|
||||
|
||||
res.render("auth/register");
|
||||
|
||||
}
|
||||
|
||||
|
||||
async register(req, res) {
|
||||
|
||||
const {
|
||||
name,
|
||||
email,
|
||||
password
|
||||
} = req.body;
|
||||
const name = (req.body.name || "").trim();
|
||||
const email = (req.body.email || "").trim().toLowerCase();
|
||||
const password = req.body.password || "";
|
||||
|
||||
if (name.length < 2 || !/^\S+@\S+\.\S+$/.test(email) || password.length < 8) {
|
||||
req.flash("error", "Vul een naam, geldig e-mailadres en een wachtwoord van minimaal 8 tekens in.");
|
||||
return res.redirect("/register");
|
||||
}
|
||||
|
||||
|
||||
const existingUser = db.prepare(
|
||||
@@ -67,7 +70,7 @@ class AuthController {
|
||||
);
|
||||
|
||||
|
||||
const userId = result.lastInsertRowid;
|
||||
const userId = result.lastInsertRowid;
|
||||
|
||||
|
||||
HouseholdService.createForUser(
|
||||
@@ -78,6 +81,10 @@ class AuthController {
|
||||
|
||||
req.session.userId = userId;
|
||||
|
||||
req.flash(
|
||||
"success",
|
||||
"Welkom bij PantryHub!"
|
||||
);
|
||||
|
||||
res.redirect("/");
|
||||
|
||||
@@ -87,9 +94,18 @@ class AuthController {
|
||||
|
||||
loginForm(req, res) {
|
||||
|
||||
res.render("auth/login", {
|
||||
title: "Inloggen"
|
||||
});
|
||||
res.locals.title = "Inloggen";
|
||||
|
||||
if (req.query.logout) {
|
||||
|
||||
req.flash(
|
||||
"info",
|
||||
"Je bent uitgelogd."
|
||||
);
|
||||
|
||||
}
|
||||
|
||||
res.render("auth/login");
|
||||
|
||||
}
|
||||
|
||||
@@ -97,10 +113,8 @@ class AuthController {
|
||||
|
||||
async login(req, res) {
|
||||
|
||||
const {
|
||||
email,
|
||||
password
|
||||
} = req.body;
|
||||
const email = (req.body.email || "").trim().toLowerCase();
|
||||
const password = req.body.password || "";
|
||||
|
||||
|
||||
const user = db.prepare(
|
||||
@@ -141,6 +155,10 @@ class AuthController {
|
||||
|
||||
req.session.userId = user.id;
|
||||
|
||||
req.flash(
|
||||
"success",
|
||||
`Welkom terug ${user.name}!`
|
||||
);
|
||||
|
||||
res.redirect("/");
|
||||
|
||||
@@ -152,7 +170,9 @@ class AuthController {
|
||||
|
||||
req.session.destroy(() => {
|
||||
|
||||
res.redirect("/login");
|
||||
res.clearCookie("connect.sid");
|
||||
|
||||
res.redirect("/login?logout=1");
|
||||
|
||||
});
|
||||
|
||||
@@ -162,4 +182,4 @@ class AuthController {
|
||||
}
|
||||
|
||||
|
||||
module.exports = new AuthController();
|
||||
module.exports = new AuthController();
|
||||
|
||||
Reference in New Issue
Block a user