summary refs log tree commit diff
diff options
context:
space:
mode:
authorPuyodead1 <puyodead@proton.me>2023-01-30 19:05:22 -0500
committerPuyodead1 <puyodead@protonmail.com>2023-02-23 22:40:05 -0500
commit34cde14f753feb37a2b1dd2ce772ccc8552b4198 (patch)
treed863d17934a31c8bffb6425961e049b387b6b2f1
parentfix linting errors (diff)
downloadserver-34cde14f753feb37a2b1dd2ce772ccc8552b4198.tar.xz
config: require account verification
-rw-r--r--src/api/routes/auth/login.ts11
-rw-r--r--src/api/routes/auth/verify/index.ts8
-rw-r--r--src/util/config/types/LoginConfiguration.ts1
3 files changed, 14 insertions, 6 deletions
diff --git a/src/api/routes/auth/login.ts b/src/api/routes/auth/login.ts
index 2b97ec10..89d0be69 100644
--- a/src/api/routes/auth/login.ts
+++ b/src/api/routes/auth/login.ts
@@ -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");
diff --git a/src/api/routes/auth/verify/index.ts b/src/api/routes/auth/verify/index.ts
index 7809bc26..14cc3f95 100644
--- a/src/api/routes/auth/verify/index.ts
+++ b/src/api/routes/auth/verify/index.ts
@@ -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) {
diff --git a/src/util/config/types/LoginConfiguration.ts b/src/util/config/types/LoginConfiguration.ts
index 862bc185..1d5752fe 100644
--- a/src/util/config/types/LoginConfiguration.ts
+++ b/src/util/config/types/LoginConfiguration.ts
@@ -18,4 +18,5 @@
 
 export class LoginConfiguration {
 	requireCaptcha: boolean = false;
+	requireVerification: boolean = false;
 }