mirror of
https://github.com/flibusta-apps/services_manager_server.git
synced 2025-12-06 04:25:38 +01:00
Reject duplicate service token on create
This commit is contained in:
15
src/views.rs
15
src/views.rs
@@ -113,6 +113,21 @@ async fn create_service(db: Database, Json(data): Json<CreateServiceData>) -> im
|
|||||||
return StatusCode::PAYMENT_REQUIRED.into_response();
|
return StatusCode::PAYMENT_REQUIRED.into_response();
|
||||||
};
|
};
|
||||||
|
|
||||||
|
let token_exists = sqlx::query_scalar!(
|
||||||
|
r#"
|
||||||
|
SELECT EXISTS(SELECT 1 FROM services WHERE token = $1)
|
||||||
|
"#,
|
||||||
|
token
|
||||||
|
)
|
||||||
|
.fetch_one(&db.0)
|
||||||
|
.await
|
||||||
|
.unwrap_or(Some(false))
|
||||||
|
.unwrap();
|
||||||
|
|
||||||
|
if token_exists {
|
||||||
|
return StatusCode::CONFLICT.into_response();
|
||||||
|
}
|
||||||
|
|
||||||
let service = sqlx::query_as!(
|
let service = sqlx::query_as!(
|
||||||
Service,
|
Service,
|
||||||
r#"
|
r#"
|
||||||
|
|||||||
Reference in New Issue
Block a user