config: require account verification

This commit is contained in:
Puyodead1 2023-01-30 19:05:22 -05:00 committed by Puyodead1
parent 97bafa81fc
commit 34cde14f75
3 changed files with 14 additions and 6 deletions

View File

@ -102,6 +102,17 @@ router.post(
});
}
// return an error for unverified accounts if verification is required
if (config.login.requireVerification && !user.verified) {
throw FieldErrors({
login: {
code: "ACCOUNT_LOGIN_VERIFICATION_EMAIL",
message:
"Email verification is required, please check your email.",
},
});
}
if (user.mfa_enabled && !user.webauthn_enabled) {
// TODO: This is not a discord.com ticket. I'm not sure what it is but I'm lazy
const ticket = crypto.randomBytes(40).toString("hex");

View File

@ -17,7 +17,7 @@
*/
import { route, verifyCaptcha } from "@fosscord/api";
import { checkToken, Config, FieldErrors } from "@fosscord/util";
import { checkToken, Config, FieldErrors, User } from "@fosscord/util";
import { Request, Response, Router } from "express";
import { HTTPError } from "lambert-server";
const router = Router();
@ -57,11 +57,7 @@ router.post(
if (user.verified) return res.send(user);
// verify email
user.verified = true;
await user.save();
// TODO: invalidate token after use?
await User.update({ id: user.id }, { verified: true });
return res.send(user);
} catch (error) {

View File

@ -18,4 +18,5 @@
export class LoginConfiguration {
requireCaptcha: boolean = false;
requireVerification: boolean = false;
}