aboutsummaryrefslogtreecommitdiff
path: root/planetwars-server/src
diff options
context:
space:
mode:
authorIlion Beyst <ilion.beyst@gmail.com>2022-03-24 20:07:03 +0100
committerIlion Beyst <ilion.beyst@gmail.com>2022-03-24 20:07:03 +0100
commit1692eeb592b9d7cef526d04ebf046c08390a3924 (patch)
treec4b33b499193104031ae917b234f7f7af71d1587 /planetwars-server/src
parent2b5a80a0324d153b20eac7e6949cc02aea9c1c07 (diff)
downloadplanetwars.dev-1692eeb592b9d7cef526d04ebf046c08390a3924.tar.xz
planetwars.dev-1692eeb592b9d7cef526d04ebf046c08390a3924.zip
require login for uploading bots
Diffstat (limited to 'planetwars-server/src')
-rw-r--r--planetwars-server/src/routes/bots.rs14
1 files changed, 10 insertions, 4 deletions
diff --git a/planetwars-server/src/routes/bots.rs b/planetwars-server/src/routes/bots.rs
index f7f99cb..1d7cbf6 100644
--- a/planetwars-server/src/routes/bots.rs
+++ b/planetwars-server/src/routes/bots.rs
@@ -1,8 +1,7 @@
-use axum::body;
use axum::extract::{Multipart, Path};
use axum::http::StatusCode;
use axum::response::{IntoResponse, Response};
-use axum::Json;
+use axum::{body, Json};
use diesel::OptionalExtension;
use rand::distributions::Alphanumeric;
use rand::Rng;
@@ -46,6 +45,7 @@ impl IntoResponse for SaveBotError {
pub async fn save_bot(
Json(params): Json<SaveBotParams>,
+ user: User,
conn: DatabaseConnection,
) -> Result<Json<Bot>, SaveBotError> {
// TODO: authorization
@@ -53,10 +53,16 @@ pub async fn save_bot(
.optional()
.expect("could not run query");
let bot = match res {
- Some(_bot) => return Err(SaveBotError::BotNameTaken),
+ Some(existing_bot) => {
+ if existing_bot.owner_id == Some(user.id) {
+ existing_bot
+ } else {
+ return Err(SaveBotError::BotNameTaken);
+ }
+ }
None => {
let new_bot = bots::NewBot {
- owner_id: None,
+ owner_id: Some(user.id),
name: &params.bot_name,
};