Display locations

This commit is contained in:
Adrian Woźniak 2023-08-23 16:27:32 +02:00
parent 7a3471ec0a
commit 2e688b7c49
4 changed files with 18 additions and 8 deletions

View File

@ -241,7 +241,10 @@ async fn create(
);
}
unreachable!()
HttpResponse::SeeOther()
.append_header(("Location", "/parking-spaces/all"))
.append_header(("HX-Redirect", "/parking-spaces/all"))
.finish()
}
async fn ensure_locations(db: Arc<sea_orm::DatabaseConnection>) {

View File

@ -4,7 +4,7 @@
{% for error in errors.global() %}
<oswilno-error>{{error|t(lang,t)}}</oswilno-error>
{% endfor %}
<form hx-post="/login" hx-target="#main-view">
<form hx-post="/parking-spaces/create" hx-target="main">
<div class="mb-4">
<label
for="location_id"

View File

@ -301,11 +301,13 @@ async fn login_inner(
actix_web::cookie::Cookie::build(actix_jwt_session::DEFAULT_HEADER_NAME, &bearer_token)
.http_only(true)
.finish();
Ok(HttpResponse::Ok()
Ok(HttpResponse::SeeOther()
.append_header((
actix_jwt_session::DEFAULT_HEADER_NAME,
format!("Bearer {bearer_token}").as_str(),
))
.append_header(("Location", "/"))
.append_header(("HX-Redirect", "/"))
.cookie(cookie)
.body(""))
}
@ -553,9 +555,7 @@ impl JwtSigningKeys {
fn load_or_create() -> Self {
match Self::load_from_files() {
Ok(s) => s,
Err(e) if e.kind() == std::io::ErrorKind::NotFound => {
Self::generate().unwrap()
}
Err(e) if e.kind() == std::io::ErrorKind::NotFound => Self::generate().unwrap(),
Err(e) => panic!("{:?}", e),
}
}
@ -585,6 +585,9 @@ impl JwtSigningKeys {
let mut e = std::fs::File::open("./config/jwt-decoding.bin")?;
e.read_to_end(&mut buf).unwrap();
let decoding_key = DecodingKey::from_ed_der(&buf);
Ok(Self { encoding_key, decoding_key })
Ok(Self {
encoding_key,
decoding_key,
})
}
}

View File

@ -13,5 +13,9 @@ pub fn t<T: std::fmt::Display + std::fmt::Debug>(
}
pub fn skip_if<T: std::fmt::Display + PartialEq + Copy>(n: &T, skip: T) -> Result<String> {
Ok(if n == &skip { "".to_string() } else { n.to_string() })
Ok(if n == &skip {
"".to_string()
} else {
n.to_string()
})
}