feat: consistent styling

This commit is contained in:
Per Stark
2024-12-28 23:54:58 +01:00
parent bdf7a12e9c
commit 0110ffa5bf
18 changed files with 256 additions and 209 deletions

View File

@@ -1,7 +1,7 @@
use axum::{
extract::State,
http::{StatusCode, Uri},
response::{IntoResponse, Redirect},
response::{Html, IntoResponse, Redirect},
Form,
};
use axum_htmx::{HxBoosted, HxRedirect};
@@ -52,10 +52,18 @@ pub async fn authenticate_user(
auth: AuthSession<User, String, SessionSurrealPool<Any>, Surreal<Any>>,
Form(form): Form<SignupParams>,
) -> Result<impl IntoResponse, ApiError> {
let user = User::authenticate(form.email, form.password, &state.surreal_db_client).await?;
let user = match User::authenticate(form.email, form.password, &state.surreal_db_client).await {
Ok(user) => user,
Err(_) => {
return Ok(Html("<p>Invalid email or password.</p>").into_response());
}
};
auth.login_user(user.id);
if form.remember_me.is_some_and(|string| string == *"on") {
auth.remember_user(true);
}
Ok((HxRedirect::from(Uri::from_static("/")), StatusCode::OK).into_response())
}

View File

@@ -1,9 +1,10 @@
use axum::{
extract::State,
response::{IntoResponse, Redirect},
http::{StatusCode, Uri},
response::{Html, IntoResponse, Redirect},
Form,
};
use axum_htmx::HxBoosted;
use axum_htmx::{HxBoosted, HxRedirect};
use axum_session_auth::AuthSession;
use axum_session_surreal::SessionSurrealPool;
use serde::{Deserialize, Serialize};
@@ -50,7 +51,14 @@ pub async fn process_signup_and_show_verification(
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?;
let user = match User::create_new(form.email, form.password, &state.surreal_db_client).await {
Ok(user) => user,
Err(_) => {
return Ok(Html("<p>User already exists</p>").into_response());
}
};
auth.login_user(user.id);
Ok(())
Ok((HxRedirect::from(Uri::from_static("/")), StatusCode::OK).into_response())
}