Fix the redirect issue with htmx on the register page and actually commit the changes for static assets for htmx, tailwindcss and nixin logo that I missed in previous commit
This commit is contained in:
parent
72f046cb29
commit
09bf058c05
4 changed files with 29 additions and 8 deletions
|
@ -4,9 +4,12 @@
|
|||
|
||||
<head>
|
||||
<title>{% block title %}{% endblock title %}</title>
|
||||
|
||||
<!--
|
||||
<script src="https://unpkg.com/htmx.org@2.0.0/dist/htmx.min.js"></script>
|
||||
<script src="https://cdn.tailwindcss.com?plugins=forms,typography,aspect-ratio"></script>
|
||||
-->
|
||||
<script src="/static/htmx.min.js"></script>
|
||||
<script src="/static/tailwindcss.js"></script>
|
||||
{% block head %}
|
||||
|
||||
{% endblock head %}
|
||||
|
|
|
@ -7,7 +7,7 @@ Index
|
|||
{% block content %}
|
||||
<div class="flex min-h-full flex-col justify-center px-6 py-12 lg:px-8">
|
||||
<div class="sm:mx-auto sm:w-full sm:max-w-sm">
|
||||
<img class="mx-auto h-12 w-auto" src="https://nixin.distrilab.eu/logo-nixin.svg" alt="NixiN">
|
||||
<img class="mx-auto h-12 w-auto" src="/static/logo-nixin.svg" alt="NixiN">
|
||||
<h2 class="mt-10 text-center text-2xl font-bold leading-9 tracking-tight text-gray-900">
|
||||
Index
|
||||
</h2>
|
||||
|
|
|
@ -21,7 +21,7 @@ Login
|
|||
-->
|
||||
<div class="flex min-h-full flex-col justify-center px-6 py-12 lg:px-8">
|
||||
<div class="sm:mx-auto sm:w-full sm:max-w-sm">
|
||||
<img class="mx-auto h-12 w-auto" src="https://nixin.distrilab.eu/logo-nixin.svg" alt="NixiN">
|
||||
<img class="mx-auto h-12 w-auto" src="/static/logo-nixin.svg" alt="NixiN">
|
||||
<h2 class="mt-10 text-center text-2xl font-bold leading-9 tracking-tight text-gray-900">Sign in to your account</h2>
|
||||
</div>
|
||||
|
||||
|
|
|
@ -8,8 +8,8 @@ use axum::{
|
|||
extract::State,
|
||||
//extract::Query,
|
||||
response::{/*IntoResponse,*/ Redirect},
|
||||
http::StatusCode,
|
||||
//Json,
|
||||
http::{StatusCode, header::{self, HeaderValue, HeaderMap}},
|
||||
Form};
|
||||
use axum_extra::extract::cookie::{CookieJar, Cookie};
|
||||
|
||||
|
@ -128,7 +128,11 @@ pub async fn do_register(
|
|||
let res = AuthMailer::send_welcome(&ctx, &user).await;
|
||||
match res {
|
||||
Ok(()) => {
|
||||
return format::redirect("/login");
|
||||
let mut headers = HeaderMap::new();
|
||||
//ToDo: modifiy below to avoid using ugly unwrap
|
||||
headers.insert("HX-Location", "/".parse().unwrap());
|
||||
|
||||
return Ok(headers.into_response());
|
||||
}
|
||||
Err(err) => {
|
||||
return views::home::error(&v,&format!("failed to send welcome email: {}",err.to_string()));
|
||||
|
@ -179,11 +183,25 @@ pub async fn do_login(
|
|||
else {
|
||||
return Ok((jar, views::home::error(&v,"Login failed: invalid email or password")));
|
||||
};
|
||||
let mut headers = HeaderMap::new();
|
||||
//ToDo: modifiy below to avoid using ugly unwrap
|
||||
headers.insert(header::AUTHORIZATION, HeaderValue::from_str(&token).unwrap());
|
||||
headers.insert("HX-Location", "/".parse().unwrap());
|
||||
|
||||
// We do not really need to return the index view in the response body
|
||||
// because the HX-Location header will trigger htmx to fetch it from
|
||||
// the client.
|
||||
// We are doing it here only to test if it allows degrading gracefully
|
||||
// on java script disabled clients.
|
||||
// See do_register() for an implementation of htmx redirect with
|
||||
// an empty body
|
||||
let index_view = views::home::index(&v,&user).unwrap();
|
||||
// Also we are returning the JWT token both in a header and in a cookie
|
||||
// This is also done for test purposes only.
|
||||
// Only one of these should be done, the one used in the auth configuration.
|
||||
Ok((
|
||||
// the updated jar must be returned for the changes
|
||||
// to be included in the response
|
||||
jar.add(Cookie::new("token", token)),
|
||||
Ok(Redirect::to("/").into_response()),))
|
||||
Ok((headers, index_view).into_response()),))
|
||||
}
|
||||
_ => {
|
||||
return Ok((jar, views::home::error(&v,"Login failed: you need to provide an email and a password")));
|
||||
|
|
Loading…
Reference in a new issue