Removed unneeded imports
This commit is contained in:
@@ -1,4 +1,4 @@
|
||||
use std::{sync::Arc, usize};
|
||||
use std::sync::Arc;
|
||||
|
||||
use argon2::{
|
||||
Argon2, PasswordHash, PasswordHasher, PasswordVerifier,
|
||||
@@ -11,7 +11,6 @@ use axum::{
|
||||
response::IntoResponse,
|
||||
};
|
||||
use axum_extra::extract::cookie::{Cookie, SameSite};
|
||||
use chrono::format;
|
||||
use jsonwebtoken::{EncodingKey, Header};
|
||||
use serde_json::json;
|
||||
|
||||
@@ -485,15 +484,16 @@ pub async fn update_user(
|
||||
pub async fn check_admin_exists(
|
||||
State(data): State<Arc<AppState>>,
|
||||
) -> Result<impl IntoResponse, (StatusCode, Json<serde_json::Value>)> {
|
||||
let admin_count = sqlx::query_scalar::<_, i64>(r#"SELECT COUNT(*) FROM users WHERE is_admin = true"#)
|
||||
.fetch_one(&data.db)
|
||||
.await
|
||||
.map_err(|e| {
|
||||
(
|
||||
StatusCode::INTERNAL_SERVER_ERROR,
|
||||
Json(json!({"status": "error", "message": format!("{:?}", e)})),
|
||||
)
|
||||
})?;
|
||||
let admin_count =
|
||||
sqlx::query_scalar::<_, i64>(r#"SELECT COUNT(*) FROM users WHERE is_admin = true"#)
|
||||
.fetch_one(&data.db)
|
||||
.await
|
||||
.map_err(|e| {
|
||||
(
|
||||
StatusCode::INTERNAL_SERVER_ERROR,
|
||||
Json(json!({"status": "error", "message": format!("{:?}", e)})),
|
||||
)
|
||||
})?;
|
||||
|
||||
let has_admin = admin_count > 0;
|
||||
Ok(Json(json!({"has_admin": has_admin})))
|
||||
@@ -528,15 +528,16 @@ pub async fn setup_initial_admin(
|
||||
Json(request): Json<UserCreateScheme>,
|
||||
) -> Result<impl IntoResponse, (StatusCode, Json<serde_json::Value>)> {
|
||||
// Check if any admin already exists
|
||||
let admin_count = sqlx::query_scalar::<_, i64>(r#"SELECT COUNT(*) FROM users WHERE is_admin = true"#)
|
||||
.fetch_one(&data.db)
|
||||
.await
|
||||
.map_err(|e| {
|
||||
(
|
||||
StatusCode::INTERNAL_SERVER_ERROR,
|
||||
Json(json!({"status": "error", "message": format!("{:?}", e)})),
|
||||
)
|
||||
})?;
|
||||
let admin_count =
|
||||
sqlx::query_scalar::<_, i64>(r#"SELECT COUNT(*) FROM users WHERE is_admin = true"#)
|
||||
.fetch_one(&data.db)
|
||||
.await
|
||||
.map_err(|e| {
|
||||
(
|
||||
StatusCode::INTERNAL_SERVER_ERROR,
|
||||
Json(json!({"status": "error", "message": format!("{:?}", e)})),
|
||||
)
|
||||
})?;
|
||||
|
||||
if admin_count > 0 {
|
||||
return Err((
|
||||
@@ -580,7 +581,9 @@ pub async fn setup_initial_admin(
|
||||
Json(json!({"status": "error", "message": "Error creating admin user"})),
|
||||
));
|
||||
} else {
|
||||
Ok(Json(json!({"status": "success", "result": "Admin user created"})))
|
||||
Ok(Json(
|
||||
json!({"status": "success", "result": "Admin user created"}),
|
||||
))
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user