Form CSS style + dev panel (WIP)

This commit is contained in:
Greg Burri 2025-04-15 11:34:18 +02:00
parent 9daa852add
commit f2e0aa3b43
18 changed files with 154 additions and 34 deletions

View file

@ -56,3 +56,5 @@ pub const REVERSE_PROXY_IP_HTTP_FIELD: &str = "x-real-ip";
// To avoid database lock.
pub const MAX_DB_CONNECTION: u32 = 1;
pub const NOT_AUTHORIZED_MESSAGE: &str = "Action not authorized";

View file

@ -50,7 +50,13 @@ mod filters {
#[template(path = "home.html")]
pub struct HomeTemplate {
pub context: Context,
pub recipes: Recipes,
}
#[derive(Template)]
#[template(path = "dev_panel.html")]
pub struct DevPanelTemplate {
pub context: Context,
pub recipes: Recipes,
}

View file

@ -261,6 +261,7 @@ async fn main() {
let html_routes = Router::new()
.route("/", get(services::home_page))
.route("/dev_panel", get(services::dev_panel))
.route("/signup", get(services::user::sign_up_get))
.route("/validation", get(services::user::sign_up_validation))
.route("/revalidation", get(services::user::email_revalidation))

View file

@ -1,11 +1,11 @@
use axum::{
body::Bytes,
http::{header, HeaderValue, StatusCode},
http::{HeaderValue, StatusCode, header},
response::{IntoResponse, Response},
};
use common::ron_api;
use ron::de::from_bytes;
use serde::{de::DeserializeOwned, Serialize};
use serde::{Serialize, de::DeserializeOwned};
pub const RON_CONTENT_TYPE: HeaderValue = HeaderValue::from_static("application/ron");

View file

@ -7,7 +7,7 @@ use axum::{
response::{Html, IntoResponse, Response},
};
use crate::{Context, Result, data::db, html_templates::*, ron_utils};
use crate::{Context, Result, consts, data::db, html_templates::*, ron_utils};
pub mod fragments;
pub mod recipe;
@ -66,15 +66,31 @@ pub async fn home_page(
pub async fn dev_panel(
State(connection): State<db::Connection>,
Extension(context): Extension<Context>,
) -> Result<impl IntoResponse> {
Ok(Html(
HomeTemplate {
recipes: Recipes::new(connection, &context.user, context.tr.current_lang_code())
.await?,
context,
}
.render()?,
))
) -> Result<Response> {
if context.user.is_some() && context.user.as_ref().unwrap().is_admin {
Ok(Html(
DevPanelTemplate {
recipes: Recipes::new(connection, &context.user, context.tr.current_lang_code())
.await?,
context,
}
.render()?,
)
.into_response())
} else {
Ok((
StatusCode::UNAUTHORIZED,
Html(
MessageTemplate::new_with_user(
consts::NOT_AUTHORIZED_MESSAGE,
context.tr,
context.user,
)
.render()?,
),
)
.into_response())
}
}
///// 404 /////

View file

@ -5,10 +5,9 @@ use axum::{
response::{ErrorResponse, IntoResponse, Response, Result},
};
use axum_extra::extract::Query;
// use tracing::{event, Level};
use crate::{
Context,
Context, consts,
data::{self, db},
ron_extractor::ExtractRon,
ron_utils::{ron_error, ron_response_ok},
@ -31,7 +30,7 @@ pub async fn get_scheduled_recipes(
} else {
Err(ErrorResponse::from(ron_error(
StatusCode::UNAUTHORIZED,
super::NOT_AUTHORIZED_MESSAGE,
consts::NOT_AUTHORIZED_MESSAGE,
)))
}
}

View file

@ -14,8 +14,6 @@ pub mod recipe;
mod rights;
pub mod shopping_list;
const NOT_AUTHORIZED_MESSAGE: &str = "Action not authorized";
#[debug_handler]
pub async fn set_lang(
State(connection): State<db::Connection>,

View file

@ -3,7 +3,7 @@ use axum::{
response::{ErrorResponse, Result},
};
use crate::{data::db, model, ron_utils::ron_error};
use crate::{consts, data::db, model, ron_utils::ron_error};
pub async fn check_user_rights_recipe(
connection: &db::Connection,
@ -17,7 +17,7 @@ pub async fn check_user_rights_recipe(
{
Err(ErrorResponse::from(ron_error(
StatusCode::UNAUTHORIZED,
super::NOT_AUTHORIZED_MESSAGE,
consts::NOT_AUTHORIZED_MESSAGE,
)))
} else {
Ok(())
@ -36,7 +36,7 @@ pub async fn check_user_rights_recipe_group(
{
Err(ErrorResponse::from(ron_error(
StatusCode::UNAUTHORIZED,
super::NOT_AUTHORIZED_MESSAGE,
consts::NOT_AUTHORIZED_MESSAGE,
)))
} else {
Ok(())
@ -55,7 +55,7 @@ pub async fn check_user_rights_recipe_groups(
{
Err(ErrorResponse::from(ron_error(
StatusCode::UNAUTHORIZED,
super::NOT_AUTHORIZED_MESSAGE,
consts::NOT_AUTHORIZED_MESSAGE,
)))
} else {
Ok(())
@ -74,7 +74,7 @@ pub async fn check_user_rights_recipe_step(
{
Err(ErrorResponse::from(ron_error(
StatusCode::UNAUTHORIZED,
super::NOT_AUTHORIZED_MESSAGE,
consts::NOT_AUTHORIZED_MESSAGE,
)))
} else {
Ok(())
@ -93,7 +93,7 @@ pub async fn check_user_rights_recipe_steps(
{
Err(ErrorResponse::from(ron_error(
StatusCode::UNAUTHORIZED,
super::NOT_AUTHORIZED_MESSAGE,
consts::NOT_AUTHORIZED_MESSAGE,
)))
} else {
Ok(())
@ -112,7 +112,7 @@ pub async fn check_user_rights_recipe_ingredient(
{
Err(ErrorResponse::from(ron_error(
StatusCode::UNAUTHORIZED,
super::NOT_AUTHORIZED_MESSAGE,
consts::NOT_AUTHORIZED_MESSAGE,
)))
} else {
Ok(())
@ -131,7 +131,7 @@ pub async fn check_user_rights_recipe_ingredients(
{
Err(ErrorResponse::from(ron_error(
StatusCode::UNAUTHORIZED,
super::NOT_AUTHORIZED_MESSAGE,
consts::NOT_AUTHORIZED_MESSAGE,
)))
} else {
Ok(())
@ -150,7 +150,7 @@ pub async fn check_user_rights_shopping_list_entry(
{
Err(ErrorResponse::from(ron_error(
StatusCode::UNAUTHORIZED,
super::NOT_AUTHORIZED_MESSAGE,
consts::NOT_AUTHORIZED_MESSAGE,
)))
} else {
Ok(())

View file

@ -7,7 +7,7 @@ use axum::{
use common::ron_api;
use crate::{
Context,
Context, consts,
data::db,
model,
ron_extractor::ExtractRon,
@ -48,7 +48,7 @@ pub async fn get(
} else {
Err(ErrorResponse::from(ron_error(
StatusCode::UNAUTHORIZED,
super::NOT_AUTHORIZED_MESSAGE,
consts::NOT_AUTHORIZED_MESSAGE,
)))
}
}