Improve 401 error html response

master
fernando 2024-02-15 16:33:46 -05:00
parent e1b9daa931
commit 9249de94ce
7 changed files with 69 additions and 15 deletions

View File

@ -14,7 +14,7 @@ CREATE TABLE user (
); );
-- This sentence creates the first user, the super admin, with a password "123456789"
-- This is the hash & salt for a password "123456789" -- TODO: Change the password for the super admin to a secure one
-- $argon2id$v=19$m=65536,t=4,p=1$TE1wdklnMEpsMDAveWhzYw$nsKg2fALcXZ8AquM7jPGBUjM3Dyg5tgbDATKMeKPtfQ insert into user (user_email, user_password, user_names, user_surnames)
-- insert into user (user_email, user_password, user_names, user_surnames) values ('fernando@eegsac.com', '$argon2id$v=19$m=65536,t=4,p=1$TE1wdklnMEpsMDAveWhzYw$nsKg2fALcXZ8AquM7jPGBUjM3Dyg5tgbDATKMeKPtfQ', 'Fernando', 'Araoz'); values ('administracion@eegsac.com', '$argon2id$v=19$m=65536,t=4,p=1$TE1wdklnMEpsMDAveWhzYw$nsKg2fALcXZ8AquM7jPGBUjM3Dyg5tgbDATKMeKPtfQ', 'Administracion', 'EEGSAC');

View File

@ -17,6 +17,6 @@ pub fn index(user: RegularUser) -> Markup {
} }
#[get("/", rank = 2)] #[get("/", rank = 2)]
pub fn index_login(cookies: &CookieJar<'_>) -> Markup { pub fn index_login() -> Markup {
crate::view::login::login() crate::view::login::login()
} }

View File

@ -1,6 +1,8 @@
use maud::Markup; use maud::Markup;
use crate::auth::RegularUser;
#[get("/register")] #[get("/register")]
pub fn get() -> Markup { pub fn get(user: RegularUser) -> Markup {
crate::view::register::register() crate::view::register::register()
} }

View File

@ -20,7 +20,14 @@ fn rocket() -> _ {
.manage(auth::session::Sessions::new()) .manage(auth::session::Sessions::new())
.register("/", catchers![view::not_authorized]) .register("/", catchers![view::not_authorized])
.attach(DefaultDB::init()) .attach(DefaultDB::init())
.mount("/", routes![controller::index, controller::index_login,]) .mount(
"/",
routes![
controller::index,
controller::index_login,
controller::register::get,
],
)
.mount( .mount(
"/f", "/f",
routes![controller::user::create_user, controller::login::login,], routes![controller::user::create_user, controller::login::login,],

View File

@ -1,4 +1,5 @@
use maud::{html, Markup, DOCTYPE}; use maud::{html, Markup, DOCTYPE};
use rocket::Request;
pub mod fragments; pub mod fragments;
pub mod login; pub mod login;
@ -26,7 +27,13 @@ pub fn default_skeleton(content: Markup) -> Markup {
} }
#[catch(401)] #[catch(401)]
pub fn not_authorized() -> Markup { pub fn not_authorized(req: &Request) -> Markup {
// get the uri from the request
let uri = req.uri().to_string();
// If the uri starts with "/f", then we are dealing with an API request
// and we should return a fragment
if uri.starts_with("/f") {
html! { html! {
p style="background-color: rgb(248, 113, 113); color: white; padding: 0.5rem; border-radius: 0.5rem;" p style="background-color: rgb(248, 113, 113); color: white; padding: 0.5rem; border-radius: 0.5rem;"
{ {
@ -35,3 +42,18 @@ pub fn not_authorized() -> Markup {
} }
} }
} }
// Otherwise, we are dealing with a regular request and we should return a full page
else {
default_skeleton(html! {
div class="container mx-auto" {
p style="background-color: rgb(248, 113, 113); color: white; padding: 0.5rem; border-radius: 0.5rem;"
{
"Tu sesión ha expirado, o no tienes permiso para realizar esta acción. "
"Por favor inicia sesión."
br;
"Si crees que esto es un error, contacta al administrador."
}
}
})
}
}

View File

@ -4,7 +4,7 @@ use super::default_skeleton;
pub fn register() -> Markup { pub fn register() -> Markup {
default_skeleton(html! { default_skeleton(html! {
h1 { "Registrar nuevo usuario" } h1 { "Registrar nuevo usuario del sistema" }
div div
x-data="{user_name: '', user_surname: '', user_email: '', user_password: ''}" x-data="{user_name: '', user_surname: '', user_email: '', user_password: ''}"
{ {

View File

@ -1,5 +1,8 @@
/** @type {import('tailwindcss').Config} */ /** @type {import('tailwindcss').Config} */
module.exports = { module.exports = {
corePlugins: {
container: false
},
content: [ content: [
"./src/**/*.{html,rs}", "./src/**/*.{html,rs}",
], ],
@ -11,5 +14,25 @@ module.exports = {
} }
}, },
}, },
plugins: [], plugins: [
function ({ addComponents }) {
addComponents({
'.container': {
width: '95%',
'@screen sm': {
maxWidth: '640px',
},
'@screen md': {
maxWidth: '768px',
},
'@screen lg': {
maxWidth: '1024px',
},
'@screen xl': {
maxWidth: '1280px',
},
}
})
}
],
} }