simple ban system for admins (to be replaced later)
Some checks failed
Build and Test / account (push) Failing after 1m15s

This commit is contained in:
red binder 2026-07-04 19:26:28 +02:00
commit ea5f9d1c13
5 changed files with 44 additions and 5 deletions

View file

@ -0,0 +1,39 @@
use rocket::serde::json::Json;
use rocket::{post, FromForm, State};
use rocket::form::Form;
use rocket::futures::TryFutureExt;
use rocket::http::Status;
use crate::account::account::Auth;
use crate::json_api::oauth::generate_token::TokenRequest;
use crate::nnid::people::{build_oauth_profile, GetOwnOAuthProfileData};
use crate::Pool;
#[derive(FromForm)]
pub struct AdminRequest<'r> {
pub username: &'r str,
}
#[post("/api/v2/admin/ban", data = "<request>")]
pub async fn ban_user(pool: &State<Pool>, auth: Auth<true>, request: Form<AdminRequest<'_>>) -> Result<(), Status> {
if auth.account_level < 2 {
return Err(Status::Forbidden);
};
log::info!("banning user {:?} from moderator {:?}", request.username, auth.username);
let row = sqlx::query!(
"UPDATE users SET account_level = $1 WHERE username = $2",
-1,
request.username
)
.execute(pool.inner())
.await
.map_err(|e| {
log::error!("failed to execute query: {:?}", e);
return Err::<(), rocket::http::Status>(Status::InternalServerError);
});
log::info!("banned user {:?}", request.username);
Ok(())
}

View file

@ -0,0 +1 @@
pub mod bans;

View file

@ -1,2 +1,3 @@
pub mod oauth;
pub mod users;
pub mod users;
pub mod admin;

View file

@ -41,10 +41,7 @@ pub fn verify_nintendo_password(pid: i32, text_password: &str, db_bcrypt_hash: &
sha.update(&[0x02, 0x65, 0x43, 0x46]);
sha.update(text_password.as_bytes());
let hashed_password_hex = hex::encode(sha.finalize());
match bcrypt::verify(hashed_password_hex, db_bcrypt_hash) {
Ok(valid) => valid,
Err(_) => false,
}
bcrypt::verify(hashed_password_hex, db_bcrypt_hash).unwrap_or_else(|_| false)
}
// dummy error responses

View file

@ -118,6 +118,7 @@ async fn launch() -> _ {
json_api::users::delete::delete_account,
json_api::oauth::authorize::authorize_page,
json_api::oauth::authorize::authorize_submit,
json_api::admin::bans::ban_user,
nnid::people::thing,
// graphql::graphiql,
// graphql::playground,