require login for uploading bots
This commit is contained in:
parent
2b5a80a032
commit
1692eeb592
1 changed files with 10 additions and 4 deletions
|
@ -1,8 +1,7 @@
|
||||||
use axum::body;
|
|
||||||
use axum::extract::{Multipart, Path};
|
use axum::extract::{Multipart, Path};
|
||||||
use axum::http::StatusCode;
|
use axum::http::StatusCode;
|
||||||
use axum::response::{IntoResponse, Response};
|
use axum::response::{IntoResponse, Response};
|
||||||
use axum::Json;
|
use axum::{body, Json};
|
||||||
use diesel::OptionalExtension;
|
use diesel::OptionalExtension;
|
||||||
use rand::distributions::Alphanumeric;
|
use rand::distributions::Alphanumeric;
|
||||||
use rand::Rng;
|
use rand::Rng;
|
||||||
|
@ -46,6 +45,7 @@ impl IntoResponse for SaveBotError {
|
||||||
|
|
||||||
pub async fn save_bot(
|
pub async fn save_bot(
|
||||||
Json(params): Json<SaveBotParams>,
|
Json(params): Json<SaveBotParams>,
|
||||||
|
user: User,
|
||||||
conn: DatabaseConnection,
|
conn: DatabaseConnection,
|
||||||
) -> Result<Json<Bot>, SaveBotError> {
|
) -> Result<Json<Bot>, SaveBotError> {
|
||||||
// TODO: authorization
|
// TODO: authorization
|
||||||
|
@ -53,10 +53,16 @@ pub async fn save_bot(
|
||||||
.optional()
|
.optional()
|
||||||
.expect("could not run query");
|
.expect("could not run query");
|
||||||
let bot = match res {
|
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 => {
|
None => {
|
||||||
let new_bot = bots::NewBot {
|
let new_bot = bots::NewBot {
|
||||||
owner_id: None,
|
owner_id: Some(user.id),
|
||||||
name: ¶ms.bot_name,
|
name: ¶ms.bot_name,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue