Sessions Route + Password Auth (#649)

* Sessions Route + Password Auth

* run prep + fix clippy

* changing passwords + logging in

* register login
This commit is contained in:
Geometrically
2023-07-08 14:29:17 -07:00
committed by GitHub
parent ef9c90a43a
commit 6c0ad7fe1a
39 changed files with 1777 additions and 1206 deletions

41
src/util/captcha.rs Normal file
View File

@@ -0,0 +1,41 @@
use crate::routes::ApiError;
use crate::util::env::parse_var;
use actix_web::HttpRequest;
use serde::Deserialize;
use serde_json::json;
pub async fn check_turnstile_captcha(req: &HttpRequest, challenge: &str) -> Result<bool, ApiError> {
let conn_info = req.connection_info().clone();
let ip_addr = if parse_var("CLOUDFLARE_INTEGRATION").unwrap_or(false) {
if let Some(header) = req.headers().get("CF-Connecting-IP") {
header.to_str().ok()
} else {
conn_info.peer_addr()
}
} else {
conn_info.peer_addr()
};
let client = reqwest::Client::new();
#[derive(Deserialize)]
struct Response {
success: bool,
}
let val: Response = client
.post("https://challenges.cloudflare.com/turnstile/v0/siteverify")
.json(&json!({
"secret": dotenvy::var("TURNSTILE_SECRET")?,
"response": challenge,
"remoteip": ip_addr,
}))
.send()
.await
.map_err(|_| ApiError::Turnstile)?
.json()
.await
.map_err(|_| ApiError::Turnstile)?;
Ok(val.success)
}

View File

@@ -1,3 +1,4 @@
pub mod captcha;
pub mod env;
pub mod ext;
pub mod guards;

View File

@@ -260,9 +260,7 @@ pub async fn send_discord_webhook(
})
.send()
.await
.map_err(|_| {
ApiError::DiscordError("Error while sending projects webhook".to_string())
})?;
.map_err(|_| ApiError::Discord("Error while sending projects webhook".to_string()))?;
}
Ok(())