From e4f542c16a27269891c710e05ad87aa69c4f1b91 Mon Sep 17 00:00:00 2001 From: leonnicolas Date: Wed, 2 Dec 2020 12:46:39 +0100 Subject: [PATCH] src/server/http_server.ts: email to lower case lower case email on create, login and update. the code style probably need improvement. --- src/server/http_server.rs | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/src/server/http_server.rs b/src/server/http_server.rs index 2c5ce26..44c9bcd 100644 --- a/src/server/http_server.rs +++ b/src/server/http_server.rs @@ -261,10 +261,11 @@ impl UserHttpServer { /// Handles the login part of the REST api fn login(database: &Database, request: &Request) -> HTTPResult { - let login_request: LoginRequest = + let mut login_request: LoginRequest = serde_json::from_str(parse_string_body(request)?.as_str()) .map_err(|e| HTTPError::new(e.to_string(), 400))?; + login_request.email.make_ascii_lowercase(); let tokens = database .users .create_tokens(&login_request.email, &login_request.password)?; @@ -429,7 +430,8 @@ impl UserHttpServer { /// Creates a new user fn create_user(database: &Database, request: &Request) -> HTTPResult { require_permission!(database, request, USER_CREATE_PERM); - let message = deserialize_body::(&request)?; + let mut message = deserialize_body::(&request)?; + message.email.make_ascii_lowercase(); let result = database.users.create_user( message.name.clone(), message.email.clone(), @@ -442,6 +444,8 @@ impl UserHttpServer { /// Updates the information of a user. This requires the operating user to revalidate his password fn update_user(database: &Database, request: &Request, email: String) -> HTTPResult { + let mut email = email; + email.make_ascii_lowercase(); let logged_in_user = check_user_permission_or_self(request, database, &email, USER_UPDATE_PERM)?; let message = deserialize_body::(&request)?;