mirror of
https://github.com/whoswhip/Sharpbin.git
synced 2026-12-06 02:48:43 +00:00
Add Cloudflare Turnstile integration and update UI titles
- Program.cs: Added static fields for Turnstile keys, updated login HTML, added token validation in login and sign-up endpoints, and updated configuration loading. - admin.html, dash.html: Changed title to "dashboard". - login.html, signup.html: Added Turnstile script and widget, updated form submission, and added styles/JS for token handling. - user.html: Adjusted width of .pastes-wrapper. - Turnstile.cs: Added Turnstile class with VerifyTurnstileToken method for token verification via Cloudflare API.
This commit is contained in:
@@ -0,0 +1,36 @@
|
||||
using Newtonsoft.Json.Linq;
|
||||
using System;
|
||||
using System.Net.Http;
|
||||
using System.Text;
|
||||
|
||||
namespace Sharpbin
|
||||
{
|
||||
public class Turnstile
|
||||
{
|
||||
public static async Task<bool> VerifyTurnstileToken(string token)
|
||||
{
|
||||
var httpClient = new HttpClient();
|
||||
JObject requestBody = new JObject
|
||||
{
|
||||
["secret"] = Program.cfTurnstileSecret,
|
||||
["response"] = token
|
||||
};
|
||||
var request = new HttpRequestMessage
|
||||
{
|
||||
Method = HttpMethod.Post,
|
||||
RequestUri = new Uri("https://challenges.cloudflare.com/turnstile/v0/siteverify"),
|
||||
Content = new StringContent(requestBody.ToString(), Encoding.UTF8, "application/json")
|
||||
};
|
||||
using (var response = await httpClient.SendAsync(request))
|
||||
{
|
||||
var jsonresponse = JObject.Parse(await response.Content.ReadAsStringAsync());
|
||||
Console.WriteLine(jsonresponse["success"]?.ToString());
|
||||
if (jsonresponse["success"]?.ToString().ToLower() == "true")
|
||||
{
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user