Skip to content

Commit

Permalink
user banning
Browse files Browse the repository at this point in the history
  • Loading branch information
benthecarman committed Dec 19, 2024
1 parent afdb1a7 commit 479dcbd
Showing 1 changed file with 23 additions and 0 deletions.
23 changes: 23 additions & 0 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -161,6 +161,17 @@ async fn main() -> anyhow::Result<()> {
Ok(())
}

fn get_banned_users() -> Vec<String> {
let mut banned_users = vec![];
let file = std::fs::read_to_string("banned_users.txt");
if let Ok(file) = file {
for line in file.lines() {
banned_users.push(line.to_string());
}
}
banned_users
}

#[axum::debug_handler]
async fn github_auth(Extension(state): Extension<AppState>) -> Result<Redirect, AppError> {
let redirect_url = format!(
Expand Down Expand Up @@ -254,6 +265,10 @@ async fn onchain_handler(
headers: HeaderMap,
Json(payload): Json<OnchainRequest>,
) -> Result<Json<OnchainResponse>, AppError> {
if get_banned_users().contains(&user.username) {
return Err(AppError::new("You are banned"));
}

// Extract the X-Forwarded-For header
let x_forwarded_for = headers
.get("x-forwarded-for")
Expand Down Expand Up @@ -284,6 +299,10 @@ async fn lightning_handler(
headers: HeaderMap,
Json(payload): Json<LightningRequest>,
) -> Result<Json<LightningResponse>, AppError> {
if get_banned_users().contains(&user.username) {
return Err(AppError::new("You are banned"));
}

// Extract the X-Forwarded-For header
let x_forwarded_for = headers
.get("x-forwarded-for")
Expand Down Expand Up @@ -366,6 +385,10 @@ async fn channel_handler(
headers: HeaderMap,
Json(payload): Json<ChannelRequest>,
) -> Result<Json<ChannelResponse>, AppError> {
if get_banned_users().contains(&user.username) {
return Err(AppError::new("You are banned"));
}

// Extract the X-Forwarded-For header
let x_forwarded_for = headers
.get("x-forwarded-for")
Expand Down

0 comments on commit 479dcbd

Please sign in to comment.