mirror of
https://github.com/perfect-panel/ppanel-web.git
synced 2026-08-29 05:52:08 -04:00
feat: README, config.example, turnstile integration, exchange rate, auth utils refactor
This commit is contained in:
@@ -10,4 +10,5 @@ reqwest = { version = "0.12", features = ["json"] }
|
||||
serde = { version = "1", features = ["derive"] }
|
||||
serde_json = "1"
|
||||
tokio = { version = "1", features = ["time"] }
|
||||
tracing = "0.1"
|
||||
uuid = { version = "1", features = ["v4"] }
|
||||
|
||||
@@ -54,6 +54,20 @@ pub async fn verify_with_key(
|
||||
Ok(resp.success)
|
||||
}
|
||||
|
||||
/// Guard: verify a token and return `Err(TOO_MANY_REQUESTS)` on failure.
|
||||
///
|
||||
/// Convenience wrapper used by auth service handlers — avoids repeating the
|
||||
/// same error mapping in every caller.
|
||||
pub async fn guard(secret: &str, token: &str, ip: &str) -> anyhow::Result<()> {
|
||||
let ok = verify(secret, token, ip).await.unwrap_or(false);
|
||||
if !ok {
|
||||
// Use a plain anyhow error with a sentinel message; callers in the
|
||||
// main crate map this to `error_code::TOO_MANY_REQUESTS`.
|
||||
anyhow::bail!("turnstile_failed");
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
|
||||
/// Generate a random UUID suitable for use as an idempotency key.
|
||||
pub fn random_uuid() -> String {
|
||||
uuid::Uuid::new_v4().to_string()
|
||||
|
||||
Reference in New Issue
Block a user