Skip to content

Commit 5405b69

Browse files
author
David Warwick
committed
Improve CAPTCHA logic and update .NET SDK installer
Updated Survey.razor to ensure CAPTCHA runs only in browsers by adding `OperatingSystem.IsBrowser()` to the condition. Enhanced debugging in Survey.razor.cs with additional Console.WriteLine statements for better logging of rendering and data loading processes. Replaced the .NET 9 SDK installer script with a new script for installing the .NET 10 SDK, reflecting the latest version and providing updated setup instructions.
1 parent fd4c0f7 commit 5405b69

File tree

3 files changed

+18
-6
lines changed

3 files changed

+18
-6
lines changed

JwtIdentity.Client/Pages/Survey/Survey.razor

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
<PageTitle>Survey Shark - Survey</PageTitle>
66

77
<div class="survey-container">
8-
@if (!isCaptchaVerified && !Preview && !ViewAnswers)
8+
@if (OperatingSystem.IsBrowser() && !isCaptchaVerified && !Preview && !ViewAnswers)
99
{
1010
<MudText Typo="Typo.h5" Class="mb-4" Align="Align.Center">Verification Required</MudText>
1111
<!-- reCAPTCHA widget with data-callback pointing to our JS function -->

JwtIdentity.Client/Pages/Survey/Survey.razor.cs

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -162,18 +162,29 @@ protected override async Task OnInitializedAsync()
162162

163163
protected override async Task OnAfterRenderAsync(bool firstRender)
164164
{
165+
Console.WriteLine("Render 1");
165166
// Only run JavaScript on the first render in the browser (not during prerendering)
166167
if (!firstRender || !OperatingSystem.IsBrowser())
167168
{
168169
return;
169170
}
170171

172+
Console.WriteLine("Render 2");
173+
174+
Console.WriteLine($"Survey != null: {Survey != null}");
175+
Console.WriteLine($"Survey.Id > 0: {(Survey?.Id ?? 0) > 0}");
176+
Console.WriteLine($"!Preview: {!Preview}");
177+
Console.WriteLine($"!ViewAnswers: {!ViewAnswers}");
178+
Console.WriteLine($"!isCaptchaVerified: {!isCaptchaVerified}");
179+
171180
// Captcha JS – only if we actually need it
172181
if (Survey != null && Survey.Id > 0 && !Preview && !ViewAnswers && !isCaptchaVerified)
173182
{
183+
Console.WriteLine("Render 3");
174184
objRef ??= DotNetObjectReference.Create(this);
175185
await JSRuntime.InvokeVoidAsync("registerCaptchaCallback", objRef);
176186
await JSRuntime.InvokeVoidAsync("renderReCaptcha", "captcha-container", Configuration["ReCaptcha:SiteKey"]);
187+
Console.WriteLine("Render 4");
177188
}
178189

179190
// Demo scroll
@@ -211,7 +222,7 @@ internal async Task LoadData()
211222
{
212223
// get the survey based on the SurveyId
213224
Survey = await ApiService.GetAsync<SurveyViewModel>($"{ApiEndpoints.Answer}/getanswersforsurveyforloggedinuser/{SurveyId}?Preview={Preview || ViewAnswers}");
214-
225+
Console.WriteLine("LoadData complete");
215226
if (Survey != null && Survey.Id > 0)
216227
{
217228
foreach (var question in Survey.Questions)
@@ -1108,13 +1119,14 @@ protected void CompleteBranchingDemo()
11081119
}
11091120

11101121
private async Task EnsureInitializedAsync()
1111-
{
1122+
{
11121123
if (_initialized)
11131124
return;
11141125

11151126
_initialized = true;
11161127

11171128
await HandleLoggingInUser();
1129+
Console.WriteLine("Loading survey data...");
11181130
await LoadData();
11191131
Loading = false;
11201132
}
Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,15 @@
11
#!/usr/bin/env bash
22
set -euo pipefail
33

4-
# Installs the latest .NET 9 SDK using Microsoft's official installer.
4+
# Installs the latest .NET 10 SDK using Microsoft's official installer.
55
# If DOTNET_INSTALL_DIR is set, the SDK will be installed there; otherwise it defaults to $HOME/.dotnet.
66
INSTALL_DIR="${DOTNET_INSTALL_DIR:-$HOME/.dotnet}"
77

8-
curl -sSL https://dot.net/v1/dotnet-install.sh | bash /dev/stdin --channel 9.0 --install-dir "$INSTALL_DIR"
8+
curl -sSL https://dot.net/v1/dotnet-install.sh | bash /dev/stdin --channel 10.0 --install-dir "$INSTALL_DIR"
99

1010
cat <<EOM
1111
12-
.NET 9 SDK installed to $INSTALL_DIR
12+
.NET 10 SDK installed to $INSTALL_DIR
1313
Add the following to your shell profile to use it:
1414
export DOTNET_ROOT="$INSTALL_DIR"
1515
export PATH="\$DOTNET_ROOT:\$PATH"

0 commit comments

Comments
 (0)