mirror of
https://github.com/MvDevsUnion/WPetition.git
synced 2026-07-14 19:40:08 +00:00
changes for easier dev setup
This commit is contained in:
@@ -1,5 +1,7 @@
|
|||||||
using Ashi.MongoInterface.Service;
|
using Ashi.MongoInterface.Service;
|
||||||
using Microsoft.AspNetCore.Mvc;
|
using Microsoft.AspNetCore.Mvc;
|
||||||
|
using Microsoft.AspNetCore.Hosting;
|
||||||
|
using Microsoft.Extensions.Hosting;
|
||||||
using Microsoft.AspNetCore.RateLimiting;
|
using Microsoft.AspNetCore.RateLimiting;
|
||||||
using Microsoft.Extensions.Caching.Memory;
|
using Microsoft.Extensions.Caching.Memory;
|
||||||
using Microsoft.Extensions.Options;
|
using Microsoft.Extensions.Options;
|
||||||
@@ -164,16 +166,23 @@ namespace Submission.Api.Controllers
|
|||||||
{
|
{
|
||||||
private readonly HttpClient _httpClient;
|
private readonly HttpClient _httpClient;
|
||||||
private readonly string _secretKey;
|
private readonly string _secretKey;
|
||||||
|
private readonly IWebHostEnvironment _env;
|
||||||
private const string SiteverifyUrl = "https://challenges.cloudflare.com/turnstile/v0/siteverify";
|
private const string SiteverifyUrl = "https://challenges.cloudflare.com/turnstile/v0/siteverify";
|
||||||
|
|
||||||
public TurnstileService(HttpClient httpClient, IOptions<TurnstileSettings> options)
|
public TurnstileService(HttpClient httpClient, IOptions<TurnstileSettings> options, IWebHostEnvironment env)
|
||||||
{
|
{
|
||||||
_httpClient = httpClient;
|
_httpClient = httpClient;
|
||||||
_secretKey = options?.Value?.SecretKey ?? throw new ArgumentNullException(nameof(options), "Turnstile:SecretKey must be configured in appsettings.json");
|
_secretKey = options?.Value?.SecretKey ?? throw new ArgumentNullException(nameof(options), "Turnstile:SecretKey must be configured in appsettings.json");
|
||||||
|
_env = env;
|
||||||
}
|
}
|
||||||
|
|
||||||
public async Task<TurnstileResponse> ValidateTokenAsync(string token, string remoteip = null)
|
public async Task<TurnstileResponse> ValidateTokenAsync(string token, string remoteip = null)
|
||||||
{
|
{
|
||||||
|
if (_env.IsDevelopment() && token == "DEV_BYPASS_TOKEN")
|
||||||
|
{
|
||||||
|
return new TurnstileResponse { Success = true };
|
||||||
|
}
|
||||||
|
|
||||||
var parameters = new Dictionary<string, string>
|
var parameters = new Dictionary<string, string>
|
||||||
{
|
{
|
||||||
{ "secret", _secretKey },
|
{ "secret", _secretKey },
|
||||||
@@ -214,7 +223,7 @@ namespace Submission.Api.Controllers
|
|||||||
[JsonPropertyName("success")]
|
[JsonPropertyName("success")]
|
||||||
public bool Success { get; set; }
|
public bool Success { get; set; }
|
||||||
|
|
||||||
// Cloudflare returns "error-codes" (with a hyphen) — map it explicitly
|
// Cloudflare returns "error-codes" (with a hyphen) — map it explicitly
|
||||||
[JsonPropertyName("error-codes")]
|
[JsonPropertyName("error-codes")]
|
||||||
public string[] ErrorCodes { get; set; }
|
public string[] ErrorCodes { get; set; }
|
||||||
|
|
||||||
|
|||||||
+17
-1
@@ -1,4 +1,13 @@
|
|||||||
services:
|
services:
|
||||||
|
mongodb:
|
||||||
|
image: mongo:7
|
||||||
|
networks:
|
||||||
|
- app-network
|
||||||
|
ports:
|
||||||
|
- "27017:27017"
|
||||||
|
volumes:
|
||||||
|
- mongodb_data:/data/db
|
||||||
|
|
||||||
submission.api:
|
submission.api:
|
||||||
image: submission.api
|
image: submission.api
|
||||||
build:
|
build:
|
||||||
@@ -8,9 +17,14 @@
|
|||||||
- app-network
|
- app-network
|
||||||
expose:
|
expose:
|
||||||
- "8080"
|
- "8080"
|
||||||
|
depends_on:
|
||||||
|
- mongodb
|
||||||
environment:
|
environment:
|
||||||
|
- ASPNETCORE_ENVIRONMENT=Development
|
||||||
- ASPNETCORE_URLS=http://+:8080
|
- ASPNETCORE_URLS=http://+:8080
|
||||||
- MongoDbSettings__ConnectionString=mongodb://host.docker.internal:27017
|
- MongoDbSettings__ConnectionString=mongodb://mongodb:27017
|
||||||
|
- MongoDbSettings__DatabaseName=petition_database
|
||||||
|
- PetitionSettings__AllowPetitionCreation=true
|
||||||
|
|
||||||
nginx:
|
nginx:
|
||||||
image: petition-nginx
|
image: petition-nginx
|
||||||
@@ -28,3 +42,5 @@ networks:
|
|||||||
app-network:
|
app-network:
|
||||||
driver: bridge
|
driver: bridge
|
||||||
|
|
||||||
|
volumes:
|
||||||
|
mongodb_data:
|
||||||
|
|||||||
Reference in New Issue
Block a user