mirror of
https://github.com/perstarkse/minne.git
synced 2026-03-23 09:51:36 +01:00
feat signout and reactivity
This commit is contained in:
@@ -26,6 +26,7 @@ use zettle_db::{
|
||||
html::{
|
||||
index::index_handler,
|
||||
search_result::search_result_handler,
|
||||
signout::sign_out_user,
|
||||
signup::{process_signup_and_show_verification, show_signup_form},
|
||||
},
|
||||
},
|
||||
@@ -147,6 +148,7 @@ fn html_routes(
|
||||
Router::new()
|
||||
.route("/", get(index_handler))
|
||||
.route("/search", get(search_result_handler))
|
||||
.route("/signout", get(sign_out_user))
|
||||
.route(
|
||||
"/signup",
|
||||
get(show_signup_form).post(process_signup_and_show_verification),
|
||||
|
||||
@@ -13,6 +13,7 @@ use crate::{
|
||||
|
||||
page_data!(IndexData, "index.html", {
|
||||
queue_length: u32,
|
||||
user: Option<User>
|
||||
});
|
||||
|
||||
pub async fn index_handler(
|
||||
@@ -21,11 +22,12 @@ pub async fn index_handler(
|
||||
) -> Result<Html<String>, ApiError> {
|
||||
info!("Displaying index page");
|
||||
|
||||
info!("{:?}", auth.current_user);
|
||||
|
||||
let queue_length = state.rabbitmq_consumer.get_queue_length().await?;
|
||||
|
||||
let data = IndexData { queue_length };
|
||||
let data = IndexData {
|
||||
queue_length,
|
||||
user: auth.current_user,
|
||||
};
|
||||
|
||||
let output = render_template(IndexData::template_name(), data, state.templates)?;
|
||||
|
||||
|
||||
@@ -6,6 +6,7 @@ use minijinja_autoreload::AutoReloader;
|
||||
pub mod index;
|
||||
pub mod search_result;
|
||||
pub mod signin;
|
||||
pub mod signout;
|
||||
pub mod signup;
|
||||
|
||||
pub trait PageData {
|
||||
|
||||
18
src/server/routes/html/signout.rs
Normal file
18
src/server/routes/html/signout.rs
Normal file
@@ -0,0 +1,18 @@
|
||||
use axum::response::{IntoResponse, Redirect};
|
||||
use axum_session_auth::AuthSession;
|
||||
use axum_session_surreal::SessionSurrealPool;
|
||||
use surrealdb::{engine::any::Any, Surreal};
|
||||
|
||||
use crate::{error::ApiError, storage::types::user::User};
|
||||
|
||||
pub async fn sign_out_user(
|
||||
auth: AuthSession<User, String, SessionSurrealPool<Any>, Surreal<Any>>,
|
||||
) -> Result<impl IntoResponse, ApiError> {
|
||||
if !auth.is_authenticated() {
|
||||
return Ok(Redirect::to("/").into_response());
|
||||
}
|
||||
|
||||
auth.logout_user();
|
||||
|
||||
Ok(Redirect::to("/").into_response())
|
||||
}
|
||||
Reference in New Issue
Block a user