use axum::response::{Html, IntoResponse}; use serde::{Deserialize, Serialize}; use tower_cookies::{Cookie, Cookies}; use crate::svc::{ auth::{Auth, AuthError, Claims}, profiles::User, }; mod html; pub mod servek; #[derive(Debug, Clone, Serialize)] struct Notification { pub message: String, pub tag_name: String, } #[derive(Debug, Clone, Deserialize)] pub struct LoginRequest { pub username: String, pub password: String, } #[derive(Debug, Clone, Deserialize)] pub struct CreateProfileRequest { pub username: String, pub password: String, pub email: String, } // pub enum HtmlOrRedirect { // Html(Html), // Redirect(()), // } #[derive(Debug, Clone, Serialize)] pub struct Redirect { pub location: String, } #[derive(Debug, Clone, Serialize)] pub enum NavType { LoggedIn, LoggedOut, } impl From> for NavType { fn from(claims: Result) -> Self { if claims.map(|c| c.expired()).unwrap_or(true) { NavType::LoggedOut } else { NavType::LoggedIn } } } impl From for NavType { fn from(c: Claims) -> Self { if c.expired() { NavType::LoggedOut } else { NavType::LoggedIn } } } #[derive(Debug, Clone, Serialize)] pub struct WithNav { pub nav_type: NavType, pub obj: T, } impl WithNav { pub fn new(obj: T, nav_type: NavType) -> WithNav { WithNav { nav_type, obj } } } impl Into for WithNav where T: Serialize, { fn into(self) -> serde_json::Value { serde_json::json!(self) } }