mirror of
https://github.com/andwati/dokploy.git
synced 2026-12-06 01:28:46 +00:00
feat(dokploy): add verification email to cloud version
This commit is contained in:
@@ -0,0 +1,95 @@
|
||||
import { OnboardingLayout } from "@/components/layouts/onboarding-layout";
|
||||
import { Logo } from "@/components/shared/logo";
|
||||
import { CardDescription, CardTitle } from "@/components/ui/card";
|
||||
import { auth } from "@/server/db/schema";
|
||||
import { IS_CLOUD, updateAuthById } from "@dokploy/server";
|
||||
import { isBefore } from "date-fns";
|
||||
import { eq } from "drizzle-orm";
|
||||
import type { GetServerSidePropsContext } from "next";
|
||||
import Link from "next/link";
|
||||
import type { ReactElement } from "react";
|
||||
|
||||
export default function Home() {
|
||||
return (
|
||||
<div className="flex h-screen w-full items-center justify-center ">
|
||||
<div className="flex flex-col items-center gap-4 w-full">
|
||||
<Link href="/" className="flex flex-row items-center gap-2">
|
||||
<Logo />
|
||||
<span className="font-medium text-sm">Dokploy</span>
|
||||
</Link>
|
||||
<CardTitle className="text-2xl font-bold">Email Confirmed</CardTitle>
|
||||
<CardDescription>
|
||||
Congratulations, your email is confirmed.
|
||||
</CardDescription>
|
||||
<div>
|
||||
<Link href="/" className="w-full text-primary">
|
||||
Click here to login
|
||||
</Link>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
Home.getLayout = (page: ReactElement) => {
|
||||
return <OnboardingLayout>{page}</OnboardingLayout>;
|
||||
};
|
||||
export async function getServerSideProps(context: GetServerSidePropsContext) {
|
||||
if (!IS_CLOUD) {
|
||||
return {
|
||||
redirect: {
|
||||
permanent: true,
|
||||
destination: "/",
|
||||
},
|
||||
};
|
||||
}
|
||||
const { token } = context.query;
|
||||
|
||||
if (typeof token !== "string") {
|
||||
return {
|
||||
redirect: {
|
||||
permanent: true,
|
||||
destination: "/",
|
||||
},
|
||||
};
|
||||
}
|
||||
|
||||
const authR = await db?.query.auth.findFirst({
|
||||
where: eq(auth.confirmationToken, token),
|
||||
});
|
||||
|
||||
if (
|
||||
!authR ||
|
||||
authR?.confirmationToken === null ||
|
||||
authR?.confirmationExpiresAt === null
|
||||
) {
|
||||
return {
|
||||
redirect: {
|
||||
permanent: true,
|
||||
destination: "/",
|
||||
},
|
||||
};
|
||||
}
|
||||
|
||||
const isExpired = isBefore(new Date(authR.confirmationExpiresAt), new Date());
|
||||
|
||||
if (isExpired) {
|
||||
return {
|
||||
redirect: {
|
||||
permanent: true,
|
||||
destination: "/",
|
||||
},
|
||||
};
|
||||
}
|
||||
|
||||
await updateAuthById(authR.id, {
|
||||
confirmationToken: null,
|
||||
confirmationExpiresAt: null,
|
||||
});
|
||||
|
||||
return {
|
||||
props: {
|
||||
token: authR.confirmationToken,
|
||||
},
|
||||
};
|
||||
}
|
||||
@@ -1,5 +1,6 @@
|
||||
import { Login2FA } from "@/components/auth/login-2fa";
|
||||
import { OnboardingLayout } from "@/components/layouts/onboarding-layout";
|
||||
import { AlertBlock } from "@/components/shared/alert-block";
|
||||
import { Logo } from "@/components/shared/logo";
|
||||
import { Button } from "@/components/ui/button";
|
||||
import {
|
||||
@@ -63,7 +64,8 @@ export default function Home({ IS_CLOUD }: Props) {
|
||||
is2FAEnabled: false,
|
||||
authId: "",
|
||||
});
|
||||
const { mutateAsync, isLoading } = api.auth.login.useMutation();
|
||||
const { mutateAsync, isLoading, error, isError } =
|
||||
api.auth.login.useMutation();
|
||||
const router = useRouter();
|
||||
const form = useForm<Login>({
|
||||
defaultValues: {
|
||||
@@ -115,6 +117,12 @@ export default function Home({ IS_CLOUD }: Props) {
|
||||
</CardDescription>
|
||||
<Card className="mx-auto w-full max-w-lg bg-transparent ">
|
||||
<div className="p-3.5" />
|
||||
{isError && (
|
||||
<AlertBlock type="error" className="mx-4 my-2">
|
||||
<span>{error?.message}</span>
|
||||
</AlertBlock>
|
||||
)}
|
||||
|
||||
<CardContent>
|
||||
{!temp.is2FAEnabled ? (
|
||||
<Form {...form}>
|
||||
|
||||
@@ -16,7 +16,7 @@ import {
|
||||
} from "@/components/ui/form";
|
||||
import { Input } from "@/components/ui/input";
|
||||
import { api } from "@/utils/api";
|
||||
import { getUserByToken } from "@dokploy/server";
|
||||
import { IS_CLOUD, getUserByToken } from "@dokploy/server";
|
||||
import { zodResolver } from "@hookform/resolvers/zod";
|
||||
import { AlertTriangle } from "lucide-react";
|
||||
import type { GetServerSidePropsContext } from "next";
|
||||
@@ -69,9 +69,10 @@ type Register = z.infer<typeof registerSchema>;
|
||||
interface Props {
|
||||
token: string;
|
||||
invitation: Awaited<ReturnType<typeof getUserByToken>>;
|
||||
isCloud: boolean;
|
||||
}
|
||||
|
||||
const Invitation = ({ token, invitation }: Props) => {
|
||||
const Invitation = ({ token, invitation, isCloud }: Props) => {
|
||||
const router = useRouter();
|
||||
const { data } = api.admin.getUserByToken.useQuery(
|
||||
{
|
||||
@@ -83,7 +84,8 @@ const Invitation = ({ token, invitation }: Props) => {
|
||||
},
|
||||
);
|
||||
|
||||
const { mutateAsync, error, isError } = api.auth.createUser.useMutation();
|
||||
const { mutateAsync, error, isError, isSuccess } =
|
||||
api.auth.createUser.useMutation();
|
||||
|
||||
const form = useForm<Register>({
|
||||
defaultValues: {
|
||||
@@ -112,7 +114,9 @@ const Invitation = ({ token, invitation }: Props) => {
|
||||
})
|
||||
.then(() => {
|
||||
toast.success("User registration succesfuly", {
|
||||
duration: 2000,
|
||||
description:
|
||||
"Please check your inbox or spam folder to confirm your account.",
|
||||
duration: 100000,
|
||||
});
|
||||
router.push("/dashboard/projects");
|
||||
})
|
||||
@@ -146,6 +150,7 @@ const Invitation = ({ token, invitation }: Props) => {
|
||||
</span>
|
||||
</div>
|
||||
)}
|
||||
|
||||
<CardContent>
|
||||
<Form {...form}>
|
||||
<form
|
||||
@@ -210,6 +215,25 @@ const Invitation = ({ token, invitation }: Props) => {
|
||||
Register
|
||||
</Button>
|
||||
</div>
|
||||
|
||||
<div className="mt-4 text-sm flex flex-row justify-between gap-2 w-full">
|
||||
{isCloud && (
|
||||
<>
|
||||
<Link
|
||||
className="hover:underline text-muted-foreground"
|
||||
href="/"
|
||||
>
|
||||
Login
|
||||
</Link>
|
||||
<Link
|
||||
className="hover:underline text-muted-foreground"
|
||||
href="/send-reset-password"
|
||||
>
|
||||
Lost your password?
|
||||
</Link>
|
||||
</>
|
||||
)}
|
||||
</div>
|
||||
</form>
|
||||
</Form>
|
||||
</CardContent>
|
||||
@@ -250,6 +274,7 @@ export async function getServerSideProps(ctx: GetServerSidePropsContext) {
|
||||
|
||||
return {
|
||||
props: {
|
||||
isCloud: IS_CLOUD,
|
||||
token: token,
|
||||
invitation: invitation,
|
||||
},
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
import { AlertBlock } from "@/components/shared/alert-block";
|
||||
import { Logo } from "@/components/shared/logo";
|
||||
import { Button } from "@/components/ui/button";
|
||||
import {
|
||||
@@ -72,7 +73,8 @@ interface Props {
|
||||
|
||||
const Register = ({ isCloud }: Props) => {
|
||||
const router = useRouter();
|
||||
const { mutateAsync, error, isError } = api.auth.createAdmin.useMutation();
|
||||
const { mutateAsync, error, isError, data } =
|
||||
api.auth.createAdmin.useMutation();
|
||||
|
||||
const form = useForm<Register>({
|
||||
defaultValues: {
|
||||
@@ -89,14 +91,16 @@ const Register = ({ isCloud }: Props) => {
|
||||
|
||||
const onSubmit = async (values: Register) => {
|
||||
await mutateAsync({
|
||||
email: values.email,
|
||||
email: values.email.toLowerCase(),
|
||||
password: values.password,
|
||||
})
|
||||
.then(() => {
|
||||
toast.success("User registration succesfuly", {
|
||||
duration: 2000,
|
||||
});
|
||||
router.push("/");
|
||||
if (!isCloud) {
|
||||
router.push("/");
|
||||
}
|
||||
})
|
||||
.catch((e) => e);
|
||||
};
|
||||
@@ -130,6 +134,14 @@ const Register = ({ isCloud }: Props) => {
|
||||
</span>
|
||||
</div>
|
||||
)}
|
||||
{data && (
|
||||
<AlertBlock type="success" className="mx-4 my-2">
|
||||
<span>
|
||||
Registration succesfuly, Please check your inbox or spam
|
||||
folder to confirm your account.
|
||||
</span>
|
||||
</AlertBlock>
|
||||
)}
|
||||
<CardContent>
|
||||
<Form {...form}>
|
||||
<form
|
||||
|
||||
Reference in New Issue
Block a user