Improve 401 error html response
This commit is contained in:
parent
e1b9daa931
commit
9249de94ce
@ -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');
|
||||||
|
@ -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()
|
||||||
}
|
}
|
||||||
|
@ -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()
|
||||||
}
|
}
|
||||||
|
@ -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,],
|
||||||
|
@ -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,12 +27,33 @@ pub fn default_skeleton(content: Markup) -> Markup {
|
|||||||
}
|
}
|
||||||
|
|
||||||
#[catch(401)]
|
#[catch(401)]
|
||||||
pub fn not_authorized() -> Markup {
|
pub fn not_authorized(req: &Request) -> Markup {
|
||||||
html! {
|
// get the uri from the request
|
||||||
p style="background-color: rgb(248, 113, 113); color: white; padding: 0.5rem; border-radius: 0.5rem;"
|
let uri = req.uri().to_string();
|
||||||
{
|
|
||||||
"Tu sesión ha expirado, o no tienes permiso para ver esta página."
|
// If the uri starts with "/f", then we are dealing with an API request
|
||||||
" Por favor, inicia sesión o contacta al administrador."
|
// 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;"
|
||||||
|
{
|
||||||
|
"Tu sesión ha expirado, o no tienes permiso para ver esta página."
|
||||||
|
" 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 {
|
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: ''}"
|
||||||
{
|
{
|
||||||
|
@ -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',
|
||||||
|
},
|
||||||
|
}
|
||||||
|
})
|
||||||
|
}
|
||||||
|
],
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user