basket logic working

This commit is contained in:
Priec
2026-06-27 22:11:13 +02:00
parent 9bdf91e717
commit c549e2bc03
13 changed files with 301 additions and 37 deletions

View File

@@ -13,6 +13,7 @@ use serde_json::json;
use crate::{
controllers::auth as auth_controller,
controllers::cart,
controllers::i18n::current_lang,
mailers::auth::AuthMailer,
models::users::{self, LoginParams, RegisterParams},
@@ -105,9 +106,13 @@ async fn login(
let token = user
.generate_jwt(&jwt_secret.secret, jwt_secret.expiration)
.or_else(|_| unauthorized("unauthorized!"))?;
let cart_cookie = cart::cart_cookie_for_user(&ctx, user.id).await?;
format::render()
.cookies(&[auth_controller::auth_cookie(&token, jwt_secret.expiration)])?
.cookies(&[
auth_controller::auth_cookie(&token, jwt_secret.expiration),
cart_cookie,
])?
.redirect(home_for(&ctx, &user))
}
@@ -185,11 +190,13 @@ async fn login_totp(
let token = user
.generate_jwt(&jwt_secret.secret, jwt_secret.expiration)
.or_else(|_| unauthorized("unauthorized!"))?;
let cart_cookie = cart::cart_cookie_for_user(&ctx, user.id).await?;
format::render()
.cookies(&[
auth_controller::auth_cookie(&token, jwt_secret.expiration),
auth_controller::clear_totp_pending_cookie(),
cart_cookie,
])?
.redirect(home_for(&ctx, &user))
}
@@ -270,6 +277,7 @@ async fn register(
.into_active_model()
.set_email_verification_sent(&ctx.db)
.await?;
cart::claim_guest_cart(&ctx, &jar, user.id).await?;
// The account already exists; a failed email send shouldn't 500 the page —
// log it and let the user fall back to resend-verification.
@@ -304,7 +312,9 @@ async fn verify(
};
if user.email_verified_at.is_none() {
let user_id = user.id;
user.into_active_model().verified(&ctx.db).await?;
cart::claim_guest_cart(&ctx, &jar, user_id).await?;
}
verified_view(&v, &jar, true)
@@ -446,7 +456,10 @@ async fn set_password(
#[debug_handler]
async fn logout() -> Result<Response> {
format::render()
.cookies(&[auth_controller::clear_auth_cookie()])?
.cookies(&[
auth_controller::clear_auth_cookie(),
cart::cleared_cart_cookie(),
])?
.redirect("/login")
}