From 366554630a6bcb76ca6c6bc89f418e5acaef841e Mon Sep 17 00:00:00 2001 From: Timo Date: Sat, 22 Aug 2020 22:49:19 +0200 Subject: [PATCH] fix: account registration --- src/client_server/account.rs | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) diff --git a/src/client_server/account.rs b/src/client_server/account.rs index e7a27fbb..fe5ac97d 100644 --- a/src/client_server/account.rs +++ b/src/client_server/account.rs @@ -86,14 +86,20 @@ pub fn register_route( let is_guest = matches!(body.kind, Some(RegistrationKind::Guest)); + let mut missing_username = false; + // Validate user id let user_id = UserId::parse_with_server_name( if is_guest { utils::random_string(GUEST_NAME_LENGTH) } else { - body.username.clone().ok_or_else(|| { - Error::BadRequest(ErrorKind::MissingParam, "Missing username field.") - })? + body.username.clone().unwrap_or_else(|| { + // If the user didn't send a username field, that means the client is just trying + // the get an UIAA error to see available flows + missing_username = true; + // Just give the user a random name. He won't be able to register with it anyway. + utils::random_string(GUEST_NAME_LENGTH) + }) } .to_lowercase(), db.globals.server_name(), @@ -106,7 +112,7 @@ pub fn register_route( ))?; // Check if username is creative enough - if db.users.exists(&user_id)? { + if !missing_username && db.users.exists(&user_id)? { return Err(Error::BadRequest( ErrorKind::UserInUse, "Desired user ID is already taken.", @@ -138,6 +144,10 @@ pub fn register_route( return Err(Error::Uiaa(uiaainfo)); } + if missing_username { + return Err(Error::BadRequest(ErrorKind::MissingParam, "Missing username field.")); + } + let password = if is_guest { None } else {