zie vorige message
This commit is contained in:
@@ -22,6 +22,7 @@ class AuthController {
|
||||
const name = (req.body.name || "").trim();
|
||||
const email = (req.body.email || "").trim().toLowerCase();
|
||||
const password = req.body.password || "";
|
||||
const inviteCode = (req.body.household_code || "").trim();
|
||||
|
||||
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.");
|
||||
@@ -45,6 +46,15 @@ class AuthController {
|
||||
|
||||
}
|
||||
|
||||
const invitedHousehold = inviteCode
|
||||
? HouseholdService.findByInviteCode(inviteCode)
|
||||
: null;
|
||||
|
||||
if (inviteCode && !invitedHousehold) {
|
||||
req.flash("error", "De huishoudcode bestaat niet.");
|
||||
return res.redirect("/register");
|
||||
}
|
||||
|
||||
|
||||
const passwordHash = await bcrypt.hash(
|
||||
password,
|
||||
@@ -73,10 +83,14 @@ class AuthController {
|
||||
const userId = result.lastInsertRowid;
|
||||
|
||||
|
||||
HouseholdService.createForUser(
|
||||
userId,
|
||||
`${name} huishouden`
|
||||
);
|
||||
if (invitedHousehold) {
|
||||
HouseholdService.addMember(invitedHousehold.id, userId);
|
||||
} else {
|
||||
HouseholdService.createForUser(
|
||||
userId,
|
||||
`${name} huishouden`
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
req.session.userId = userId;
|
||||
|
||||
Reference in New Issue
Block a user