fix: change admin user password requirement (#5577)
* fix: change admin user password requirement * fix: preload translations Co-authored-by: Peer Richelsen <[email protected]>
This commit is contained in:
1 parent
fa026ee393
commit
91274d8ee0
3 files changed
+16
-6
No files matched your search
@@ -1,6 +1,7 @@
|
||||
import { CheckIcon } from "@heroicons/react/solid";
|
||||
import { zodResolver } from "@hookform/resolvers/zod";
|
||||
import classNames from "classnames";
|
||||
import { GetServerSidePropsContext } from "next";
|
||||
import { useRouter } from "next/router";
|
||||
import { useState } from "react";
|
||||
import { Controller, FormProvider, useForm } from "react-hook-form";
|
||||
@@ -13,6 +14,8 @@ import { inferSSRProps } from "@calcom/types/inferSSRProps";
|
||||
import { TextField, EmailField, PasswordField, Label } from "@calcom/ui/components/form";
|
||||
import WizardForm from "@calcom/ui/v2/core/WizardForm";
|
||||
|
||||
import { ssrInit } from "@server/lib/ssr";
|
||||
|
||||
const StepDone = () => {
|
||||
const { t } = useLocale();
|
||||
|
||||
@@ -39,7 +42,8 @@ const SetupFormStep1 = (props: { setIsLoading: (val: boolean) => void }) => {
|
||||
email_address: z.string().email({ message: t("enter_valid_email") }),
|
||||
full_name: z.string().min(3, t("at_least_characters", { count: 3 })),
|
||||
password: z.string().superRefine((data, ctx) => {
|
||||
const result = isPasswordValid(data, true);
|
||||
const isStrict = true;
|
||||
const result = isPasswordValid(data, true, isStrict);
|
||||
Object.keys(result).map((key: string) => {
|
||||
if (!result[key as keyof typeof result]) {
|
||||
ctx.addIssue({
|
||||
@@ -185,7 +189,7 @@ const SetupFormStep1 = (props: { setIsLoading: (val: boolean) => void }) => {
|
||||
formMethods.setValue("password", e.target.value);
|
||||
await formMethods.trigger("password");
|
||||
}}
|
||||
hintErrors={["caplow", "min", "num"]}
|
||||
hintErrors={["caplow", "admin_min", "num"]}
|
||||
name="password"
|
||||
className="my-0"
|
||||
autoComplete="off"
|
||||
@@ -221,10 +225,13 @@ export default function Setup(props: inferSSRProps<typeof getServerSideProps>) {
|
||||
);
|
||||
}
|
||||
|
||||
export const getServerSideProps = async () => {
|
||||
export const getServerSideProps = async (context: GetServerSidePropsContext) => {
|
||||
const ssr = await ssrInit(context);
|
||||
const userCount = await prisma.user.count();
|
||||
|
||||
return {
|
||||
props: {
|
||||
trpcState: ssr.dehydrate(),
|
||||
userCount,
|
||||
},
|
||||
};
|
||||
|
||||
@@ -420,6 +420,7 @@
|
||||
"current_incorrect_password": "Current password is incorrect",
|
||||
"password_hint_caplow": "Mix of uppercase & lowercase letters",
|
||||
"password_hint_min": "Minimum 8 characters long",
|
||||
"password_hint_admin_min": "Minimum 15 characters long",
|
||||
"password_hint_num": "Contain at least 1 number",
|
||||
"invalid_password_hint": "The password must be a minimum of 7 characters long containing at least one number and have a mixture of uppercase and lowercase letters",
|
||||
"incorrect_password": "Password is incorrect.",
|
||||
|
||||
@@ -38,13 +38,15 @@ export function isPasswordValid(
|
||||
password: string,
|
||||
breakdown: boolean,
|
||||
strict?: boolean
|
||||
): { caplow: boolean; num: boolean; min: boolean };
|
||||
): { caplow: boolean; num: boolean; min: boolean; admin_min: boolean };
|
||||
export function isPasswordValid(password: string, breakdown?: boolean, strict?: boolean) {
|
||||
let cap = false, // Has uppercase characters
|
||||
low = false, // Has lowercase characters
|
||||
num = false, // At least one number
|
||||
min = false; // Eight characters, or fifteen in strict mode.
|
||||
min = false, // Eight characters, or fifteen in strict mode.
|
||||
admin_min = false;
|
||||
if (password.length > 7 && (!strict || password.length > 14)) min = true;
|
||||
if (strict && password.length > 14) admin_min = true;
|
||||
for (let i = 0; i < password.length; i++) {
|
||||
if (!isNaN(parseInt(password[i]))) num = true;
|
||||
else {
|
||||
@@ -52,7 +54,7 @@ export function isPasswordValid(password: string, breakdown?: boolean, strict?:
|
||||
if (password[i] === password[i].toLowerCase()) low = true;
|
||||
}
|
||||
}
|
||||
return !!breakdown ? { caplow: cap && low, num, min } : cap && low && num && min;
|
||||
return !!breakdown ? { caplow: cap && low, num, min, admin_min } : cap && low && num && min;
|
||||
}
|
||||
|
||||
type CtxOrReq = { req: NextApiRequest; ctx?: never } | { ctx: { req: NextApiRequest }; req?: never };
|
||||
|
||||
Reference in new issue
Block a user