From fdfe4a05b88cd6cf952f02cf79920f6f4aa24ea3 Mon Sep 17 00:00:00 2001 From: Per Stark Date: Mon, 23 Dec 2024 10:18:25 +0100 Subject: [PATCH] refactoring route names --- assets/style.css | 121 ------------------ src/bin/server.rs | 7 +- src/server/routes/html/mod.rs | 3 +- src/server/routes/html/signin.rs | 56 ++++++++ src/server/routes/html/{auth.rs => signup.rs} | 2 +- tailwind.config.js | 3 +- templates/auth/signup_form.html | 2 - 7 files changed, 66 insertions(+), 128 deletions(-) create mode 100644 src/server/routes/html/signin.rs rename src/server/routes/html/{auth.rs => signup.rs} (96%) diff --git a/assets/style.css b/assets/style.css index 699f79e..bb0b1a8 100644 --- a/assets/style.css +++ b/assets/style.css @@ -877,57 +877,6 @@ html { content: var(--tw-content); } -.card { - position: relative; - display: flex; - flex-direction: column; - border-radius: var(--rounded-box, 1rem); -} - -.card:focus { - outline: 2px solid transparent; - outline-offset: 2px; -} - -.card figure { - display: flex; - align-items: center; - justify-content: center; -} - -.card.image-full { - display: grid; -} - -.card.image-full:before { - position: relative; - content: ""; - z-index: 10; - border-radius: var(--rounded-box, 1rem); - --tw-bg-opacity: 1; - background-color: var(--fallback-n,oklch(var(--n)/var(--tw-bg-opacity))); - opacity: 0.75; -} - -.card.image-full:before, - .card.image-full > * { - grid-column-start: 1; - grid-row-start: 1; -} - -.card.image-full > figure img { - height: 100%; - -o-object-fit: cover; - object-fit: cover; -} - -.card.image-full > .card-body { - position: relative; - z-index: 20; - --tw-text-opacity: 1; - color: var(--fallback-nc,oklch(var(--nc)/var(--tw-text-opacity))); -} - .chat { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); @@ -1215,34 +1164,6 @@ html { } } -.footer { - display: grid; - width: 100%; - grid-auto-flow: row; - place-items: start; - -moz-column-gap: 1rem; - column-gap: 1rem; - row-gap: 2.5rem; - font-size: 0.875rem; - line-height: 1.25rem; -} - -.footer > * { - display: grid; - place-items: start; - gap: 0.5rem; -} - -@media (min-width: 48rem) { - .footer { - grid-auto-flow: column; - } - - .footer-center { - grid-auto-flow: row dense; - } -} - .form-control { display: flex; flex-direction: column; @@ -1579,44 +1500,6 @@ html { } } -.card :where(figure:first-child) { - overflow: hidden; - border-start-start-radius: inherit; - border-start-end-radius: inherit; - border-end-start-radius: unset; - border-end-end-radius: unset; -} - -.card :where(figure:last-child) { - overflow: hidden; - border-start-start-radius: unset; - border-start-end-radius: unset; - border-end-start-radius: inherit; - border-end-end-radius: inherit; -} - -.card:focus-visible { - outline: 2px solid currentColor; - outline-offset: 2px; -} - -.card.bordered { - border-width: 1px; - --tw-border-opacity: 1; - border-color: var(--fallback-b2,oklch(var(--b2)/var(--tw-border-opacity))); -} - -.card.compact .card-body { - padding: 1rem; - font-size: 0.875rem; - line-height: 1.25rem; -} - -.card.image-full :where(figure) { - overflow: hidden; - border-radius: inherit; -} - .checkbox:focus { box-shadow: none; } @@ -2178,10 +2061,6 @@ html { border-top-right-radius: 0px; } -.border { - border-width: 1px; -} - .border-transparent { border-color: transparent; } diff --git a/src/bin/server.rs b/src/bin/server.rs index 13a5466..15290be 100644 --- a/src/bin/server.rs +++ b/src/bin/server.rs @@ -24,9 +24,9 @@ use zettle_db::{ queue_length::queue_length_handler, }, html::{ - auth::{show_signup_form, signup_handler}, index::index_handler, search_result::search_result_handler, + signup::{process_signup_and_show_verification, show_signup_form}, }, }, AppState, @@ -147,7 +147,10 @@ fn html_routes( Router::new() .route("/", get(index_handler)) .route("/search", get(search_result_handler)) - .route("/signup", get(show_signup_form).post(signup_handler)) + .route( + "/signup", + get(show_signup_form).post(process_signup_and_show_verification), + ) .nest_service("/assets", ServeDir::new("assets/")) .layer( AuthSessionLayer::, Surreal>::new(Some( diff --git a/src/server/routes/html/mod.rs b/src/server/routes/html/mod.rs index c89a7ac..c3f8712 100644 --- a/src/server/routes/html/mod.rs +++ b/src/server/routes/html/mod.rs @@ -3,9 +3,10 @@ use std::sync::Arc; use axum::response::Html; use minijinja_autoreload::AutoReloader; -pub mod auth; pub mod index; pub mod search_result; +pub mod signin; +pub mod signup; pub trait PageData { fn template_name() -> &'static str; diff --git a/src/server/routes/html/signin.rs b/src/server/routes/html/signin.rs new file mode 100644 index 0000000..f99a306 --- /dev/null +++ b/src/server/routes/html/signin.rs @@ -0,0 +1,56 @@ +use axum::{ + extract::State, + response::{IntoResponse, Redirect}, + Form, +}; +use axum_htmx::HxBoosted; +use axum_session_auth::AuthSession; +use axum_session_surreal::SessionSurrealPool; +use serde::{Deserialize, Serialize}; +use surrealdb::{engine::any::Any, Surreal}; + +use crate::{error::ApiError, server::AppState, storage::types::user::User}; + +use super::{render_block, render_template}; + +#[derive(Deserialize, Serialize)] +pub struct SignupParams { + pub email: String, + pub password: String, +} + +#[derive(Serialize)] +struct PageData { + // name: String, +} + +pub async fn show_login_form( + State(state): State, + auth: AuthSession, Surreal>, + HxBoosted(boosted): HxBoosted, +) -> Result { + if auth.is_authenticated() { + return Ok(Redirect::to("/").into_response()); + } + let output = match boosted { + true => render_block( + "auth/signup_form.html", + "body", + PageData {}, + state.templates, + )?, + false => render_template("auth/signup_form.html", PageData {}, state.templates)?, + }; + + Ok(output.into_response()) +} + +pub async fn authenticate_user( + State(state): State, + auth: AuthSession, Surreal>, + Form(form): Form, +) -> Result { + let user = User::create_new(form.email, form.password, &state.surreal_db_client).await?; + auth.login_user(user.id); + Ok(()) +} diff --git a/src/server/routes/html/auth.rs b/src/server/routes/html/signup.rs similarity index 96% rename from src/server/routes/html/auth.rs rename to src/server/routes/html/signup.rs index c6f5ab2..40cd9fa 100644 --- a/src/server/routes/html/auth.rs +++ b/src/server/routes/html/signup.rs @@ -45,7 +45,7 @@ pub async fn show_signup_form( Ok(output.into_response()) } -pub async fn signup_handler( +pub async fn process_signup_and_show_verification( State(state): State, auth: AuthSession, Surreal>, Form(form): Form, diff --git a/tailwind.config.js b/tailwind.config.js index f9960f4..ee22051 100644 --- a/tailwind.config.js +++ b/tailwind.config.js @@ -1,7 +1,8 @@ /** @type {import('tailwindcss').Config} */ module.exports = { content: [ - './templates/**/*' + './templates/**/*', + '!./templates/email/**/*' ], theme: { extend: {}, diff --git a/templates/auth/signup_form.html b/templates/auth/signup_form.html index 1f0007e..855e5e8 100644 --- a/templates/auth/signup_form.html +++ b/templates/auth/signup_form.html @@ -25,8 +25,6 @@ -