Skip to content

Commit

Permalink
Use pass-by-value for SocketAddr
Browse files Browse the repository at this point in the history
Since `SocketAddr` is `Copy` and small enough, it's better to pass it
by value.
  • Loading branch information
msk authored Dec 12, 2024
1 parent 238fb77 commit 2dfc46d
Showing 1 changed file with 6 additions and 18 deletions.
24 changes: 6 additions & 18 deletions src/graphql/account.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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())
Expand All @@ -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())
Expand Down Expand Up @@ -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<SocketAddr>,
username: &str,
) -> Result<()> {
if let Some(allow_access_from) = account.allow_access_from.as_ref() {
Expand Down Expand Up @@ -546,7 +534,7 @@ fn sign_in_actions(
account: &mut types::Account,
store: &Store,
account_map: &Table<types::Account>,
client_ip: Option<&SocketAddr>,
client_ip: Option<SocketAddr>,
username: &str,
) -> Result<AuthPayload> {
let (token, expiration_time) =
Expand Down

0 comments on commit 2dfc46d

Please sign in to comment.