feat: Implement basic (dummy) admin auth
This commit is contained in:
parent
b37c0665d3
commit
8c29f1d31f
13 changed files with 706 additions and 5 deletions
23
src/http/logout.rs
Normal file
23
src/http/logout.rs
Normal file
|
|
@ -0,0 +1,23 @@
|
|||
use axum::extract::State;
|
||||
use axum::response::{IntoResponse, Redirect, Response};
|
||||
use axum_extra::extract::cookie::CookieJar;
|
||||
|
||||
use crate::db::DatabaseInterface;
|
||||
use crate::http::HttpState;
|
||||
use crate::http::login::{LoginError, login_page};
|
||||
|
||||
pub async fn logout<D: DatabaseInterface>(
|
||||
State(state): State<HttpState<D>>,
|
||||
cookies: CookieJar,
|
||||
) -> Response {
|
||||
let Some(session) = state.sessions.get_session(&cookies) else {
|
||||
return (cookies, Redirect::to("/")).into_response();
|
||||
};
|
||||
|
||||
let cookies = state.sessions.remove_session(&session, cookies);
|
||||
(
|
||||
cookies,
|
||||
login_page(State(state), Some(LoginError::SessionInvalidated)).await,
|
||||
)
|
||||
.into_response()
|
||||
}
|
||||
Loading…
Reference in a new issue