Skip to content

Commit

Permalink
Fix google recaptcha issue when project has api parameter is false
Browse files Browse the repository at this point in the history
  • Loading branch information
ysmoradi committed Apr 20, 2024
1 parent 67ea3e5 commit 5689a20
Show file tree
Hide file tree
Showing 11 changed files with 28 additions and 37 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,12 @@
"format": "yyyy-MM-dd"
}
},
"api": {
"displayName": "Add API to Server project?",
"type": "parameter",
"datatype": "bool",
"defaultValue": "true"
},
"database": {
"displayName": "Backend database",
"type": "parameter",
Expand Down Expand Up @@ -123,12 +129,6 @@
"datatype": "bool",
"defaultValue": "false"
},
"api": {
"displayName": "Add API to Server project?",
"type": "parameter",
"datatype": "bool",
"defaultValue": "true"
},
"appInsights": {
"displayName": "Add Azure application insights to project?",
"type": "parameter",
Expand Down Expand Up @@ -277,6 +277,9 @@
"src/Boilerplate.Server/Services/AppSecureJwtDataFormat.cs",
"src/Boilerplate.Server/wwwroot/swagger/**",
"src/Boilerplate.Server/AppSettings.cs",
"src/Boilerplate.Server/Services/GoogleRecaptchaHttpClient.cs",
"src/Boilerplate.Server/Services/GoogleRecaptchaVerificationResponse.cs",
"src/Boilerplate.Server/Services/ServerJsonContext.cs",
"src/Boilerplate.Server/IdentityCertificate.pfx"
]
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -144,10 +144,12 @@ private static void ConfigureServices(this WebApplicationBuilder builder)

AddBlazor(builder);

//#if (api == true)
services.AddHttpClient<GoogleRecaptchaHttpClient>(c =>
{
c.BaseAddress = new Uri("https://www.google.com/recaptcha/");
});
//#endif
}

private static void AddBlazor(WebApplicationBuilder builder)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,6 @@ public async ValueTask<bool> Verify(string? googleRecaptchaResponse)

var result = await response.Content.ReadFromJsonAsync(ServerJsonContext.Default.GoogleRecaptchaVerificationResponse);

return result?.Success ?? false;
return result?.Success is true;
}
}

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

Original file line number Diff line number Diff line change
Expand Up @@ -583,7 +583,4 @@
<data name="InvalidGoogleRecaptchaChallenge" xml:space="preserve">
<value>شما باید چالش گوگل ریکپچا را به سرانجام برسانید.</value>
</data>
<data name="ResetRecaptcha" xml:space="preserve">
<value>بازنشانی ریکپجا</value>
</data>
</root>
Original file line number Diff line number Diff line change
Expand Up @@ -582,7 +582,4 @@
<data name="InvalidGoogleRecaptchaChallenge" xml:space="preserve">
<value>Vous devez réussir le défi Google reCAPTCHA.</value>
</data>
<data name="ResetRecaptcha" xml:space="preserve">
<value>Réinitialiser reCAPTCHA</value>
</data>
</root>
Original file line number Diff line number Diff line change
Expand Up @@ -590,9 +590,6 @@ Please confirm your email by clicking on the link.</value>
</data>
<data name="InvalidGoogleRecaptchaChallenge" xml:space="preserve">
<value>You need to pass the Google reCAPTCHA challenge.</value>
</data>
<data name="ResetRecaptcha" xml:space="preserve">
<value>Reset reCAPTCHA</value>
</data>
<!--#endif -->
</root>
Original file line number Diff line number Diff line change
Expand Up @@ -43,11 +43,14 @@ private async Task DoSubmit()

forgotPasswordMessage = e.Message;
}
catch
{
await JSRuntime.GoogleRecaptchaReset();
throw;
}
finally
{
isLoading = false;

await JSRuntime.GoogleRecaptchaReset();
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,4 @@
</script>
<script src="https://www.google.com/recaptcha/api.js?onload=onloadCallback&render=explicit&hl=@(CultureInfo.CurrentUICulture.TwoLetterISOLanguageName)" async defer></script>

<div id="grecaptcha_element" data-sitekey="@(Configuration.GetValue<string>("GoogleRecaptchaSiteKey"))"></div>

<BitIconButton OnClick="@(() => _ = JSRuntime.GoogleRecaptchaReset())"
ButtonType="BitButtonType.Button"
IconName="@BitIconName.Reset"
Title="@Localizer[nameof(AppStrings.ResetRecaptcha)]" />
<div id="grecaptcha_element" data-sitekey="@(Configuration.GetValue<string>("GoogleRecaptchaSiteKey"))"></div>
Original file line number Diff line number Diff line change
Expand Up @@ -51,11 +51,14 @@ private async Task DoSignIn()

signInMessage = e.Message;
}
catch
{
await JSRuntime.GoogleRecaptchaReset();
throw;
}
finally
{
isLoading = false;

await JSRuntime.GoogleRecaptchaReset();
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,11 +71,14 @@ private async Task DoResendLink()
signUpMessage = e.Message;
signUpMessageType = BitMessageBarType.Error;
}
catch
{
await JSRuntime.GoogleRecaptchaReset();
throw;
}
finally
{
isLoading = false;

await JSRuntime.GoogleRecaptchaReset();
}
}
}

0 comments on commit 5689a20

Please sign in to comment.