mirror of
https://github.com/fosrl/pangolin.git
synced 2026-03-06 10:46:38 +00:00
add send email verification opt out
This commit is contained in:
@@ -1,7 +1,7 @@
|
|||||||
import { NextFunction, Request, Response } from "express";
|
import { NextFunction, Request, Response } from "express";
|
||||||
import { db, users } from "@server/db";
|
import { db, users } from "@server/db";
|
||||||
import HttpCode from "@server/types/HttpCode";
|
import HttpCode from "@server/types/HttpCode";
|
||||||
import { z } from "zod";
|
import { email, z } from "zod";
|
||||||
import { fromError } from "zod-validation-error";
|
import { fromError } from "zod-validation-error";
|
||||||
import createHttpError from "http-errors";
|
import createHttpError from "http-errors";
|
||||||
import response from "@server/lib/response";
|
import response from "@server/lib/response";
|
||||||
@@ -30,7 +30,8 @@ export const signupBodySchema = z.object({
|
|||||||
inviteToken: z.string().optional(),
|
inviteToken: z.string().optional(),
|
||||||
inviteId: z.string().optional(),
|
inviteId: z.string().optional(),
|
||||||
termsAcceptedTimestamp: z.string().nullable().optional(),
|
termsAcceptedTimestamp: z.string().nullable().optional(),
|
||||||
marketingEmailConsent: z.boolean().optional()
|
marketingEmailConsent: z.boolean().optional(),
|
||||||
|
skipVerificationEmail: z.boolean().optional()
|
||||||
});
|
});
|
||||||
|
|
||||||
export type SignUpBody = z.infer<typeof signupBodySchema>;
|
export type SignUpBody = z.infer<typeof signupBodySchema>;
|
||||||
@@ -61,7 +62,8 @@ export async function signup(
|
|||||||
inviteToken,
|
inviteToken,
|
||||||
inviteId,
|
inviteId,
|
||||||
termsAcceptedTimestamp,
|
termsAcceptedTimestamp,
|
||||||
marketingEmailConsent
|
marketingEmailConsent,
|
||||||
|
skipVerificationEmail
|
||||||
} = parsedBody.data;
|
} = parsedBody.data;
|
||||||
|
|
||||||
const passwordHash = await hashPassword(password);
|
const passwordHash = await hashPassword(password);
|
||||||
@@ -214,7 +216,13 @@ export async function signup(
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (config.getRawConfig().flags?.require_email_verification) {
|
if (config.getRawConfig().flags?.require_email_verification) {
|
||||||
sendEmailVerificationCode(email, userId);
|
if (!skipVerificationEmail) {
|
||||||
|
sendEmailVerificationCode(email, userId);
|
||||||
|
} else {
|
||||||
|
logger.debug(
|
||||||
|
`User ${email} opted out of verification email during signup.`
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
return response<SignUpResponse>(res, {
|
return response<SignUpResponse>(res, {
|
||||||
data: {
|
data: {
|
||||||
@@ -222,7 +230,9 @@ export async function signup(
|
|||||||
},
|
},
|
||||||
success: true,
|
success: true,
|
||||||
error: false,
|
error: false,
|
||||||
message: `User created successfully. We sent an email to ${email} with a verification code.`,
|
message: skipVerificationEmail
|
||||||
|
? "User created successfully. Please verify your email."
|
||||||
|
: `User created successfully. We sent an email to ${email} with a verification code.`,
|
||||||
status: HttpCode.OK
|
status: HttpCode.OK
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -436,6 +436,7 @@ export async function validateOidcCallback(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// These are the orgs that the user should be provisioned into based on the IdP mappings and the token claims
|
||||||
logger.debug("User org info", { userOrgInfo });
|
logger.debug("User org info", { userOrgInfo });
|
||||||
|
|
||||||
let existingUserId = existingUser?.userId;
|
let existingUserId = existingUser?.userId;
|
||||||
|
|||||||
@@ -15,6 +15,7 @@ export default async function Page(props: {
|
|||||||
redirect: string | undefined;
|
redirect: string | undefined;
|
||||||
email: string | undefined;
|
email: string | undefined;
|
||||||
fromSmartLogin: string | undefined;
|
fromSmartLogin: string | undefined;
|
||||||
|
skipVerificationEmail: string | undefined;
|
||||||
}>;
|
}>;
|
||||||
}) {
|
}) {
|
||||||
const searchParams = await props.searchParams;
|
const searchParams = await props.searchParams;
|
||||||
@@ -75,6 +76,10 @@ export default async function Page(props: {
|
|||||||
inviteId={inviteId}
|
inviteId={inviteId}
|
||||||
emailParam={searchParams.email}
|
emailParam={searchParams.email}
|
||||||
fromSmartLogin={searchParams.fromSmartLogin === "true"}
|
fromSmartLogin={searchParams.fromSmartLogin === "true"}
|
||||||
|
skipVerificationEmail={
|
||||||
|
searchParams.skipVerificationEmail === "true" ||
|
||||||
|
searchParams.skipVerificationEmail === "1"
|
||||||
|
}
|
||||||
/>
|
/>
|
||||||
|
|
||||||
<p className="text-center text-muted-foreground mt-4">
|
<p className="text-center text-muted-foreground mt-4">
|
||||||
|
|||||||
@@ -72,6 +72,7 @@ type SignupFormProps = {
|
|||||||
inviteToken?: string;
|
inviteToken?: string;
|
||||||
emailParam?: string;
|
emailParam?: string;
|
||||||
fromSmartLogin?: boolean;
|
fromSmartLogin?: boolean;
|
||||||
|
skipVerificationEmail?: boolean;
|
||||||
};
|
};
|
||||||
|
|
||||||
const formSchema = z
|
const formSchema = z
|
||||||
@@ -103,7 +104,8 @@ export default function SignupForm({
|
|||||||
inviteId,
|
inviteId,
|
||||||
inviteToken,
|
inviteToken,
|
||||||
emailParam,
|
emailParam,
|
||||||
fromSmartLogin = false
|
fromSmartLogin = false,
|
||||||
|
skipVerificationEmail = false
|
||||||
}: SignupFormProps) {
|
}: SignupFormProps) {
|
||||||
const router = useRouter();
|
const router = useRouter();
|
||||||
const { env } = useEnvContext();
|
const { env } = useEnvContext();
|
||||||
@@ -147,7 +149,8 @@ export default function SignupForm({
|
|||||||
inviteToken,
|
inviteToken,
|
||||||
termsAcceptedTimestamp: termsAgreedAt,
|
termsAcceptedTimestamp: termsAgreedAt,
|
||||||
marketingEmailConsent:
|
marketingEmailConsent:
|
||||||
build === "saas" ? marketingEmailConsent : undefined
|
build === "saas" ? marketingEmailConsent : undefined,
|
||||||
|
skipVerificationEmail: skipVerificationEmail || undefined
|
||||||
})
|
})
|
||||||
.catch((e) => {
|
.catch((e) => {
|
||||||
console.error(e);
|
console.error(e);
|
||||||
|
|||||||
Reference in New Issue
Block a user