mirror of
https://github.com/Unleash/unleash.git
synced 2024-12-22 19:07:54 +01:00
fix: add check for obscure error (#305)
This commit is contained in:
parent
281e027c8a
commit
0e32583fa0
@ -4,7 +4,7 @@ export const useStyles = makeStyles(theme => ({
|
|||||||
container: {
|
container: {
|
||||||
border: '1px solid #f1f1f1',
|
border: '1px solid #f1f1f1',
|
||||||
borderRadius: '3px',
|
borderRadius: '3px',
|
||||||
right: '100px',
|
position: 'relative',
|
||||||
maxWidth: '350px',
|
maxWidth: '350px',
|
||||||
color: '#44606e',
|
color: '#44606e',
|
||||||
},
|
},
|
||||||
@ -41,4 +41,9 @@ export const useStyles = makeStyles(theme => ({
|
|||||||
helpIcon: {
|
helpIcon: {
|
||||||
height: '17.5px',
|
height: '17.5px',
|
||||||
},
|
},
|
||||||
|
repeatingError: {
|
||||||
|
marginTop: '0.5rem',
|
||||||
|
bottom: '0',
|
||||||
|
position: 'absolute',
|
||||||
|
},
|
||||||
}));
|
}));
|
||||||
|
@ -6,6 +6,8 @@ import { useStyles } from './PasswordChecker.styles';
|
|||||||
import HelpIcon from '@material-ui/icons/Help';
|
import HelpIcon from '@material-ui/icons/Help';
|
||||||
import { useCallback } from 'react';
|
import { useCallback } from 'react';
|
||||||
import { formatApiPath } from '../../../../../utils/format-path';
|
import { formatApiPath } from '../../../../../utils/format-path';
|
||||||
|
import { Alert } from '@material-ui/lab';
|
||||||
|
import ConditionallyRender from '../../../../common/ConditionallyRender';
|
||||||
|
|
||||||
interface IPasswordCheckerProps {
|
interface IPasswordCheckerProps {
|
||||||
password: string;
|
password: string;
|
||||||
@ -31,6 +33,8 @@ const UPPERCASE_ERROR =
|
|||||||
'The password must contain at least one uppercase letter.';
|
'The password must contain at least one uppercase letter.';
|
||||||
const LOWERCASE_ERROR =
|
const LOWERCASE_ERROR =
|
||||||
'The password must contain at least one lowercase letter.';
|
'The password must contain at least one lowercase letter.';
|
||||||
|
const REPEATING_CHARACTER_ERROR =
|
||||||
|
'The password may not contain sequences of three or more repeated characters.';
|
||||||
|
|
||||||
const PasswordChecker = ({
|
const PasswordChecker = ({
|
||||||
password,
|
password,
|
||||||
@ -42,6 +46,7 @@ const PasswordChecker = ({
|
|||||||
const [numberError, setNumberError] = useState(true);
|
const [numberError, setNumberError] = useState(true);
|
||||||
const [symbolError, setSymbolError] = useState(true);
|
const [symbolError, setSymbolError] = useState(true);
|
||||||
const [lengthError, setLengthError] = useState(true);
|
const [lengthError, setLengthError] = useState(true);
|
||||||
|
const [repeatingCharError, setRepeatingCharError] = useState(false);
|
||||||
|
|
||||||
const makeValidatePassReq = useCallback(() => {
|
const makeValidatePassReq = useCallback(() => {
|
||||||
const path = formatApiPath('auth/reset/validate-password');
|
const path = formatApiPath('auth/reset/validate-password');
|
||||||
@ -54,9 +59,19 @@ const PasswordChecker = ({
|
|||||||
});
|
});
|
||||||
}, [password]);
|
}, [password]);
|
||||||
|
|
||||||
|
const clearCheckerErrors = useCallback(() => {
|
||||||
|
setAllErrors(false);
|
||||||
|
}, []);
|
||||||
|
|
||||||
const checkPassword = useCallback(async () => {
|
const checkPassword = useCallback(async () => {
|
||||||
if (!password) return;
|
if (!password) {
|
||||||
if (password.length < 3) return;
|
setAllErrors(true);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (password.length < 3) {
|
||||||
|
setLengthError(true);
|
||||||
|
return;
|
||||||
|
}
|
||||||
try {
|
try {
|
||||||
const res = await makeValidatePassReq();
|
const res = await makeValidatePassReq();
|
||||||
if (res.status === BAD_REQUEST) {
|
if (res.status === BAD_REQUEST) {
|
||||||
@ -66,24 +81,25 @@ const PasswordChecker = ({
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (res.status === OK) {
|
if (res.status === OK) {
|
||||||
clearErrors();
|
clearCheckerErrors();
|
||||||
|
setRepeatingCharError(false);
|
||||||
callback(true);
|
callback(true);
|
||||||
}
|
}
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
// ResetPasswordForm handles errors related to submitting the form.
|
// ResetPasswordForm handles errors related to submitting the form.
|
||||||
console.log('An exception was caught and handled');
|
console.log('An exception was caught and handled');
|
||||||
}
|
}
|
||||||
}, [makeValidatePassReq, callback, password]);
|
}, [makeValidatePassReq, callback, password, clearCheckerErrors]);
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
checkPassword();
|
checkPassword();
|
||||||
}, [password, checkPassword]);
|
}, [password, checkPassword]);
|
||||||
|
|
||||||
const clearErrors = () => {
|
const setAllErrors = (flag: boolean) => {
|
||||||
setCasingError(false);
|
setCasingError(flag);
|
||||||
setNumberError(false);
|
setNumberError(flag);
|
||||||
setSymbolError(false);
|
setSymbolError(flag);
|
||||||
setLengthError(false);
|
setLengthError(flag);
|
||||||
};
|
};
|
||||||
|
|
||||||
const handleErrorResponse = (data: IErrorResponse) => {
|
const handleErrorResponse = (data: IErrorResponse) => {
|
||||||
@ -115,6 +131,12 @@ const PasswordChecker = ({
|
|||||||
} else {
|
} else {
|
||||||
setCasingError(false);
|
setCasingError(false);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (errors.includes(REPEATING_CHARACTER_ERROR)) {
|
||||||
|
setRepeatingCharError(true);
|
||||||
|
} else {
|
||||||
|
setRepeatingCharError(false);
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
const lengthStatusBarClasses = classnames(styles.statusBar, {
|
const lengthStatusBarClasses = classnames(styles.statusBar, {
|
||||||
@ -191,6 +213,17 @@ const PasswordChecker = ({
|
|||||||
<div className={symbolStatusBarClasses} data-loading />
|
<div className={symbolStatusBarClasses} data-loading />
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
<ConditionallyRender
|
||||||
|
condition={repeatingCharError}
|
||||||
|
show={
|
||||||
|
<Alert
|
||||||
|
severity="error"
|
||||||
|
className={styles.repeatingError}
|
||||||
|
>
|
||||||
|
You may not repeat three characters in a row.
|
||||||
|
</Alert>
|
||||||
|
}
|
||||||
|
/>
|
||||||
</div>
|
</div>
|
||||||
</>
|
</>
|
||||||
);
|
);
|
||||||
|
@ -41,6 +41,10 @@ const ResetPasswordForm = ({ token, setLoading }: IResetPasswordProps) => {
|
|||||||
]);
|
]);
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
|
if (!password) {
|
||||||
|
setValidOwaspPassword(false);
|
||||||
|
}
|
||||||
|
|
||||||
if (password === confirmPassword) {
|
if (password === confirmPassword) {
|
||||||
setMatchingPasswords(true);
|
setMatchingPasswords(true);
|
||||||
} else {
|
} else {
|
||||||
|
Loading…
Reference in New Issue
Block a user