cargo clippy --fix
This commit is contained in:
parent
27c463bdf1
commit
a3f84442a4
25
src/main.rs
25
src/main.rs
@ -1,5 +1,5 @@
|
||||
use axum::extract::Query;
|
||||
use axum::http::{HeaderMap, HeaderValue, Uri};
|
||||
use axum::http::{HeaderMap, HeaderValue};
|
||||
use axum::response::{Html, Redirect};
|
||||
use axum::{extract::State, http::StatusCode, response::IntoResponse, routing::get, Form, Router};
|
||||
use minijinja::{context, Environment};
|
||||
@ -94,12 +94,9 @@ async fn auth(
|
||||
return StatusCode::UNAUTHORIZED;
|
||||
};
|
||||
let mut locked = state.session.lock().await;
|
||||
if locked.contains_key(&s) {
|
||||
if let std::collections::hash_map::Entry::Occupied(mut e) = locked.entry(s) {
|
||||
// FIX, when accessed /auth with correct cookie, the cookie's expiration is delayed
|
||||
let Some(v) = locked.insert(
|
||||
s,
|
||||
Instant::now() + Duration::from_secs(*SESSION_ACTIVE_TIME),
|
||||
) else {
|
||||
let Some(v) = Some(e.insert(Instant::now() + Duration::from_secs(*SESSION_ACTIVE_TIME))) else {
|
||||
tracing::info!("session:{} extended", session_token.value());
|
||||
return StatusCode::UNAUTHORIZED;
|
||||
};
|
||||
@ -108,13 +105,13 @@ async fn auth(
|
||||
}
|
||||
}
|
||||
}
|
||||
return StatusCode::UNAUTHORIZED;
|
||||
StatusCode::UNAUTHORIZED
|
||||
}
|
||||
|
||||
async fn login(
|
||||
State(state): State<Arc<ServerState>>,
|
||||
cookies: Cookies,
|
||||
Query(mut params): Query<HashMap<String, String>>,
|
||||
Query(params): Query<HashMap<String, String>>,
|
||||
Form(frm): Form<UserLoginForm>,
|
||||
) -> Result<Redirect, (StatusCode, &'static str)> {
|
||||
let conn = state.db.acquire().await;
|
||||
@ -137,14 +134,14 @@ async fn login(
|
||||
let s = Uuid::new_v4();
|
||||
let mut locked = state.session.lock().await;
|
||||
locked.insert(
|
||||
s.clone(),
|
||||
s,
|
||||
Instant::now() + Duration::from_secs(*SESSION_ACTIVE_TIME),
|
||||
);
|
||||
let mut new_cookie = Cookie::new(&*COOKIE_NAME, s.to_string());
|
||||
new_cookie.set_domain(".aaronhu.cn");
|
||||
cookies.add(new_cookie);
|
||||
if let Some(original_uri) = params.get("original_url") {
|
||||
return Ok(Redirect::to(&original_uri));
|
||||
return Ok(Redirect::to(original_uri));
|
||||
}
|
||||
|
||||
return Err((StatusCode::ACCEPTED, "ok"));
|
||||
@ -152,7 +149,7 @@ async fn login(
|
||||
return Err((StatusCode::UNAUTHORIZED, "wrong password"));
|
||||
}
|
||||
}
|
||||
return Err((StatusCode::BAD_GATEWAY, "unreachable"));
|
||||
Err((StatusCode::BAD_GATEWAY, "unreachable"))
|
||||
}
|
||||
|
||||
async fn login_page(headers: HeaderMap<HeaderValue>) -> impl IntoResponse {
|
||||
@ -173,11 +170,11 @@ async fn login_page(headers: HeaderMap<HeaderValue>) -> impl IntoResponse {
|
||||
}
|
||||
}
|
||||
}
|
||||
return Html(
|
||||
Html(
|
||||
template
|
||||
.render(context! { url => String::new() })
|
||||
.unwrap_or("Error".to_string()),
|
||||
);
|
||||
)
|
||||
}
|
||||
|
||||
pub fn check_otp(key_from_db: String, user_input_otp: String) -> bool {
|
||||
@ -196,7 +193,7 @@ pub fn check_otp(key_from_db: String, user_input_otp: String) -> bool {
|
||||
return token == user_input_otp;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
false
|
||||
}
|
||||
|
||||
async fn gc(state: Arc<ServerState>) -> Result<(), String> {
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user