Further improvements regarding indents

This commit is contained in:
finga 2020-08-29 00:59:56 +02:00
parent b155c17337
commit b2e8141676

View file

@ -58,6 +58,7 @@ fn reset_prepare(config: &Ldap0rConfig, keys: &Keys, email_address: &str) -> Res
ldap.unbind()?;
let (rs, _res) = result.success()?;
// check for less or more than 1 result
if rs.len() != 1 {
bail!("Invalid password reset request for '{}'", email_address);
}
@ -101,11 +102,32 @@ fn set_password(
key: &str,
passwords: &PasswordsForm,
) -> Result<Flash<Redirect>> {
if passwords.password == passwords.password_control {
if passwords.password.len() >= 8 {
if passwords.password != passwords.password_control {
return Ok(Flash::error(
Redirect::to(uri!(reset_key: key)),
"Password does not match the password verification field",
));
}
if passwords.password.len() < 8 {
return Ok(Flash::error(
Redirect::to(uri!(reset_key: key)),
"Password length has to be at least 8",
));
}
// key lookup
let keys = Arc::clone(&keys.keys);
if let Ok(mut keys) = keys.lock() {
let mut keys = match keys.lock() {
Ok(keys) => keys,
Err(e) => {
error!("Could not aquire lock for keys: {}", e);
return Ok(Flash::error(
Redirect::to(uri!(reset_key: key)),
"Setting new password failed",
));
}
};
let email = keys
.get(key)
.ok_or_else(|| anyhow!("Could not extract email"))?
@ -148,29 +170,10 @@ fn set_password(
"New password set for user '{}' with email address '{}'",
&user, &email
);
return Ok(Flash::success(
Ok(Flash::success(
Redirect::to(uri!(reset)),
"New password was saved",
));
} else {
error!("Could not aquire lock for keys");
};
} else {
return Ok(Flash::error(
Redirect::to(uri!(reset_key: key)),
"Password length has to be at least 8",
));
}
} else {
return Ok(Flash::error(
Redirect::to(uri!(reset_key: key)),
"Password does not match the password verification field",
));
}
Ok(Flash::error(
Redirect::to(uri!(reset_key: key)),
"Setting new password failed",
))
}
@ -241,6 +244,7 @@ fn reset_key(keys: State<Keys>, key: String, flash: Option<FlashMessage>) -> Opt
} else {
error!("Could not aquire lock for keys");
}
None
}
@ -252,16 +256,13 @@ fn reset_password(
key: String,
passwords: Form<PasswordsForm>,
) -> Flash<Redirect> {
match set_password(&config, &keys, &key, &passwords) {
Ok(flash) => flash,
Err(e) => {
set_password(&config, &keys, &key, &passwords).unwrap_or_else(|e| {
error!("{} from {}", e, remote_address);
Flash::error(
Redirect::to(uri!(reset_key: key)),
"Setting new password failed",
)
}
}
})
}
fn main() {