Ajoute l'authentification et le partage de listes
- Inscription / connexion par email + mot de passe (argon2), prénom ou pseudo enregistré ; session par cookie HttpOnly, jeton haché en base. - Listes privées par propriétaire, partageables par email ; les membres peuvent gérer les articles et quitter la liste. - Contrôle d'accès dans chaque server function. - Suggestions propres à chaque utilisateur. - Avatar avec initiales et feuille de compte (déconnexion). - La page 404 reçoit le pool SQLite. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
9536cf0dbe
commit
cbda09ed40
12 files changed
+1083
-60
No files matched your search
+42
-7
@@ -1,3 +1,4 @@
|
||||
mod account;
|
||||
mod icons;
|
||||
mod sheets;
|
||||
mod tiles;
|
||||
@@ -13,7 +14,8 @@ use leptos_router::hooks::use_params_map;
|
||||
use leptos_router::path;
|
||||
|
||||
use crate::api::{get_items, get_lists, get_suggestions};
|
||||
use crate::model::{Item, ShoppingList, Suggestion};
|
||||
use crate::model::{Item, ShoppingList, Suggestion, User};
|
||||
use account::{AccountSheet, Auth, LoginPage, RegisterPage, RequireUser};
|
||||
use sheets::{ItemEditor, ItemSheet, ListEditor, ListSheet};
|
||||
use tiles::{BasketTile, ItemTile, SuggestionTile};
|
||||
|
||||
@@ -41,6 +43,7 @@ pub fn shell(options: LeptosOptions) -> impl IntoView {
|
||||
#[component]
|
||||
pub fn App() -> impl IntoView {
|
||||
provide_meta_context();
|
||||
Auth::provide();
|
||||
|
||||
view! {
|
||||
<Stylesheet id="leptos" href="/pkg/lisette.css" />
|
||||
@@ -59,6 +62,8 @@ pub fn App() -> impl IntoView {
|
||||
<Routes fallback=|| view! { <p class="p-4">"Page introuvable."</p> }>
|
||||
<Route path=path!("/") view=ListsPage />
|
||||
<Route path=path!("/l/:id") view=ListsPage />
|
||||
<Route path=path!("/connexion") view=LoginPage />
|
||||
<Route path=path!("/inscription") view=RegisterPage />
|
||||
</Routes>
|
||||
</Router>
|
||||
}
|
||||
@@ -74,6 +79,9 @@ pub struct Ctx {
|
||||
optimistic: RwSignal<HashMap<i64, bool>>,
|
||||
item_editor: RwSignal<Option<ItemEditor>>,
|
||||
list_editor: RwSignal<Option<ListEditor>>,
|
||||
account_open: RwSignal<bool>,
|
||||
user_id: i64,
|
||||
auth: Auth,
|
||||
}
|
||||
|
||||
impl Ctx {
|
||||
@@ -89,11 +97,20 @@ impl Ctx {
|
||||
on_ok(value);
|
||||
self.refresh.update(|n| *n += 1);
|
||||
}
|
||||
Err(err) => self.error.set(Some(error_message(err))),
|
||||
Err(err) => self.report(err),
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
fn report(self, err: ServerFnError) {
|
||||
let msg = error_message(err);
|
||||
if msg == crate::api::NOT_LOGGED_IN {
|
||||
// The guard sends the user back to the login page.
|
||||
self.auth.me.refetch();
|
||||
}
|
||||
self.error.set(Some(msg));
|
||||
}
|
||||
|
||||
fn toggle(self, item: &Item) {
|
||||
let (id, checked) = (item.id, !item.checked);
|
||||
self.optimistic.update(|map| {
|
||||
@@ -104,7 +121,7 @@ impl Ctx {
|
||||
self.optimistic.update(|map| {
|
||||
map.remove(&id);
|
||||
});
|
||||
self.error.set(Some(error_message(err)));
|
||||
self.report(err);
|
||||
}
|
||||
});
|
||||
}
|
||||
@@ -119,12 +136,20 @@ fn error_message(err: ServerFnError) -> String {
|
||||
|
||||
#[component]
|
||||
fn ListsPage() -> impl IntoView {
|
||||
view! { <RequireUser render=|user| view! { <ListsView user /> } /> }
|
||||
}
|
||||
|
||||
#[component]
|
||||
fn ListsView(user: User) -> impl IntoView {
|
||||
let ctx = Ctx {
|
||||
refresh: RwSignal::new(0),
|
||||
error: RwSignal::new(None),
|
||||
optimistic: RwSignal::new(HashMap::new()),
|
||||
item_editor: RwSignal::new(None),
|
||||
list_editor: RwSignal::new(None),
|
||||
account_open: RwSignal::new(false),
|
||||
user_id: user.id,
|
||||
auth: expect_context::<Auth>(),
|
||||
};
|
||||
provide_context(ctx);
|
||||
|
||||
@@ -157,12 +182,13 @@ fn ListsPage() -> impl IntoView {
|
||||
<h1 class="font-display text-5xl leading-[0.9] font-extrabold tracking-tight">
|
||||
"mes"<br />"listes"
|
||||
</h1>
|
||||
<div
|
||||
<button
|
||||
class="grid size-14 shrink-0 place-items-center rounded-2xl bg-ink font-display text-lg font-bold text-lime"
|
||||
aria-label="Profil"
|
||||
aria-label="Mon compte"
|
||||
on:click=move |_| ctx.account_open.set(true)
|
||||
>
|
||||
"CL"
|
||||
</div>
|
||||
{user.initials()}
|
||||
</button>
|
||||
</header>
|
||||
|
||||
<ErrorBanner />
|
||||
@@ -192,6 +218,7 @@ fn ListsPage() -> impl IntoView {
|
||||
|
||||
<ItemSheet list_id=active_id />
|
||||
<ListSheet />
|
||||
<AccountSheet user />
|
||||
}
|
||||
}
|
||||
|
||||
@@ -272,6 +299,14 @@ fn ListsContent(
|
||||
<h2 class="mt-1 font-display text-[1.7rem] leading-tight font-bold tracking-tight">
|
||||
{list.name.clone()}
|
||||
</h2>
|
||||
{(!list.is_owner)
|
||||
.then(|| {
|
||||
view! {
|
||||
<p class="mt-1 font-medium text-ink/60">
|
||||
{format!("Partagée par {}", list.owner_name)}
|
||||
</p>
|
||||
}
|
||||
})}
|
||||
<p class="mt-1 text-lg text-ink/70">{move || remaining_text(remaining.get(), total())}</p>
|
||||
|
||||
<div class="mt-5 grid grid-cols-3 gap-3">
|
||||
|
||||
Reference in new issue
Block a user