Skip to content

Commit

Permalink
spaces in usernames not allowed
Browse files Browse the repository at this point in the history
  • Loading branch information
Dromader2137 committed May 28, 2024
1 parent acbb4fb commit 0c5d120
Showing 1 changed file with 13 additions and 0 deletions.
13 changes: 13 additions & 0 deletions src/api_calls.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1170,11 +1170,19 @@ impl Reject for UserAlereadyExists {}
struct WrongToken;
impl Reject for WrongToken {}

#[derive(Debug)]
struct SpacesNotAllowed;
impl Reject for SpacesNotAllowed {}

pub async fn signup(request: SignupRequest) -> Result<impl warp::Reply, warp::Rejection> {
let connection = tokio_rusqlite::Connection::open("projekt-db")
.await
.unwrap();

if request.user_name.contains(" ") {
return Err(warp::reject::custom(SpacesNotAllowed));
}

if check_user_name(&connection, request.user_name.clone()).await {
Err(warp::reject::custom(UserAlereadyExists))
} else {
Expand Down Expand Up @@ -1874,6 +1882,11 @@ pub async fn handle_rejection(
"User already exists",
warp::http::StatusCode::BAD_REQUEST,
))
} else if err.find::<SpacesNotAllowed>().is_some() {
Ok(warp::reply::with_status(
"Spaces in username not allowed",
warp::http::StatusCode::NOT_ACCEPTABLE,
))
} else if err.find::<WrongToken>().is_some() {
Ok(warp::reply::with_status(
"Wrong token",
Expand Down

0 comments on commit 0c5d120

Please sign in to comment.