Working on session

This commit is contained in:
eraden 2023-08-16 08:48:39 +02:00
parent dcb2276ed3
commit 4d0e589a44
7 changed files with 77 additions and 11 deletions

View File

@ -767,6 +767,10 @@ select {
left: 0px;
}
.top-0 {
top: 0px;
}
.z-50 {
z-index: 50;
}
@ -849,6 +853,10 @@ select {
height: 2rem;
}
.h-full {
height: 100%;
}
.min-h-screen {
min-height: 100vh;
}
@ -901,6 +909,10 @@ select {
flex-wrap: wrap;
}
.content-center {
align-content: center;
}
.items-center {
align-items: center;
}
@ -979,6 +991,11 @@ select {
border-color: rgb(209 213 219 / var(--tw-border-opacity));
}
.bg-black {
--tw-bg-opacity: 1;
background-color: rgb(0 0 0 / var(--tw-bg-opacity));
}
.bg-blue-700 {
--tw-bg-opacity: 1;
background-color: rgb(29 78 216 / var(--tw-bg-opacity));
@ -1009,6 +1026,14 @@ select {
background-color: rgb(255 255 255 / var(--tw-bg-opacity));
}
.bg-cover {
background-size: cover;
}
.bg-center {
background-position: center;
}
.p-2 {
padding: 0.5rem;
}
@ -1046,6 +1071,10 @@ select {
padding-bottom: 0.75rem;
}
.pb-32 {
padding-bottom: 8rem;
}
.pl-10 {
padding-left: 2.5rem;
}
@ -1058,6 +1087,10 @@ select {
padding-right: 1rem;
}
.pt-16 {
padding-top: 4rem;
}
.text-2xl {
font-size: 1.5rem;
line-height: 2rem;
@ -1134,6 +1167,10 @@ select {
color: rgb(255 255 255 / var(--tw-text-opacity));
}
.opacity-75 {
opacity: 0.75;
}
.shadow {
--tw-shadow: 0 1px 3px 0 rgb(0 0 0 / 0.1), 0 1px 2px -1px rgb(0 0 0 / 0.1);
--tw-shadow-colored: 0 1px 3px 0 var(--tw-shadow-color), 0 1px 2px -1px var(--tw-shadow-color);

View File

@ -6,7 +6,7 @@ use oswilno_contract::accounts;
use oswilno_contract::parking_space_rents;
use oswilno_contract::parking_spaces;
use oswilno_session::{Authenticated, MaybeAuthenticated};
use oswilno_view::{is_partial, Layout, Main, MainOpts, SessionOpts, SearchOpts};
use oswilno_view::{is_partial, Layout, Main, MainOpts, SearchOpts, SessionOpts, Blank};
use sea_orm::prelude::*;
use sea_orm::ActiveValue::{NotSet, Set};
use std::collections::HashMap;
@ -48,6 +48,7 @@ async fn all_parking_spaces(
let parking_spaces = load_parking_spaces(db).await;
let main = Main {
body: parking_spaces,
title: Blank,
opts: MainOpts {
session: session.into_option().map(|s| SessionOpts {
login: s.subject.to_owned(),

View File

@ -60,7 +60,8 @@ async fn main() -> std::io::Result<()> {
.app_data(Data::new(l10n.clone()))
.configure(oswilno_parking_space::mount)
.configure(oswilno_admin::mount)
.configure(web_assets::configure)
.configure(web_assets::mount)
.configure(oswilno_view::mount)
.configure(|c| session_config.app_data(c))
})
.bind(("0.0.0.0", 8080))?

View File

@ -9,7 +9,7 @@ use askama_actix::Template;
use autometrics::autometrics;
use garde::Validate;
use jsonwebtoken::*;
use oswilno_view::{Errors, Lang, Layout, Main, MainOpts, TranslationStorage};
use oswilno_view::{Errors, Lang, Layout, Main, MainOpts, TranslationStorage, Blank};
use ring::rand::SystemRandom;
use ring::signature::{Ed25519KeyPair, KeyPair};
use sea_orm::DatabaseConnection;
@ -169,6 +169,7 @@ async fn login_view(req: HttpRequest, t: Data<TranslationStorage>) -> HttpRespon
search: None,
session: None,
},
title: Blank,
}
.render()
} else {
@ -184,6 +185,7 @@ async fn login_view(req: HttpRequest, t: Data<TranslationStorage>) -> HttpRespon
show: true,
..Default::default()
},
title: Blank,
},
}
.render()
@ -344,6 +346,7 @@ async fn register_view(req: HttpRequest, t: Data<TranslationStorage>) -> HttpRes
lang: Lang::Pl,
errors: oswilno_view::Errors::default(),
},
title: Blank,
opts: MainOpts {
show: true,
search: None,
@ -360,6 +363,7 @@ async fn register_view(req: HttpRequest, t: Data<TranslationStorage>) -> HttpRes
lang: Lang::Pl,
errors: oswilno_view::Errors::default(),
},
title: Blank,
opts: MainOpts::default(),
},
}

View File

@ -1,12 +1,26 @@
use std::collections::HashMap;
use std::sync::{Arc, RwLock};
use actix_web::HttpRequest;
use actix_web::http::header::ContentType;
use actix_web::web::ServiceConfig;
use actix_web::{get, HttpRequest, HttpResponse};
pub use lang::*;
pub mod filters;
pub mod lang;
pub fn mount(config: &mut ServiceConfig) {
config.service(banner);
}
#[get("/banner.jpg")]
async fn banner() -> HttpResponse {
const BANNER_BLOB: &[u8; 314124] = include_bytes!("../assets/banner.jpg");
HttpResponse::Ok()
.append_header(ContentType::jpeg())
.body(BANNER_BLOB.as_slice())
}
pub fn is_partial(req: &HttpRequest) -> bool {
req.headers()
.get("Accept")
@ -43,14 +57,19 @@ impl Default for MainOpts {
}
}
#[derive(Debug, askama_actix::Template)]
#[derive(Debug, Default, askama_actix::Template)]
#[template(source = "", ext = "txt")]
pub struct Blank;
#[derive(Debug, Default, askama_actix::Template)]
#[template(path = "../templates/main.html")]
pub struct Main<BodyTemplate: askama::Template> {
pub struct Main<BodyTemplate: askama::Template, TitleTemplate: askama::Template = Blank> {
pub title: TitleTemplate,
pub body: BodyTemplate,
pub opts: MainOpts,
}
#[derive(Debug, askama_actix::Template)]
#[derive(Debug, Default, askama_actix::Template)]
#[template(path = "../templates/base.html")]
pub struct Layout<BodyTemplate: askama::Template> {
pub main: Main<BodyTemplate>,

View File

@ -1,6 +1,10 @@
<main class="relative">
<div class="absolute top-0 w-full h-full bg-center bg-cover" style="background-image:url('/banner.jpg')">
</div>
<main>
{% include "navbar.html" %}
<section id="main-header" class="relative pt-16 pb-32 flex content-center items-center justify-center" style="min-height:75vh">
<div class="absolute top-0 w-full h-full bg-center bg-cover" style="background-image:url('/banner.jpg')">
<span id="blackOverlay" class="w-full h-full absolute opacity-75 bg-black"></span>
</div>
{{ title|safe }}
</section>
{{ body|safe }}
</main>

View File

@ -2,7 +2,7 @@ use std::{borrow::Cow, sync::Once};
use actix_web::{get, web::ServiceConfig, HttpResponse};
pub fn configure(config: &mut ServiceConfig) {
pub fn mount(config: &mut ServiceConfig) {
config
.service(serve_build_js)
.service(serve_build_js_map)