Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Captcha bug fixes #2801

Merged
merged 3 commits into from
Sep 19, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 6 additions & 4 deletions verification/curator-service/api/src/controllers/auth.ts
Original file line number Diff line number Diff line change
Expand Up @@ -216,12 +216,13 @@ export class AuthController {
req.body.token,
);

if (!captchaResult)
if (!captchaResult) {
res.status(403).json({
message:
"Unfortunately, you didn't pass the captcha. Please, try again later.",
});

return;
}
passport.authenticate(
'register',
(error: Error, user: IUser, info: any) => {
Expand Down Expand Up @@ -253,12 +254,13 @@ export class AuthController {
req.body.token,
);

if (!captchaResult)
if (!captchaResult) {
res.status(403).json({
message:
"Unfortunately, you didn't pass the captcha. Please, try again later.",
});

return;
}
passport.authenticate(
'login',
(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ export const loginLimiter = rateLimit({
message: 'Too many failed login attempts, please try again later',
});
},
skipSuccessfulRequests: true,
});

export const registerLimiter = rateLimit({
Expand All @@ -23,6 +24,7 @@ export const registerLimiter = rateLimit({
'You sent too many requests. Please wait a while then try again',
});
},
skipSuccessfulRequests: true,
});

export const resetPasswordLimiter = rateLimit({
Expand All @@ -36,6 +38,7 @@ export const resetPasswordLimiter = rateLimit({
'You sent too many requests. Please wait a while then try again',
});
},
skipSuccessfulRequests: true,
});

export const forgotPasswordLimiter = rateLimit({
Expand All @@ -49,6 +52,7 @@ export const forgotPasswordLimiter = rateLimit({
'You sent too many requests. Please wait a while then try again',
});
},
skipSuccessfulRequests: true,
});

export const resetPasswordWithTokenLimiter = rateLimit({
Expand All @@ -62,4 +66,5 @@ export const resetPasswordWithTokenLimiter = rateLimit({
'You sent too many requests. Please wait a while then try again',
});
},
skipSuccessfulRequests: true,
});
18 changes: 9 additions & 9 deletions verification/curator-service/ui/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion verification/curator-service/ui/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
"react-dom": "^16.13.1",
"react-draggable": "^4.4.4",
"react-google-button": "^0.7.2",
"react-google-recaptcha": "^2.1.0",
"react-google-recaptcha": "^3.0.0-alpha.1",
"react-gtm-module": "^2.0.11",
"react-helmet": "^6.1.0",
"react-highlight-words": "^0.17.0",
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import React, { useEffect, useState } from 'react';
import React, { useEffect, useRef, useState } from 'react';
import { Paper, Typography } from '@material-ui/core';
import { Theme, makeStyles } from '@material-ui/core/styles';
import { useLastLocation } from 'react-router-last-location';
Expand Down Expand Up @@ -33,6 +33,7 @@ import {
import { MapLink } from '../../constants/types';
import { getReleaseNotesUrl } from '../util/helperFunctions';
import { getDiseaseName } from '../../redux/app/thunk';
import ReCAPTCHA from 'react-google-recaptcha';

interface StylesProps {
smallHeight: boolean;
Expand Down Expand Up @@ -202,6 +203,11 @@ const MoreInformationLinks = ({
);
};

const RECAPTCHA_SITE_KEY = window.Cypress
? '6LeIxAcTAAAAAJcZVRqyHh71UMIEGNQ_MXjiZKhI'
: ((process.env.RECAPTCHA_SITE_KEY ||
process.env.REACT_APP_RECAPTCHA_SITE_KEY) as string);

const LandingPage = (): JSX.Element => {
const dispatch = useAppDispatch();

Expand All @@ -210,6 +216,7 @@ const LandingPage = (): JSX.Element => {
const lastLocation = useLastLocation();
const [registrationScreenOn, setRegistrationScreenOn] = useState(true);
const [changePasswordScreenOn, setChangePasswordScreenOn] = useState(false);
const recaptchaRef = useRef<ReCAPTCHA>(null);

const isLoading = useAppSelector(selectIsLoading);
const error = useAppSelector(selectError);
Expand Down Expand Up @@ -277,15 +284,18 @@ const LandingPage = (): JSX.Element => {
<SignUpForm
disabled={isLoading}
setRegistrationScreenOn={setRegistrationScreenOn}
recaptchaRef={recaptchaRef}
/>
) : (
!changePasswordScreenOn && (
<SignInForm
disabled={isLoading}
setRegistrationScreenOn={setRegistrationScreenOn}
recaptchaRef={recaptchaRef}
/>
)
)}

{changePasswordScreenOn && (
<ChangePasswordForm
token={token}
Expand Down Expand Up @@ -319,6 +329,11 @@ const LandingPage = (): JSX.Element => {

<PartnerLogos />
</Paper>
<ReCAPTCHA
sitekey={RECAPTCHA_SITE_KEY}
size="invisible"
ref={recaptchaRef}
/>
</>
);
};
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import React, { useState, useEffect, useRef } from 'react';
import React, { useState, useEffect } from 'react';
import { useFormik } from 'formik';
import * as Yup from 'yup';
import { useAppDispatch } from '../../hooks/redux';
Expand Down Expand Up @@ -69,22 +69,18 @@ interface FormValues {
interface SignInFormProps {
disabled?: boolean;
setRegistrationScreenOn: (active: boolean) => void;
recaptchaRef?: React.RefObject<ReCAPTCHA>;
}

const RECAPTCHA_SITE_KEY = window.Cypress
? '6LeIxAcTAAAAAJcZVRqyHh71UMIEGNQ_MXjiZKhI'
: ((process.env.RECAPTCHA_SITE_KEY ||
process.env.REACT_APP_RECAPTCHA_SITE_KEY) as string);

export default function SignInForm({
disabled,
setRegistrationScreenOn,
recaptchaRef,
}: SignInFormProps): JSX.Element {
const dispatch = useAppDispatch();
const classes = useStyles();

const [passwordVisible, setPasswordVisible] = useState(false);
const recaptchaRef = useRef<ReCAPTCHA>(null);

const validationSchema = Yup.object().shape({
email: Yup.string()
Expand All @@ -100,7 +96,7 @@ export default function SignInForm({
},
validationSchema,
onSubmit: async (values) => {
if (!recaptchaRef.current) return;
if (!recaptchaRef || !recaptchaRef.current) return;

// eslint-disable-next-line no-useless-catch
try {
Expand Down Expand Up @@ -238,7 +234,6 @@ export default function SignInForm({
>
Sign in
</Button>

<Typography className={classes.title}>
Don't have an account?{' '}
<span
Expand All @@ -248,11 +243,6 @@ export default function SignInForm({
{' '}
Sign up!
</span>
<ReCAPTCHA
sitekey={RECAPTCHA_SITE_KEY}
size="invisible"
ref={recaptchaRef}
/>
</Typography>
</form>

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import React, { useEffect, useRef, useState } from 'react';
import React, { useEffect, useState } from 'react';
import { useFormik } from 'formik';
import * as Yup from 'yup';
import { useAppDispatch } from '../../hooks/redux';
Expand Down Expand Up @@ -90,21 +90,17 @@ interface FormValues {
interface SignUpFormProps {
disabled: boolean;
setRegistrationScreenOn: (active: boolean) => void;
recaptchaRef?: React.RefObject<ReCAPTCHA>;
}

const RECAPTCHA_SITE_KEY = window.Cypress
? '6LeIxAcTAAAAAJcZVRqyHh71UMIEGNQ_MXjiZKhI'
: ((process.env.RECAPTCHA_SITE_KEY ||
process.env.REACT_APP_RECAPTCHA_SITE_KEY) as string);

export default function SignUpForm({
disabled,
setRegistrationScreenOn,
recaptchaRef,
}: SignUpFormProps): React.ReactElement {
const classes = useStyles();
const dispatch = useAppDispatch();

const recaptchaRef = useRef<ReCAPTCHA>(null);
const [passwordVisible, setPasswordVisible] = useState(false);
const [passwordStrength, setPasswordStrength] = useState(0);
const [passwordConfirmationVisible, setPasswordConfirmationVisible] =
Expand Down Expand Up @@ -161,7 +157,7 @@ export default function SignUpForm({
},
validationSchema,
onSubmit: async (values) => {
if (!recaptchaRef.current) return;
if (!recaptchaRef || !recaptchaRef.current) return;
const { email, password, isNewsletterChecked } = values;
// eslint-disable-next-line no-useless-catch
try {
Expand Down Expand Up @@ -452,12 +448,6 @@ export default function SignUpForm({
>
Sign up
</Button>
<ReCAPTCHA
sitekey={RECAPTCHA_SITE_KEY}
size="invisible"
ref={recaptchaRef}
/>

<Typography className={classes.title}>
Already have an account?{' '}
<span
Expand Down
1 change: 1 addition & 0 deletions verification/curator-service/ui/src/types/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,6 @@ export {};
declare global {
interface Window {
dataLayer: any;
Cypress: any;
}
}