Files
Sharpbin/PasteBin/Turnstile.cs
T
whoswhip 46615aba5b Refactor endpoints and update HTML for new API
Simplified /archive endpoint to return static HTML without dynamic content or database queries. Refactored CreatePaste method to accept a Paste object and conditionally write compressed or uncompressed content based on size. Added new /api/pastes/get endpoint for fetching paginated pastes in JSON format.

Updated archives.html to remove dynamic placeholders, using JavaScript for fetching and displaying pastes, and handling user authentication and pagination. Improved index.html with new font family and font weight for buttons. Updated paste.html to truncate long paste titles for display.

Removed unused using directive in Turnstile.cs. Updated Program.cs to include new API endpoint and refactored CreatePaste method.
2024-10-25 16:40:26 -04:00

34 lines
1.1 KiB
C#

using Newtonsoft.Json.Linq;
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());
if (jsonresponse["success"]?.ToString().ToLower() == "true")
{
return true;
}
return false;
}
}
}
}