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 ccafede
Showing 1 changed file with 20 additions and 0 deletions.
20 changes: 20 additions & 0 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -161,6 +161,14 @@ async fn main() -> anyhow::Result<()> {
Ok(())
}

fn get_banned_users() -> Vec<String> {
let mut banned_users = vec![];
for line in std::fs::read_to_string("banned_users.txt").unwrap().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 +262,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 +296,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 +382,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 ccafede

Please sign in to comment.