diff --git a/DysonNetwork.Sphere/Account/EmailService.cs b/DysonNetwork.Sphere/Account/EmailService.cs index 492c105..159c40a 100644 --- a/DysonNetwork.Sphere/Account/EmailService.cs +++ b/DysonNetwork.Sphere/Account/EmailService.cs @@ -20,7 +20,7 @@ public class EmailService public EmailService(IConfiguration configuration) { - var cfg = configuration.GetValue("Email"); + var cfg = configuration.GetSection("Email").Get(); _configuration = cfg ?? throw new ArgumentException("Email service was not configured."); } diff --git a/DysonNetwork.Sphere/Account/MagicSpellService.cs b/DysonNetwork.Sphere/Account/MagicSpellService.cs index 98c35cc..48aecee 100644 --- a/DysonNetwork.Sphere/Account/MagicSpellService.cs +++ b/DysonNetwork.Sphere/Account/MagicSpellService.cs @@ -44,7 +44,7 @@ public class MagicSpellService(AppDatabase db, EmailService email, ILogger(json); + var result = JsonSerializer.Deserialize(json, options: jsonOpts); - return cfResult?.Success == true; + return result?.Success == true; case "google": content = new StringContent($"secret={apiSecret}&response={token}", System.Text.Encoding.UTF8, "application/x-www-form-urlencoded"); @@ -45,9 +51,19 @@ public class AuthService(IConfiguration config, IHttpClientFactory httpClientFac response.EnsureSuccessStatusCode(); json = await response.Content.ReadAsStringAsync(); - var capResult = JsonSerializer.Deserialize(json); + result = JsonSerializer.Deserialize(json, options: jsonOpts); - return capResult?.Success == true; + return result?.Success == true; + case "hcaptcha": + content = new StringContent($"secret={apiSecret}&response={token}", System.Text.Encoding.UTF8, + "application/x-www-form-urlencoded"); + response = await client.PostAsync("https://hcaptcha.com/siteverify", content); + response.EnsureSuccessStatusCode(); + + json = await response.Content.ReadAsStringAsync(); + result = JsonSerializer.Deserialize(json, options: jsonOpts); + + return result?.Success == true; default: throw new ArgumentException("The server misconfigured for the captcha."); } diff --git a/DysonNetwork.Sphere/Auth/CheckpointModel.cs b/DysonNetwork.Sphere/Auth/CheckpointModel.cs index bb74632..3b4ea12 100644 --- a/DysonNetwork.Sphere/Auth/CheckpointModel.cs +++ b/DysonNetwork.Sphere/Auth/CheckpointModel.cs @@ -1,17 +1,6 @@ namespace DysonNetwork.Sphere.Auth; -public class CloudflareVerificationResponse +public class CaptchaVerificationResponse { public bool Success { get; set; } - public string[]? ErrorCodes { get; set; } -} - -public class GoogleVerificationResponse -{ - public bool Success { get; set; } - public float Score { get; set; } - public string Action { get; set; } - public DateTime ChallengeTs { get; set; } - public string Hostname { get; set; } - public string[]? ErrorCodes { get; set; } } \ No newline at end of file diff --git a/DysonNetwork.Sphere/Pages/CheckpointPage.cshtml b/DysonNetwork.Sphere/Pages/Checkpoint/CheckpointPage.cshtml similarity index 90% rename from DysonNetwork.Sphere/Pages/CheckpointPage.cshtml rename to DysonNetwork.Sphere/Pages/Checkpoint/CheckpointPage.cshtml index de1a2f1..e6984d4 100644 --- a/DysonNetwork.Sphere/Pages/CheckpointPage.cshtml +++ b/DysonNetwork.Sphere/Pages/Checkpoint/CheckpointPage.cshtml @@ -1,5 +1,5 @@ @page "/auth/captcha" -@model DysonNetwork.Sphere.Pages.CheckpointPage +@model DysonNetwork.Sphere.Pages.Checkpoint.CheckpointPage @{ Layout = null; @@ -73,6 +73,9 @@ defer > break; + case "hcaptcha": + + break; } @@ -95,6 +98,13 @@ data-callback="onSuccess" > break; + case "hcaptcha": +
+ break; default:

Captcha provider not configured correctly.

break; diff --git a/DysonNetwork.Sphere/Pages/CheckpointPage.cshtml.cs b/DysonNetwork.Sphere/Pages/Checkpoint/CheckpointPage.cshtml.cs similarity index 70% rename from DysonNetwork.Sphere/Pages/CheckpointPage.cshtml.cs rename to DysonNetwork.Sphere/Pages/Checkpoint/CheckpointPage.cshtml.cs index b467290..69f53e9 100644 --- a/DysonNetwork.Sphere/Pages/CheckpointPage.cshtml.cs +++ b/DysonNetwork.Sphere/Pages/Checkpoint/CheckpointPage.cshtml.cs @@ -1,13 +1,14 @@ using Microsoft.AspNetCore.Mvc; using Microsoft.AspNetCore.Mvc.RazorPages; -namespace DysonNetwork.Sphere.Pages; +namespace DysonNetwork.Sphere.Pages.Checkpoint; public class CheckpointPage(IConfiguration configuration) : PageModel { [BindProperty] public IConfiguration Configuration { get; set; } = configuration; - public void OnGet() + public ActionResult OnGet() { + return Page(); } } \ No newline at end of file diff --git a/DysonNetwork.Sphere/Pages/MagicSpellPage.cshtml b/DysonNetwork.Sphere/Pages/Spell/MagicSpellPage.cshtml similarity index 93% rename from DysonNetwork.Sphere/Pages/MagicSpellPage.cshtml rename to DysonNetwork.Sphere/Pages/Spell/MagicSpellPage.cshtml index f86b5dd..d6eb888 100644 --- a/DysonNetwork.Sphere/Pages/MagicSpellPage.cshtml +++ b/DysonNetwork.Sphere/Pages/Spell/MagicSpellPage.cshtml @@ -1,6 +1,6 @@ @page "/spells/{spellWord}" @using DysonNetwork.Sphere.Account -@model DysonNetwork.Sphere.Pages.MagicSpellPage +@model DysonNetwork.Sphere.Pages.Spell.MagicSpellPage @{ Layout = null; @@ -8,8 +8,6 @@ var spell = ViewData["Spell"] as MagicSpell; } - - @@ -57,10 +55,6 @@ margin-bottom: 5px; opacity: 0.8; } - - .g-recaptcha { - display: inline-block; /* Adjust as needed */ - } diff --git a/DysonNetwork.Sphere/Pages/MagicSpellPage.cshtml.cs b/DysonNetwork.Sphere/Pages/Spell/MagicSpellPage.cshtml.cs similarity index 63% rename from DysonNetwork.Sphere/Pages/MagicSpellPage.cshtml.cs rename to DysonNetwork.Sphere/Pages/Spell/MagicSpellPage.cshtml.cs index 10ae3b9..a11ebdd 100644 --- a/DysonNetwork.Sphere/Pages/MagicSpellPage.cshtml.cs +++ b/DysonNetwork.Sphere/Pages/Spell/MagicSpellPage.cshtml.cs @@ -4,21 +4,27 @@ using Microsoft.AspNetCore.Mvc.RazorPages; using Microsoft.EntityFrameworkCore; using NodaTime; -namespace DysonNetwork.Sphere.Pages; +namespace DysonNetwork.Sphere.Pages.Spell; public class MagicSpellPage(AppDatabase db, MagicSpellService spells) : PageModel { - public async Task OnGet(string spellWord) + public async Task OnGetAsync(string spellWord) { + spellWord = Uri.UnescapeDataString(spellWord); var now = SystemClock.Instance.GetCurrentInstant(); var spell = await db.MagicSpells .Where(e => e.Spell == spellWord) - .Where(e => e.ExpiresAt == null || now >= e.ExpiresAt) + .Where(e => e.ExpiresAt == null || now < e.ExpiresAt) .Where(e => e.AffectedAt == null || now >= e.AffectedAt) .FirstOrDefaultAsync(); ViewData["Spell"] = spell; + if (spell is not null) + { + await spells.ApplyMagicSpell(spell); + } + return Page(); } } \ No newline at end of file diff --git a/DysonNetwork.Sphere/appsettings.json b/DysonNetwork.Sphere/appsettings.json index dedc37b..2a3d0fb 100644 --- a/DysonNetwork.Sphere/appsettings.json +++ b/DysonNetwork.Sphere/appsettings.json @@ -45,8 +45,8 @@ ] }, "Captcha": { - "Provider": "recaptcha", - "ApiKey": "6LfIzSArAAAAAN413MtycDcPlKa636knBSAhbzj-", + "Provider": "cloudflare", + "ApiKey": "0x4AAAAAABCDUdOujj4feOb_", "ApiSecret": "" }, "Notifications": { @@ -62,12 +62,12 @@ } }, "Email": { - "Server": "", + "Server": "smtpdm.aliyun.com", "Port": 465, - "Username": "", + "Username": "no-reply@mail.solsynth.dev", "Password": "", - "FromAddress": "", - "FromName": "", + "FromAddress": "no-reply@mail.solsynth.dev", + "FromName": "Alphabot", "SubjectPrefix": "Solar Network" } } diff --git a/DysonNetwork.sln.DotSettings.user b/DysonNetwork.sln.DotSettings.user index cd7f0b2..5645117 100644 --- a/DysonNetwork.sln.DotSettings.user +++ b/DysonNetwork.sln.DotSettings.user @@ -28,6 +28,7 @@ ForceIncluded ForceIncluded ForceIncluded + ForceIncluded ForceIncluded ForceIncluded ForceIncluded