Implemented user authentication.

This commit is contained in:
2023-09-22 21:26:13 +02:00
parent 0bac17f2eb
commit 17f628739f
23 changed files with 704 additions and 326 deletions
+1 -1
View File
@@ -1,7 +1,7 @@
use crate::backend::data::Company;
use crate::backend::company::UpdateCompany;
use crate::components::modal_box::{
DialogOpener, DlgNotLoaded, ModalBody, ModalDialog, ModalFooter,
DialogOpener, ModalBody, ModalDialog, ModalFooter,
};
use crate::components::server_err::ServerErr;
use crate::locales::trl;
+16 -12
View File
@@ -1,7 +1,6 @@
use leptos::*;
use serde::de::Unexpected::Option;
use crate::backend::company::get_company;
use crate::backend::data::Company;
use crate::backend::data::{ApiResponse, Company};
use crate::components::modal_box::DialogOpener;
use crate::locales::trl;
use crate::pages::company_edit::CompanyEdit;
@@ -20,18 +19,23 @@ pub fn CompanyInfo() -> impl IntoView {
<p class="card-text">
<Transition fallback=move || view! {<p>{trl("Loading...")}</p> }>
{move || {
company.read().map(|c| match c {
Err(e) => {view! {<p>{trl("Error loading data")}</p>
<p>{e.to_string()}</p>
company.get().map(|c| match c {
Err(e) => {view! {<div><p>{trl("Error loading data")}</p>
<p>{e.to_string()}</p></div>
}}
Ok(c) => {
set_cmp.update(|cmp| *cmp = c.clone());
view! {
<p><b>{c.name}</b></p>
<p>{c.street}" "{c.house_number}<br/>
{c.zip_code}" "{c.city}
</p>
}}
match c {
ApiResponse::Data(d) => {set_cmp.update(|cmp| *cmp = d.clone());
view! {<div>
<p><b>{d.name}</b></p>
<p>{d.street}" "{d.house_number}<br/>
{d.zip_code}" "{d.city}
</p></div>}
}
ApiResponse::Error(_) => {view! {<div><p>{trl("Error loading data")}</p></div>}}
}
}
})
}}
</Transition>
-11
View File
@@ -1,6 +1,5 @@
use leptos::*;
use crate::components::modal_box::{DialogOpener, ModalDialog, ModalBody, ModalFooter};
use crate::server_fn::*;
use crate::locales::trl;
/// Renders the home page of your application.
@@ -65,16 +64,6 @@ pub fn HomePage() -> impl IntoView {
<h1>"Welcome to Leptos!"</h1>
<button on:click=on_click>"Click Me: " {count}</button>
<button on:click=move |_| dialog.show()>"Dialog"</button>
<button on:click=move |_| {
spawn_local(async move {
set_session().await;
});
}>"Session"</button>
<button on:click=move |_| {
spawn_local(async move {
get_session().await;
});
}>"Session get"</button>
<p>{trl("testik!")}</p>
}
}
+74
View File
@@ -0,0 +1,74 @@
use leptos::*;
use leptos_meta::*;
use leptos_router::ActionForm;
use crate::backend::user::Login;
#[component]
pub fn Login() -> impl IntoView {
let login = create_server_action::<Login>();
view! {
<Link rel="stylesheet" href="/vendor/css/pages/page-auth.css" />
<div class="authentication-wrapper authentication-basic container-p-y">
<div class="authentication-inner">
<div class="card">
<div class="card-body">
//<!-- Logo -->
<div class="app-brand justify-content-center">
<a href="index.html" class="app-brand-link gap-2">
<span class="app-brand-logo demo">
</span>
//<span class="app-brand-text demo text-body fw-bolder">Sneat</span>
</a>
</div>
//<!-- /Logo -->
<h4 class="mb-2">"Welcome to Rezervator 👋"</h4>
<p class="mb-4">"Please sign-in to your account and start the adventure"</p>
<ActionForm action=login>
<div class="mb-3">
<label for="username" class="form-label">"Username"</label>
<input
type="text"
class="form-control"
id="username"
name="username"
placeholder="Enter your username"
autofocus
/>
</div>
<div class="mb-3 form-password-toggle">
<div class="d-flex justify-content-between">
<label class="form-label" for="password">"Password"</label>
<a href="auth-forgot-password-basic.html">
<small>"Forgot Password?"</small>
</a>
</div>
<div class="input-group input-group-merge">
<input
type="password"
id="password"
class="form-control"
name="password"
aria-describedby="password"
/>
<span class="input-group-text cursor-pointer"><i class="bx bx-hide"></i></span>
</div>
</div>
<div class="mb-3">
</div>
<div class="mb-3">
<button class="btn btn-primary d-grid w-100" type="submit">"Sign in"</button>
</div>
</ActionForm>
</div>
</div>
</div>
</div>
}
}
+2
View File
@@ -2,3 +2,5 @@ pub mod home_page;
pub mod settings;
pub mod company_info;
mod company_edit;
pub mod login;
pub mod public;
+8
View File
@@ -0,0 +1,8 @@
use leptos::*;
#[component]
pub fn Public() -> impl IntoView {
view! {
<div>"public"</div>
}
}