Further improvements regarding indents
This commit is contained in:
parent
b155c17337
commit
b2e8141676
1 changed files with 75 additions and 74 deletions
59
src/main.rs
59
src/main.rs
|
@ -58,6 +58,7 @@ fn reset_prepare(config: &Ldap0rConfig, keys: &Keys, email_address: &str) -> Res
|
||||||
ldap.unbind()?;
|
ldap.unbind()?;
|
||||||
let (rs, _res) = result.success()?;
|
let (rs, _res) = result.success()?;
|
||||||
|
|
||||||
|
// check for less or more than 1 result
|
||||||
if rs.len() != 1 {
|
if rs.len() != 1 {
|
||||||
bail!("Invalid password reset request for '{}'", email_address);
|
bail!("Invalid password reset request for '{}'", email_address);
|
||||||
}
|
}
|
||||||
|
@ -101,11 +102,32 @@ fn set_password(
|
||||||
key: &str,
|
key: &str,
|
||||||
passwords: &PasswordsForm,
|
passwords: &PasswordsForm,
|
||||||
) -> Result<Flash<Redirect>> {
|
) -> Result<Flash<Redirect>> {
|
||||||
if passwords.password == passwords.password_control {
|
if passwords.password != passwords.password_control {
|
||||||
if passwords.password.len() >= 8 {
|
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
|
// key lookup
|
||||||
let keys = Arc::clone(&keys.keys);
|
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
|
let email = keys
|
||||||
.get(key)
|
.get(key)
|
||||||
.ok_or_else(|| anyhow!("Could not extract email"))?
|
.ok_or_else(|| anyhow!("Could not extract email"))?
|
||||||
|
@ -148,29 +170,10 @@ fn set_password(
|
||||||
"New password set for user '{}' with email address '{}'",
|
"New password set for user '{}' with email address '{}'",
|
||||||
&user, &email
|
&user, &email
|
||||||
);
|
);
|
||||||
return Ok(Flash::success(
|
|
||||||
|
Ok(Flash::success(
|
||||||
Redirect::to(uri!(reset)),
|
Redirect::to(uri!(reset)),
|
||||||
"New password was saved",
|
"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 {
|
} else {
|
||||||
error!("Could not aquire lock for keys");
|
error!("Could not aquire lock for keys");
|
||||||
}
|
}
|
||||||
|
|
||||||
None
|
None
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -252,16 +256,13 @@ fn reset_password(
|
||||||
key: String,
|
key: String,
|
||||||
passwords: Form<PasswordsForm>,
|
passwords: Form<PasswordsForm>,
|
||||||
) -> Flash<Redirect> {
|
) -> Flash<Redirect> {
|
||||||
match set_password(&config, &keys, &key, &passwords) {
|
set_password(&config, &keys, &key, &passwords).unwrap_or_else(|e| {
|
||||||
Ok(flash) => flash,
|
|
||||||
Err(e) => {
|
|
||||||
error!("{} from {}", e, remote_address);
|
error!("{} from {}", e, remote_address);
|
||||||
Flash::error(
|
Flash::error(
|
||||||
Redirect::to(uri!(reset_key: key)),
|
Redirect::to(uri!(reset_key: key)),
|
||||||
"Setting new password failed",
|
"Setting new password failed",
|
||||||
)
|
)
|
||||||
}
|
})
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fn main() {
|
fn main() {
|
||||||
|
|
Loading…
Reference in a new issue