Require verified email for new account registration

This commit is contained in:
Kalle 2024-04-12 21:23:51 +03:00
parent 610c6a4db5
commit 424dbf443e
9 changed files with 29 additions and 16 deletions

View File

@ -3,12 +3,15 @@ import { useTranslation } from "react-i18next";
import { LOG_IN_URL, SENDOU_INK_DISCORD_URL } from "~/utils/urls";
import { Button } from "../Button";
import { Dialog } from "../Dialog";
import { createPortal } from "react-dom";
import { useIsMounted } from "~/hooks/useIsMounted";
export function LogInButtonContainer({
children,
}: {
children: React.ReactNode;
}) {
const isMounted = useIsMounted();
const { t } = useTranslation();
const [searchParams, setSearchParams] = useSearchParams();
const authError = searchParams.get("authError");
@ -23,14 +26,19 @@ export function LogInButtonContainer({
<form action={LOG_IN_URL} method="post">
{children}
</form>
{authError != null && (
<Dialog isOpen close={closeAuthErrorDialog}>
<div className="stack md">
<AuthenticationErrorHelp errorCode={authError} />
<Button onClick={closeAuthErrorDialog}>{t("actions.close")}</Button>
</div>
</Dialog>
)}
{authError != null &&
isMounted &&
createPortal(
<Dialog isOpen close={closeAuthErrorDialog}>
<div className="stack md">
<AuthenticationErrorHelp errorCode={authError} />
<Button onClick={closeAuthErrorDialog}>
{t("actions.close")}
</Button>
</div>
</Dialog>,
document.body,
)}
</>
);
}

View File

@ -5,6 +5,7 @@ import { OAuth2Strategy } from "remix-auth-oauth2";
import invariant from "tiny-invariant";
import { z } from "zod";
import * as UserRepository from "~/features/user-page/UserRepository.server";
import { logger } from "~/utils/logger";
interface DiscordExtraParams extends Record<string, string | number> {
scope: string;
@ -18,6 +19,7 @@ const partialDiscordUserSchema = z.object({
id: z.string(),
username: z.string(),
global_name: z.string().nullish(),
verified: z.boolean().nullish(),
});
const partialDiscordConnectionsSchema = z.array(
z.object({
@ -63,6 +65,15 @@ export class DiscordStrategy extends OAuth2Strategy<
const [user, connections] =
discordUserDetailsSchema.parse(discordResponses);
const isAlreadyRegistered = Boolean(
await UserRepository.findByIdentifier(user.id),
);
if (!isAlreadyRegistered && !user.verified) {
logger.info(`User is not verified with id: ${user.id}`);
throw new Error("Unverified user");
}
const userFromDb = await UserRepository.upsert({
discordAvatar: user.avatar ?? null,
discordDiscriminator: user.discriminator,
@ -80,7 +91,7 @@ export class DiscordStrategy extends OAuth2Strategy<
},
);
this.scope = "identify connections";
this.scope = "identify connections email";
}
private authGatewayEnabled() {

View File

@ -33,7 +33,6 @@
"auth.errors.aborted": "logindforsøg afbrudt",
"auth.errors.failed": "Loginforsøg fejlet",
"auth.errors.discordPermissions": "Før at du kan oprette en profil på Sendou.ink, skal Sendou.ink have adgang til din Discordprofils navn, brugerbillede og sociale forbindelser (de sociale medier, som du har tilknyttet din discordprofil).",
"auth.errors.unknown": "Log ind fejlet grundet en serverfejl. Prøv igen senere eller brug /login-kommandoen via Lohi-botten. Botten kan blive fundet på sendou.inks Discordserver",
"footer.github.subtitle": "Kildekode",
"footer.discord.subtitle": "Hjælp og feedback",

View File

@ -33,7 +33,7 @@
"auth.errors.aborted": "Login Aborted",
"auth.errors.failed": "Login Failed",
"auth.errors.discordPermissions": "For your sendou.ink profile, the site needs access to your Discord profile's name, avatar and social connections.",
"auth.errors.unknown": "The login failed due to a server error. Please try again later or use the /login command via the Lohi bot. The bot can be found on sendou.ink's Discord:",
"auth.errors.unknown": "Does your Discord account have a verified email? For help please reach out to us via the #helpdesk channel on our Discord:",
"footer.github.subtitle": "Source code",
"footer.discord.subtitle": "Help & feedback",

View File

@ -33,7 +33,6 @@
"auth.errors.aborted": "Connexion abandonnée",
"auth.errors.failed": "Connexion échouée",
"auth.errors.discordPermissions": "Pour mettre en place votre profil, sendou.ink a besoin de votre nom de profil Discord, de votre avatar et de vos réseaux connectés.",
"auth.errors.unknown": "La connexion a échoué en raison d'une erreur de serveur. Veuillez réessayer plus tards ou utlisez la commande /login via le bot Lohi sur le serveur Discord:",
"footer.github.subtitle": "Code source",
"footer.discord.subtitle": "Aide & retours",

View File

@ -33,7 +33,6 @@
"auth.errors.aborted": "הכניסה בוטלה",
"auth.errors.failed": "הכניסה נכשלה",
"auth.errors.discordPermissions": "עבור פרופיל sendou.ink שלך, האתר זקוק לגישה לשם, הפרופיל והקשרים החברתיים של פרופיל ה-Discord שלך.",
"auth.errors.unknown": "ההתחברות נכשלה עקב שגיאה בשרת. נסו שוב בבקשה או השתמשו בפקודה /login דרך הלוהי בוט. הבוט נמצא בשרת דיסקורד sendou.ink:",
"footer.github.subtitle": "קוד מקור",
"footer.discord.subtitle": "עזרה & משוב",

View File

@ -33,7 +33,6 @@
"auth.errors.aborted": "Login Abortado",
"auth.errors.failed": "Login Falhou",
"auth.errors.discordPermissions": "Para o seu perfil do sendou.ink, o site precisa de acesso ao nome do perfil do seu Discord, incluindo também o avatar e conexões sociais.",
"auth.errors.unknown": "O login falhou devido a um erro do servidor. Por favor, tente novamente mais tarde ou use o comando /login através do bot Lohi. O bot pode ser encontrado no Discord do sendou.ink:",
"footer.github.subtitle": "Código fonte",
"footer.discord.subtitle": "Ajuda e Feedback",

View File

@ -33,7 +33,6 @@
"auth.errors.aborted": "Вход отменён",
"auth.errors.failed": "Ошибка входа",
"auth.errors.discordPermissions": "Для вашего профиля на sendou.ink странице нужет доступ к вашему имени, аватару и привязанным аккаунтам соц. сетей в Discord.",
"auth.errors.unknown": "Логин не удался из-за серверной ошибки. Пожалуйста, повторите попытку позже или воспользуйтесь командой /login с помощью бота Lohi, которого можно найти на Discord сервере sendou.ink:",
"footer.github.subtitle": "Исходный код",
"footer.discord.subtitle": "Помощь и обратная связь",

View File

@ -33,7 +33,6 @@
"auth.errors.aborted": "登录中止",
"auth.errors.failed": "登录失败",
"auth.errors.discordPermissions": "为了完善您的sendou.ink个人资料网站需要获取您的Discord名字、头像和社交链接。",
"auth.errors.unknown": "登录因服务器错误失败。请稍后重试或通过Lohi机器人使用/login指令。机器人可以在sendou.ink的Discord 中找到:",
"footer.github.subtitle": "源代码",
"footer.discord.subtitle": "帮助及反馈",