From 2dfc46d4f7670a259c956012624d2f15bcdeb50b Mon Sep 17 00:00:00 2001 From: "Min S. Kim" Date: Thu, 12 Dec 2024 15:14:38 -0800 Subject: [PATCH] Use pass-by-value for SocketAddr Since `SocketAddr` is `Copy` and small enough, it's better to pass it by value. --- src/graphql/account.rs | 24 ++++++------------------ 1 file changed, 6 insertions(+), 18 deletions(-) diff --git a/src/graphql/account.rs b/src/graphql/account.rs index 1bc8467..2e6941a 100644 --- a/src/graphql/account.rs +++ b/src/graphql/account.rs @@ -326,16 +326,10 @@ impl AccountMutation { if let Some(mut account) = account_map.get(&username)? { validate_password(&account, &username, &password)?; validate_last_signin_time(&account, &username)?; - validate_allow_access_from(&account, client_ip.as_ref(), &username)?; + validate_allow_access_from(&account, client_ip, &username)?; validate_max_parallel_sessions(&account, &store, &username)?; - sign_in_actions( - &mut account, - &store, - &account_map, - client_ip.as_ref(), - &username, - ) + sign_in_actions(&mut account, &store, &account_map, client_ip, &username) } else { info!("{username} is not a valid username"); Err("incorrect username or password".into()) @@ -362,19 +356,13 @@ impl AccountMutation { if let Some(mut account) = account_map.get(&username)? { validate_password(&account, &username, &password)?; - validate_allow_access_from(&account, client_ip.as_ref(), &username)?; + validate_allow_access_from(&account, client_ip, &username)?; validate_max_parallel_sessions(&account, &store, &username)?; validate_update_new_password(&password, &new_password, &username)?; account.update_password(&new_password)?; - sign_in_actions( - &mut account, - &store, - &account_map, - client_ip.as_ref(), - &username, - ) + sign_in_actions(&mut account, &store, &account_map, client_ip, &username) } else { info!("{username} is not a valid username"); Err("incorrect username or password".into()) @@ -487,7 +475,7 @@ fn validate_last_signin_time(account: &types::Account, username: &str) -> Result fn validate_allow_access_from( account: &types::Account, - client_ip: Option<&SocketAddr>, + client_ip: Option, username: &str, ) -> Result<()> { if let Some(allow_access_from) = account.allow_access_from.as_ref() { @@ -546,7 +534,7 @@ fn sign_in_actions( account: &mut types::Account, store: &Store, account_map: &Table, - client_ip: Option<&SocketAddr>, + client_ip: Option, username: &str, ) -> Result { let (token, expiration_time) =