diff --git a/src/extractor.rs b/src/extractor.rs index 63daeab..b037f5c 100644 --- a/src/extractor.rs +++ b/src/extractor.rs @@ -11,6 +11,8 @@ use crate::{model::user::User, state::AppState, token::Claims}; pub struct ExtractUserToken(pub Option); +pub const TOKEN_COOKIE_NAME: &'static str = "imgboard-token"; + #[async_trait] impl FromRequestParts for ExtractUserToken where @@ -22,8 +24,8 @@ where async fn from_request_parts(parts: &mut Parts, state: &S) -> Result { let state = match parts.extract_with_state::(state).await { Ok(s) => s, - Err(why) => { - error!("Getting state: {}", why); + Err(err) => { + error!("Getting state: {}", err); return Err((StatusCode::INTERNAL_SERVER_ERROR, "Internal server error")); } }; @@ -36,7 +38,7 @@ where } }; - match cookie.get("imgboard-token") { + match cookie.get(TOKEN_COOKIE_NAME) { Some(token) => { let claims = Claims::decode(token, &state.decoding_key).map_err(|e| { error!("Decoding token claims: {}", e); diff --git a/src/pages/user/mod.rs b/src/pages/user/mod.rs index 4ff147d..ef1cc2f 100644 --- a/src/pages/user/mod.rs +++ b/src/pages/user/mod.rs @@ -26,8 +26,8 @@ pub async fn get_user( .await { Ok(user) => user, - Err(why) => { - error!("Getting user: {}", why); + Err(err) => { + error!("Getting user: {}", err); return Page::new(state.hbs.render( "error.hbs", &PageData { @@ -82,8 +82,8 @@ pub async fn get_user_new( .await { Ok(r) => r.count.unwrap_or(0), - Err(why) => { - error!("Getting user count: {}", why); + Err(err) => { + error!("Getting user count: {}", err); return Page::new( state .hbs @@ -118,8 +118,8 @@ pub async fn post_user_new( .await { Ok(r) => r.count.unwrap_or(0), - Err(why) => { - error!("Getting user count: {}", why); + Err(err) => { + error!("Getting user count: {}", err); return Page::new(state.hbs.render( "error.hbs", @@ -175,8 +175,8 @@ pub async fn post_user_new( let hashed_password = match bcrypt::hash(form_data.password, 12) { Ok(hash) => hash, - Err(why) => { - error!("Hashing password: {}", why); + Err(err) => { + error!("Hashing password: {}", err); return Page::new(state.hbs.render( "error.hbs", @@ -199,8 +199,8 @@ pub async fn post_user_new( .await { Ok(u) => u, - Err(why) => { - error!("Creating user: {}", why); + Err(err) => { + error!("Creating user: {}", err); return Page::new(state.hbs.render( "error.hbs", diff --git a/src/templates.rs b/src/templates.rs index 44dbb1c..d2bad5d 100644 --- a/src/templates.rs +++ b/src/templates.rs @@ -43,8 +43,8 @@ impl IntoResponse for Page { fn into_response(self) -> axum::response::Response { match self.0 { Ok(s) => ([(header::CONTENT_TYPE, "text/html; charset=utf-8")], s).into_response(), - Err(why) => { - error!("Error rendering page: {}", why); + Err(err) => { + error!("Error rendering page: {}", err); (StatusCode::INTERNAL_SERVER_ERROR, "Internal server error").into_response() } }