mirror of
https://github.com/awatertrevi/infisical.git
synced 2026-10-12 14:29:34 +00:00
>>> yup for email & url validation, fixed minor err in error msgs
This commit is contained in:
@@ -46,6 +46,7 @@ type Errors = {
|
||||
specialChar?: string;
|
||||
repeatedChar?: string;
|
||||
isEmail?: string;
|
||||
isUrl?: string;
|
||||
isBeachedPassword?: string;
|
||||
};
|
||||
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import isEmail from "validator/lib/isEmail";
|
||||
import {string} from "yup";
|
||||
import { checkIsPasswordBreached } from "./checkIsPasswordBreached";
|
||||
|
||||
/* eslint-disable no-param-reassign */
|
||||
@@ -13,6 +13,7 @@ interface PasswordCheckProps {
|
||||
setPasswordErrorSpecialChar: (value: boolean) => void;
|
||||
setPasswordErrorRepeatedChar: (value: boolean) => void;
|
||||
setPasswordErrorIsEmail: (value: boolean) => void;
|
||||
setPasswordErrorIsUrl: (value: boolean) => void;
|
||||
setPasswordErrorIsBreachedPassword: (value: boolean) => void;
|
||||
}
|
||||
|
||||
@@ -29,6 +30,7 @@ const passwordCheck = async ({
|
||||
setPasswordErrorSpecialChar,
|
||||
setPasswordErrorRepeatedChar,
|
||||
setPasswordErrorIsEmail,
|
||||
setPasswordErrorIsUrl,
|
||||
setPasswordErrorIsBreachedPassword,
|
||||
errorCheck
|
||||
}: PasswordCheckProps) => {
|
||||
@@ -97,13 +99,25 @@ const passwordCheck = async ({
|
||||
}
|
||||
|
||||
// isEmail
|
||||
if (isEmail(password)) {
|
||||
const emailSchema = string().email();
|
||||
|
||||
if (await emailSchema.isValid(password)) {
|
||||
setPasswordErrorIsEmail(true);
|
||||
errorCheck = true;
|
||||
} else {
|
||||
setPasswordErrorIsEmail(false);
|
||||
}
|
||||
|
||||
// isUrl
|
||||
const urlSchema = string().url();
|
||||
|
||||
if (await urlSchema.isValid(password)) {
|
||||
setPasswordErrorIsUrl(true);
|
||||
errorCheck = true;
|
||||
} else {
|
||||
setPasswordErrorIsUrl(false);
|
||||
}
|
||||
|
||||
// breachedPassword
|
||||
if (await checkIsPasswordBreached(password)) {
|
||||
setPasswordErrorIsBreachedPassword(true);
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import isEmail from "validator/lib/isEmail";
|
||||
import {string} from "yup"
|
||||
import { checkIsPasswordBreached } from "./checkIsPasswordBreached";
|
||||
|
||||
type Errors = {
|
||||
@@ -10,6 +10,7 @@ type Errors = {
|
||||
specialChar?: string;
|
||||
repeatedChar?: string;
|
||||
isEmail?: string;
|
||||
isUrl?: string;
|
||||
isBreachedPassword?: string;
|
||||
};
|
||||
|
||||
@@ -93,10 +94,19 @@ const checkPassword = async ({ password, setErrors }: CheckPasswordParams): Prom
|
||||
}
|
||||
|
||||
// isEmail
|
||||
if (isEmail(password)) {
|
||||
const emailSchema = string().email();
|
||||
|
||||
if (await emailSchema.isValid(password)) {
|
||||
errors.isEmail = "The password cannot be an email address";
|
||||
}
|
||||
|
||||
// isUrl
|
||||
const urlSchema = string().url();
|
||||
|
||||
if (await urlSchema.isValid(password)) {
|
||||
errors.isUrl = "The password cannot be a URL";
|
||||
}
|
||||
|
||||
// breachedPassword
|
||||
if (await checkIsPasswordBreached(password)) {
|
||||
errors.isBreachedPassword =
|
||||
|
||||
@@ -36,6 +36,7 @@ export default function PasswordReset() {
|
||||
const [passwordErrorSpecialChar, setPasswordErrorSpecialChar] = useState(false);
|
||||
const [passwordErrorRepeatedChar, setPasswordErrorRepeatedChar] = useState(false);
|
||||
const [passwordErrorIsEmail, setPasswordErrorIsEmail] = useState(false);
|
||||
const [passwordErrorIsUrl, setPasswordErrorIsUrl] = useState(false);
|
||||
const [passwordErrorIsBreachedPassword, setPasswordErrorIsBreachedPassword] = useState(false);
|
||||
|
||||
const router = useRouter();
|
||||
@@ -81,6 +82,7 @@ export default function PasswordReset() {
|
||||
setPasswordErrorSpecialChar,
|
||||
setPasswordErrorRepeatedChar,
|
||||
setPasswordErrorIsEmail,
|
||||
setPasswordErrorIsUrl,
|
||||
setPasswordErrorIsBreachedPassword,
|
||||
errorCheck: false
|
||||
});
|
||||
@@ -243,6 +245,7 @@ export default function PasswordReset() {
|
||||
setPasswordErrorSpecialChar,
|
||||
setPasswordErrorRepeatedChar,
|
||||
setPasswordErrorIsEmail,
|
||||
setPasswordErrorIsUrl,
|
||||
setPasswordErrorIsBreachedPassword,
|
||||
errorCheck: false
|
||||
});
|
||||
@@ -259,6 +262,7 @@ export default function PasswordReset() {
|
||||
passwordErrorSpecialChar &&
|
||||
passwordErrorRepeatedChar &&
|
||||
passwordErrorIsEmail &&
|
||||
passwordErrorIsUrl &&
|
||||
passwordErrorIsBreachedPassword
|
||||
}
|
||||
autoComplete="new-password"
|
||||
@@ -273,6 +277,7 @@ export default function PasswordReset() {
|
||||
passwordErrorSpecialChar ||
|
||||
passwordErrorRepeatedChar ||
|
||||
passwordErrorIsEmail ||
|
||||
passwordErrorIsUrl ||
|
||||
passwordErrorIsBreachedPassword ? (
|
||||
<div className="mx-2 mt-3 mb-2 flex w-full max-w-md flex-col items-start rounded-md bg-white/5 px-2 py-2">
|
||||
<div className="mb-1 text-sm text-gray-400">Password should contain:</div>
|
||||
@@ -369,6 +374,18 @@ export default function PasswordReset() {
|
||||
The password cannot be an email address.
|
||||
</div>
|
||||
</div>
|
||||
<div className="ml-1 flex flex-row items-center justify-start">
|
||||
{passwordErrorIsUrl ? (
|
||||
<FontAwesomeIcon icon={faX} className="text-md mr-2.5 text-red" />
|
||||
) : (
|
||||
<FontAwesomeIcon icon={faCheck} className="text-md mr-2 text-primary" />
|
||||
)}
|
||||
<div
|
||||
className={`${passwordErrorIsUrl ? "text-gray-400" : "text-gray-600"} text-sm`}
|
||||
>
|
||||
The password cannot be a URL.
|
||||
</div>
|
||||
</div>
|
||||
<div className="ml-1 flex flex-row items-center justify-start">
|
||||
{passwordErrorIsBreachedPassword ? (
|
||||
<FontAwesomeIcon icon={faX} className="text-md mr-2.5 text-red" />
|
||||
|
||||
@@ -29,13 +29,15 @@ import { fetchOrganizations } from "@app/hooks/api/organization/queries";
|
||||
const client = new jsrp.client();
|
||||
|
||||
type Errors = {
|
||||
length?: string;
|
||||
tooShort?: string;
|
||||
tooLong?: string;
|
||||
upperCase?: string;
|
||||
lowerCase?: string;
|
||||
number?: string;
|
||||
specialChar?: string;
|
||||
repeatedChar?: string;
|
||||
isEmail?: string;
|
||||
isUrl?: string;
|
||||
breachedPassword?: string;
|
||||
};
|
||||
|
||||
|
||||
+1
@@ -21,6 +21,7 @@ type Errors = {
|
||||
specialChar?: string;
|
||||
repeatedChar?: string;
|
||||
isEmail?: string;
|
||||
isUrl?: string;
|
||||
isBreachedPassword?: string;
|
||||
};
|
||||
|
||||
|
||||
@@ -41,6 +41,7 @@ type Errors = {
|
||||
specialChar?: string;
|
||||
repeatedChar?: string;
|
||||
isEmail?: string;
|
||||
isUrl?: string;
|
||||
isBeachedPassword?: string;
|
||||
};
|
||||
|
||||
|
||||
Reference in New Issue
Block a user