tailwindcss + wip auth

This commit is contained in:
Per Stark
2024-12-12 20:59:27 +01:00
parent 766653030d
commit 96f2e765f6
26 changed files with 2496 additions and 300 deletions

36
src/server/routes/auth.rs Normal file
View File

@@ -0,0 +1,36 @@
use axum::{
extract::State,
response::{Html, IntoResponse},
Form,
};
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};
#[derive(Deserialize, Serialize)]
pub struct SignupParams {
pub email: String,
pub password: String,
}
pub async fn show_signup_form(State(state): State<AppState>) -> Html<String> {
let context = tera::Context::new();
let html = state
.tera
.render("auth/signup.html", &context)
.unwrap_or_else(|_| "<h1>Error rendering template</h1>".to_string());
Html(html)
}
pub async fn signup_handler(
State(state): State<AppState>,
auth: AuthSession<User, String, SessionSurrealPool<Any>, Surreal<Any>>,
Form(form): Form<SignupParams>,
) -> Result<impl IntoResponse, ApiError> {
let user = User::create_new(form.email, form.password, &state.surreal_db_client).await?;
auth.login_user(user.id);
Ok(())
}

View File

@@ -1,13 +1,21 @@
use axum::{extract::State, response::Html};
use axum_session_auth::AuthSession;
use axum_session_surreal::SessionSurrealPool;
use serde_json::json;
use surrealdb::{engine::any::Any, Surreal};
use tera::Context;
use tracing::info;
use crate::{error::ApiError, server::AppState};
use crate::{error::ApiError, server::AppState, storage::types::user::User};
pub async fn index_handler(State(state): State<AppState>) -> Result<Html<String>, ApiError> {
pub async fn index_handler(
State(state): State<AppState>,
auth: AuthSession<User, String, SessionSurrealPool<Any>, Surreal<Any>>,
) -> Result<Html<String>, ApiError> {
info!("Displaying index page");
info!("{:?}", auth.current_user);
let queue_length = state.rabbitmq_consumer.get_queue_length().await?;
let output = state

View File

@@ -1,3 +1,4 @@
pub mod auth;
pub mod file;
pub mod index;
pub mod ingress;