added footer links, added email alias check
This commit is contained in:
@@ -51,29 +51,30 @@ export const deletePilotHistory = async (id: number) => {
|
||||
});
|
||||
};
|
||||
|
||||
export const CheckEmailCode = async (userId: string, code: string) => {
|
||||
const user = await prisma.user.findUnique({
|
||||
export const CheckEmailCode = async (code: string) => {
|
||||
const users = await prisma.user.findMany({
|
||||
where: {
|
||||
id: userId,
|
||||
emailVerificationToken: code,
|
||||
},
|
||||
select: {
|
||||
id: true,
|
||||
emailVerificationToken: true,
|
||||
emailVerificationExpiresAt: true,
|
||||
},
|
||||
});
|
||||
if (!user) {
|
||||
return { error: "Nutzer nicht gefunden" };
|
||||
}
|
||||
if (user.emailVerificationToken !== code || !user.emailVerificationExpiresAt) {
|
||||
return { error: "Falscher Code" };
|
||||
const user = users[0];
|
||||
|
||||
if (!user || !user.emailVerificationExpiresAt) {
|
||||
return { error: "Code ist ungültig" };
|
||||
}
|
||||
|
||||
if (user.emailVerificationExpiresAt < new Date()) {
|
||||
return { error: "Code ist nicht mehr gültig" };
|
||||
}
|
||||
|
||||
await prisma.user.update({
|
||||
where: {
|
||||
id: userId,
|
||||
id: user.id,
|
||||
},
|
||||
data: {
|
||||
emailVerified: true,
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
import type { Metadata } from "next";
|
||||
import { DiscordLogoIcon, InstagramLogoIcon, ReaderIcon } from "@radix-ui/react-icons";
|
||||
import { HorizontalNav, VerticalNav } from "../_components/Nav";
|
||||
import { Toaster } from "react-hot-toast";
|
||||
import { redirect } from "next/navigation";
|
||||
import { getServerSession } from "../api/auth/[...nextauth]/auth";
|
||||
import { Error } from "_components/Error";
|
||||
@@ -20,7 +19,7 @@ export default async function RootLayout({
|
||||
const session = await getServerSession();
|
||||
|
||||
if (session?.user.isBanned)
|
||||
return <Error title="You are banned from using this service" statusCode={403} />;
|
||||
return <Error title="Dein Account wurde gesperrt!" statusCode={403} />;
|
||||
|
||||
if (!session) redirect(`/login`);
|
||||
|
||||
@@ -32,13 +31,6 @@ export default async function RootLayout({
|
||||
}}
|
||||
>
|
||||
<div className="hero-overlay bg-opacity-30"></div>
|
||||
<div>
|
||||
<Toaster
|
||||
containerStyle={{ zIndex: "999999999" }}
|
||||
position="top-center"
|
||||
reverseOrder={false}
|
||||
/>
|
||||
</div>
|
||||
{/* Card */}
|
||||
<div className="hero-content text-neutral-content text-center w-full max-w-full h-full m-10">
|
||||
<div className="card bg-base-100 shadow-2xl w-full min-h-full h-full max-h-[calc(100vh-13rem)] p-4 flex flex-col mr-24 ml-24">
|
||||
@@ -65,10 +57,10 @@ export default async function RootLayout({
|
||||
<footer className="footer flex justify-between items-center p-4 bg-base-200 mt-4 rounded-lg shadow-md">
|
||||
{/* Left: Impressum & Datenschutz */}
|
||||
<div className="flex gap-4 text-sm">
|
||||
<a href="/impressum" className="hover:text-primary">
|
||||
<a href="https://virtualairrescue.com/impressum/" className="hover:text-primary">
|
||||
Impressum
|
||||
</a>
|
||||
<a href="/datenschutz" className="hover:text-primary">
|
||||
<a href="https://virtualairrescue.com/datenschutz/" className="hover:text-primary">
|
||||
Datenschutzerklärung
|
||||
</a>
|
||||
</div>
|
||||
@@ -80,7 +72,7 @@ export default async function RootLayout({
|
||||
<div className="flex gap-4">
|
||||
<div className="tooltip tooltip-top" data-tip="Discord">
|
||||
<a
|
||||
href="https://discord.com"
|
||||
href="https://discord.gg/yn7uXmmNnG"
|
||||
target="_blank"
|
||||
rel="noopener noreferrer"
|
||||
className="hover:text-primary"
|
||||
@@ -90,7 +82,7 @@ export default async function RootLayout({
|
||||
</div>
|
||||
<div className="tooltip tooltip-top" data-tip="Instagram">
|
||||
<a
|
||||
href="https://instagram.com"
|
||||
href="https://www.instagram.com/virtualairrescue/"
|
||||
target="_blank"
|
||||
rel="noopener noreferrer"
|
||||
className="hover:text-primary"
|
||||
@@ -99,7 +91,7 @@ export default async function RootLayout({
|
||||
</a>
|
||||
</div>
|
||||
<div className="tooltip tooltip-top" data-tip="Knowledgebase">
|
||||
<a href="/docs" className="hover:text-primary">
|
||||
<a href="https://docs.virtualairrescue.com/" className="hover:text-primary">
|
||||
<ReaderIcon className="w-5 h-5" />
|
||||
</a>
|
||||
</div>
|
||||
|
||||
@@ -23,16 +23,29 @@ import toast from "react-hot-toast";
|
||||
import { UserOptionalDefaults, UserOptionalDefaultsSchema } from "@repo/db/zod";
|
||||
import { Bell, Plane } from "lucide-react";
|
||||
import Link from "next/link";
|
||||
import { sendVerificationLink } from "(app)/admin/user/action";
|
||||
|
||||
export const ProfileForm = ({ user }: { user: User }): React.JSX.Element => {
|
||||
const schema = z.object({
|
||||
firstname: z.string().min(2).max(30),
|
||||
lastname: z.string().min(2).max(30),
|
||||
email: z.string().email({
|
||||
message: "Bitte gebe eine gültige E-Mail Adresse ein",
|
||||
}),
|
||||
email: z
|
||||
.string()
|
||||
.email({
|
||||
message: "Bitte gebe eine gültige E-Mail Adresse ein",
|
||||
})
|
||||
.refine(
|
||||
(value) => {
|
||||
// Regex to check for email aliases like + or %
|
||||
const emailAliasRegex = /[+%]/;
|
||||
return !emailAliasRegex.test(value);
|
||||
},
|
||||
{
|
||||
message: "Email-Aliase (wie + oder %) sind nicht erlaubt",
|
||||
},
|
||||
),
|
||||
settingsHideLastname: z.boolean(),
|
||||
emailVerified: z.boolean(),
|
||||
emailVerified: z.boolean().optional(),
|
||||
});
|
||||
const [isLoading, setIsLoading] = useState(false);
|
||||
type IFormInput = z.infer<typeof schema>;
|
||||
@@ -46,6 +59,7 @@ export const ProfileForm = ({ user }: { user: User }): React.JSX.Element => {
|
||||
},
|
||||
resolver: zodResolver(schema),
|
||||
});
|
||||
console.log(form.formState.errors);
|
||||
return (
|
||||
<form
|
||||
className="card-body"
|
||||
@@ -53,13 +67,20 @@ export const ProfileForm = ({ user }: { user: User }): React.JSX.Element => {
|
||||
setIsLoading(true);
|
||||
await updateUser(values);
|
||||
form.reset(values);
|
||||
if (user.email !== values.email) {
|
||||
await sendVerificationLink(user.id);
|
||||
toast.success(
|
||||
"Deine E-Mail Addresse hat sich geändert, wir haben die einen Link gesendet!",
|
||||
);
|
||||
} else {
|
||||
toast.success("Deine Änderungen wurden gespeichert!", {
|
||||
style: {
|
||||
background: "var(--color-base-100)",
|
||||
color: "var(--color-base-content)",
|
||||
},
|
||||
});
|
||||
}
|
||||
setIsLoading(false);
|
||||
toast.success("Deine Änderungen wurden gespeichert!", {
|
||||
style: {
|
||||
background: "var(--color-base-100)",
|
||||
color: "var(--color-base-content)",
|
||||
},
|
||||
});
|
||||
})}
|
||||
>
|
||||
<h2 className="card-title">
|
||||
@@ -105,12 +126,13 @@ export const ProfileForm = ({ user }: { user: User }): React.JSX.Element => {
|
||||
<EnvelopeClosedIcon /> E-Mail
|
||||
</span>
|
||||
<input
|
||||
{...form.register("email")}
|
||||
value={form.watch("email")}
|
||||
type="text"
|
||||
className="input input-bordered w-full"
|
||||
defaultValue={user.email}
|
||||
onChange={(e) => {
|
||||
form.setValue("email", e.target.value.trim());
|
||||
form.setValue("email", e.target.value.trim(), {
|
||||
shouldDirty: true,
|
||||
});
|
||||
form.setValue("emailVerified", false);
|
||||
}}
|
||||
placeholder="E-Mail"
|
||||
|
||||
@@ -1,56 +0,0 @@
|
||||
"use client";
|
||||
import { CheckEmailCode } from "(app)/admin/user/action";
|
||||
import { Check } from "lucide-react";
|
||||
import { useSession } from "next-auth/react";
|
||||
import { useRouter, useSearchParams } from "next/navigation";
|
||||
import { useEffect, useState } from "react";
|
||||
import toast from "react-hot-toast";
|
||||
|
||||
export default function Page() {
|
||||
const session = useSession();
|
||||
const router = useRouter();
|
||||
const searchParams = useSearchParams();
|
||||
const paramsCode = searchParams.get("code");
|
||||
const [code, setCode] = useState(paramsCode || "");
|
||||
|
||||
useEffect(() => {
|
||||
if (!paramsCode) return;
|
||||
verifyCode(paramsCode);
|
||||
}, [paramsCode])
|
||||
|
||||
async function verifyCode(code: string) {
|
||||
if (!session.data?.user.email || !code) return;
|
||||
const res = await CheckEmailCode(session.data?.user.id || "", code);
|
||||
if (res.error) {
|
||||
toast.error(res.error);
|
||||
} else {
|
||||
toast.success(res.message || "E-Mail erfolgreich bestätigt!");
|
||||
router.push("/");
|
||||
}
|
||||
}
|
||||
|
||||
return (
|
||||
<div className="card bg-base-200 shadow-xl mb-4 ">
|
||||
<div className="card-body">
|
||||
<p className="text-2xl font-semibold text-left flex items-center gap-2">
|
||||
<Check className="w-5 h-5" /> E-Mail Bestätigung
|
||||
</p>
|
||||
<div className="flex justify-center gap-3 w-full">
|
||||
<input
|
||||
className="input flex-1"
|
||||
placeholder="Bestätigungscode"
|
||||
value={code}
|
||||
onChange={(e) => setCode(e.target.value)}
|
||||
/>
|
||||
<button
|
||||
className="btn btn-primary"
|
||||
onClick={() => verifyCode(code)}
|
||||
disabled={!session.data?.user.email || !code}
|
||||
>
|
||||
Bestätigen
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
Reference in New Issue
Block a user