summaryrefslogtreecommitdiff
path: root/src/request_handler/handler_login.rs
diff options
context:
space:
mode:
authorYves Fischer <yvesf-git@xapek.org>2018-11-26 21:01:09 +0100
committerYves Fischer <yvesf-git@xapek.org>2018-11-26 21:01:09 +0100
commit16055300c760c636399f555ce30c07deff2a6820 (patch)
tree9b93f656f413ec02810c4deab38cdf8cec2f34ab /src/request_handler/handler_login.rs
parent4a966e386d2a095c3028c758f2bc872fcb3c1e48 (diff)
downloadnginx-auth-totp-16055300c760c636399f555ce30c07deff2a6820.tar.gz
nginx-auth-totp-16055300c760c636399f555ce30c07deff2a6820.zip
Redo response builder usage
- Set correct content-type header - Refactor views to use one base-view
Diffstat (limited to 'src/request_handler/handler_login.rs')
-rw-r--r--src/request_handler/handler_login.rs17
1 files changed, 10 insertions, 7 deletions
diff --git a/src/request_handler/handler_login.rs b/src/request_handler/handler_login.rs
index bfa7016..aa93e96 100644
--- a/src/request_handler/handler_login.rs
+++ b/src/request_handler/handler_login.rs
@@ -14,9 +14,9 @@ use super::*;
pub(in super) fn GET<'a>(header_infos: &HeaderExtract, state: &ApplicationState, path_rest: &'a str)
-> Response<String> {
if is_logged_in(&header_infos.cookies, &state.cookie_store) {
- make_response(StatusCode::OK, views::login_is_logged_in())
+ Response::builder().set_defaults().body(views::login_is_logged_in()).unwrap()
} else {
- make_response(StatusCode::OK, views::login_login_form(path_rest))
+ Response::builder().set_defaults().body(views::login_login_form(path_rest)).unwrap()
}
}
@@ -51,10 +51,9 @@ pub(in super) fn POST<'a>(header_infos: &HeaderExtract, state: &ApplicationState
let redirect = redirect.unwrap_or(Default::default());
if header_infos.totp_secrets.is_empty() {
- return error_handler_internal("no secrets configured".to_string())
+ return error_handler_internal("no secrets configured".to_string());
}
- let mut ret = Response::builder();
if test_secrets(&header_infos.totp_secrets, &token.unwrap()) {
let cookie_value = state.cookie_store.create_authenticated_cookie();
let cookie = CookieBuilder::new(COOKIE_NAME, cookie_value.to_string())
@@ -62,10 +61,14 @@ pub(in super) fn POST<'a>(header_infos: &HeaderExtract, state: &ApplicationState
.path("/")
.max_age(state.cookie_max_age)
.finish();
- ret.header(SET_COOKIE, cookie.to_string());
warn!("Authenticated user with cookie {}", cookie);
- ret.body(views::login_auth_success(&redirect)).unwrap()
+ Response::builder()
+ .set_defaults()
+ .header(SET_COOKIE, cookie.to_string())
+ .body(views::login_auth_success(&redirect)).unwrap()
} else {
- ret.body(views::login_auth_fail()).unwrap()
+ Response::builder()
+ .set_defaults()
+ .body(views::login_auth_fail()).unwrap()
}
} \ No newline at end of file