-
Notifications
You must be signed in to change notification settings - Fork 34
Asub 8192/captcha2 login #1978
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
Asub 8192/captcha2 login #1978
Changes from all commits
041690a
7507276
e0ea359
2d87df7
3262d03
0b0e73e
3cca67c
8be0f19
6809a3b
b3d73fe
6c9165c
90f27b9
c1a2818
b6500e5
6c414d7
360d528
8e4f082
4847c64
57eb86f
009228d
fdc4830
a84de20
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,64 @@ | ||
| import React, { useState, useEffect } from "react"; | ||
| import { useFusionContext } from "fusion:context"; | ||
| import getProperties from "fusion:properties"; | ||
| import getTranslatedPhrases from "fusion:intl"; | ||
| import { Paragraph, useIdentity, useSales } from "@wpmedia/arc-themes-components"; | ||
| import ReCAPTCHA from "react-google-recaptcha"; | ||
|
|
||
| const BotChallengeProtection = ({ challengeIn, setCaptchaToken, className, captchaError, setCaptchaError }) => { | ||
| const { Identity, isInitialized } = useIdentity(); | ||
| const { Sales } = useSales(); | ||
| const [siteKey, setSiteKey] = useState(); | ||
|
|
||
| const onChange = (value) => { | ||
| setCaptchaToken(value); | ||
| setCaptchaError(null); | ||
| localStorage.setItem('ArcXP_captchaToken', value); | ||
| }; | ||
|
|
||
| useEffect(() => { | ||
| const checkCaptcha = async () => { | ||
| const config = await Identity.getConfig(); | ||
| const {recaptchaSiteKey, recaptchaScore } = config; | ||
| const isIdentityCaptchaEnabled = config?.[`${challengeIn}Recaptcha`]; | ||
|
|
||
| if(['signup', 'signin', 'magicLink'].includes(challengeIn)) { | ||
| if (isIdentityCaptchaEnabled && recaptchaScore === '-1' && recaptchaSiteKey) { | ||
| setSiteKey(recaptchaSiteKey); | ||
| } | ||
| } | ||
|
|
||
| if (challengeIn === 'checkout') { | ||
| const salesConfig = await Sales.getConfig(); | ||
| const isSalesCaptchaEnabled = salesConfig?.checkoutRecaptchaEnabled; | ||
| if (isSalesCaptchaEnabled && recaptchaScore === '-1' && recaptchaSiteKey) { | ||
| setSiteKey(recaptchaSiteKey); | ||
| } | ||
| } | ||
|
|
||
| }; | ||
| checkCaptcha(); | ||
|
|
||
| }, [Identity, Sales, challengeIn]); | ||
|
|
||
| const { arcSite } = useFusionContext(); | ||
| const { locale } = getProperties(arcSite); | ||
| const phrases = getTranslatedPhrases(locale); | ||
|
|
||
| if (!isInitialized) { | ||
| return null; | ||
| } | ||
|
|
||
| return ( | ||
| <section className={`${className}__bot-protection-section`} data-testid="bot-challege-protection-container"> | ||
| {!!siteKey && <ReCAPTCHA | ||
| sitekey={siteKey} | ||
| onChange={onChange} | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Checking the reCaptcha documentation if you include |
||
| onExpired={() => {}} | ||
| />} | ||
| {captchaError && <Paragraph data-testid="bot-challege-captcha-error">{phrases.t("identity-block.bot-protection-error")}</Paragraph>} | ||
| </section> | ||
| ); | ||
| }; | ||
|
|
||
| export default BotChallengeProtection; | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,50 @@ | ||
| import React from "react"; | ||
| import { render, screen } from "@testing-library/react"; | ||
| import { useIdentity } from "@wpmedia/arc-themes-components"; | ||
| import BotChallengeProtection from "."; | ||
|
|
||
| const mockLogin = jest.fn(() => Promise.resolve()); | ||
|
|
||
| const mockIdentity = { | ||
| isLoggedIn: jest.fn(() => false), | ||
| getConfig: jest.fn(() => ({})), | ||
| login: mockLogin, | ||
| }; | ||
|
|
||
| const mockSales = { | ||
| getConfig: jest.fn(() => {}) | ||
| } | ||
|
|
||
| jest.mock("@wpmedia/arc-themes-components", () => ({ | ||
| ...jest.requireActual("@wpmedia/arc-themes-components"), | ||
| useIdentity: jest.fn(() => ({ | ||
| isInitialized: true, | ||
| Identity: { | ||
| ...mockIdentity, | ||
| }, | ||
| })), | ||
| useSales: jest.fn(() => ({ | ||
| isInitialized: true, | ||
| Sales: { | ||
| ...mockSales, | ||
| }, | ||
| })), | ||
| })); | ||
|
|
||
| describe("Bot challenge protection", () => { | ||
| it("renders with required items", () => { | ||
| render(<BotChallengeProtection challengeIn="signin" />); | ||
|
|
||
| expect(screen.getByTestId("bot-challege-protection-container")).not.toBeNull(); | ||
| }); | ||
| it("it does not render if identity is not initialized", () => { | ||
| useIdentity.mockImplementation(() => ({ | ||
| isInitialized: false, | ||
| Identity: { | ||
| ...mockIdentity, | ||
| }, | ||
| })) | ||
| render(<BotChallengeProtection challengeIn="test" />); | ||
| expect(screen.queryByTestId("bot-challege-protection-container")).toBeNull(); | ||
| }); | ||
| }); |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -629,7 +629,7 @@ | |
| "bn": "কোনো অ্যাকাউন্ট নেই?\nসাইন আপ করুন", | ||
| "bo": "ཁྱེད་ལ་དྲ་གྲངས་མེད་དམ། ཐོ་འགོད།", | ||
| "de": "Sign up for an account.", | ||
| "en": "Don't have an account? Sign up", | ||
| "en": "Need to create an account? ", | ||
| "es": "Sign up for an account.", | ||
| "fr": "Sign up for an account.", | ||
| "id": "Belum memiliki akun? Daftar", | ||
|
|
@@ -1273,5 +1273,20 @@ | |
| "vi": "Tên người dùng", | ||
| "zh-CN": "用户名", | ||
| "zh-TW": "使用者名稱" | ||
| }, | ||
| "identity-block.bot-protection-error": { | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Hi @edwardcho1231 , As part of the designs we have an additional reCaptcha state when it expires. |
||
| "en": "Please verify that you are not a robot." | ||
| }, | ||
| "identity-block.email-label": { | ||
| "en": "Email" | ||
| }, | ||
| "identity-block.log-in-headline": { | ||
| "en": "Log in to your account" | ||
| }, | ||
| "identity-block.privacy-statement": { | ||
| "en": "By creating an account, you agree to the Terms of Service and acknowledge our Privacy Policy." | ||
| }, | ||
| "identity-block.sign-up-natural": { | ||
| "en": "Sign up" | ||
| } | ||
| } | ||
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@edwardcho1231 I think you can move L23-L25 into
ifon L27, thus you call config from identity or sales, depending on challengeInThere was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@LauraPinilla Don't we have to call
Identity.configeven when thechallengeIn === 'checkout'since we need the recaptchaSiteKey?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
good point @edwardcho1231 I missed that. Yep for checkout we need to call both