mirror of
https://github.com/agersant/polaris
synced 2024-12-11 13:56:24 +00:00
autoformat
This commit is contained in:
parent
42fcf70f53
commit
942ac099c7
2 changed files with 18 additions and 14 deletions
20
src/api.rs
20
src/api.rs
|
@ -56,7 +56,10 @@ pub fn get_handler(collection: Collection, secret: &str) -> Chain {
|
|||
|
||||
let manager = ChaCha20Poly1305SessionManager::<Session>::from_password(secret.as_bytes());
|
||||
let config = SessionConfig::default();
|
||||
let session_middleware = SessionMiddleware::<Session, SessionKey, ChaCha20Poly1305SessionManager<Session>>::new(manager, config);
|
||||
let session_middleware =
|
||||
SessionMiddleware::<Session,
|
||||
SessionKey,
|
||||
ChaCha20Poly1305SessionManager<Session>>::new(manager, config);
|
||||
api_chain.link_around(session_middleware);
|
||||
|
||||
api_chain
|
||||
|
@ -142,11 +145,9 @@ struct AuthHandler {
|
|||
}
|
||||
|
||||
fn set_cookie(username: &str, response: &mut Response) {
|
||||
response.headers.set(
|
||||
SetCookie(vec![
|
||||
format!("username={}; Path=/", username)
|
||||
])
|
||||
);
|
||||
response
|
||||
.headers
|
||||
.set(SetCookie(vec![format!("username={}; Path=/", username)]));
|
||||
}
|
||||
|
||||
impl Handler for AuthHandler {
|
||||
|
@ -161,7 +162,8 @@ impl Handler for AuthHandler {
|
|||
auth_success = self.collection
|
||||
.auth(auth.username.as_str(), password.as_str());
|
||||
username = Some(auth.username.clone());
|
||||
req.extensions.insert::<SessionKey>(Session { username: auth.username.clone() });
|
||||
req.extensions
|
||||
.insert::<SessionKey>(Session { username: auth.username.clone() });
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -215,7 +217,9 @@ fn auth(request: &mut Request, collection: &Collection) -> IronResult<Response>
|
|||
if collection.auth(username.as_str(), password.as_str()) {
|
||||
let mut response = Response::with((status::Ok, ""));
|
||||
set_cookie(&username, &mut response);
|
||||
request.extensions.insert::<SessionKey>(Session { username: username.clone() });
|
||||
request
|
||||
.extensions
|
||||
.insert::<SessionKey>(Session { username: username.clone() });
|
||||
Ok(response)
|
||||
} else {
|
||||
Err(Error::from(ErrorKind::IncorrectCredentials).into())
|
||||
|
|
|
@ -84,7 +84,7 @@ fn daemonize() -> Result<()> {
|
|||
log_file.push("polaris.log");
|
||||
match daemonize_redirect(Some(&log_file), Some(&log_file), ChdirMode::NoChdir) {
|
||||
Ok(_) => Ok(()),
|
||||
Err(_) => bail!(ErrorKind::DaemonError)
|
||||
Err(_) => bail!(ErrorKind::DaemonError),
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue