Improve 401 error html response
This commit is contained in:
parent
e1b9daa931
commit
9249de94ce
@ -14,7 +14,7 @@ CREATE TABLE user (
|
||||
);
|
||||
|
||||
|
||||
|
||||
-- This is the hash & salt for a password "123456789"
|
||||
-- $argon2id$v=19$m=65536,t=4,p=1$TE1wdklnMEpsMDAveWhzYw$nsKg2fALcXZ8AquM7jPGBUjM3Dyg5tgbDATKMeKPtfQ
|
||||
-- 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');
|
||||
-- This sentence creates the first user, the super admin, with a password "123456789"
|
||||
-- TODO: Change the password for the super admin to a secure one
|
||||
insert into user (user_email, user_password, user_names, user_surnames)
|
||||
values ('administracion@eegsac.com', '$argon2id$v=19$m=65536,t=4,p=1$TE1wdklnMEpsMDAveWhzYw$nsKg2fALcXZ8AquM7jPGBUjM3Dyg5tgbDATKMeKPtfQ', 'Administracion', 'EEGSAC');
|
||||
|
@ -17,6 +17,6 @@ pub fn index(user: RegularUser) -> Markup {
|
||||
}
|
||||
|
||||
#[get("/", rank = 2)]
|
||||
pub fn index_login(cookies: &CookieJar<'_>) -> Markup {
|
||||
pub fn index_login() -> Markup {
|
||||
crate::view::login::login()
|
||||
}
|
||||
|
@ -1,6 +1,8 @@
|
||||
use maud::Markup;
|
||||
|
||||
use crate::auth::RegularUser;
|
||||
|
||||
#[get("/register")]
|
||||
pub fn get() -> Markup {
|
||||
pub fn get(user: RegularUser) -> Markup {
|
||||
crate::view::register::register()
|
||||
}
|
||||
|
@ -20,7 +20,14 @@ fn rocket() -> _ {
|
||||
.manage(auth::session::Sessions::new())
|
||||
.register("/", catchers![view::not_authorized])
|
||||
.attach(DefaultDB::init())
|
||||
.mount("/", routes![controller::index, controller::index_login,])
|
||||
.mount(
|
||||
"/",
|
||||
routes![
|
||||
controller::index,
|
||||
controller::index_login,
|
||||
controller::register::get,
|
||||
],
|
||||
)
|
||||
.mount(
|
||||
"/f",
|
||||
routes![controller::user::create_user, controller::login::login,],
|
||||
|
@ -1,4 +1,5 @@
|
||||
use maud::{html, Markup, DOCTYPE};
|
||||
use rocket::Request;
|
||||
|
||||
pub mod fragments;
|
||||
pub mod login;
|
||||
@ -26,7 +27,13 @@ pub fn default_skeleton(content: Markup) -> Markup {
|
||||
}
|
||||
|
||||
#[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! {
|
||||
p style="background-color: rgb(248, 113, 113); color: white; padding: 0.5rem; border-radius: 0.5rem;"
|
||||
{
|
||||
@ -34,4 +41,19 @@ pub fn not_authorized() -> Markup {
|
||||
" Por favor, inicia sesión o contacta al administrador."
|
||||
}
|
||||
}
|
||||
}
|
||||
// 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."
|
||||
}
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
@ -4,7 +4,7 @@ use super::default_skeleton;
|
||||
|
||||
pub fn register() -> Markup {
|
||||
default_skeleton(html! {
|
||||
h1 { "Registrar nuevo usuario" }
|
||||
h1 { "Registrar nuevo usuario del sistema" }
|
||||
div
|
||||
x-data="{user_name: '', user_surname: '', user_email: '', user_password: ''}"
|
||||
{
|
||||
|
@ -1,5 +1,8 @@
|
||||
/** @type {import('tailwindcss').Config} */
|
||||
module.exports = {
|
||||
corePlugins: {
|
||||
container: false
|
||||
},
|
||||
content: [
|
||||
"./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',
|
||||
},
|
||||
}
|
||||
})
|
||||
}
|
||||
],
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user