diff --git a/sql/schema.sql b/sql/schema.sql index 2538c4c..baf7a5f 100644 --- a/sql/schema.sql +++ b/sql/schema.sql @@ -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'); \ No newline at end of file +-- 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'); diff --git a/src/controller/mod.rs b/src/controller/mod.rs index 5cfed08..b1984bc 100644 --- a/src/controller/mod.rs +++ b/src/controller/mod.rs @@ -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() } diff --git a/src/controller/register.rs b/src/controller/register.rs index ff09cb6..17d1d52 100644 --- a/src/controller/register.rs +++ b/src/controller/register.rs @@ -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() } diff --git a/src/main.rs b/src/main.rs index 12c6da6..e223d41 100644 --- a/src/main.rs +++ b/src/main.rs @@ -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,], diff --git a/src/view/mod.rs b/src/view/mod.rs index 9477f4d..cfb3ead 100644 --- a/src/view/mod.rs +++ b/src/view/mod.rs @@ -1,4 +1,5 @@ use maud::{html, Markup, DOCTYPE}; +use rocket::Request; pub mod fragments; pub mod login; @@ -26,12 +27,33 @@ pub fn default_skeleton(content: Markup) -> Markup { } #[catch(401)] -pub fn not_authorized() -> Markup { - 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." +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;" + { + "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." + } + } + }) + } } diff --git a/src/view/register.rs b/src/view/register.rs index a6a51ae..7deae3c 100644 --- a/src/view/register.rs +++ b/src/view/register.rs @@ -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: ''}" { diff --git a/tailwind.config.js b/tailwind.config.js index e9c97ae..4c4031c 100644 --- a/tailwind.config.js +++ b/tailwind.config.js @@ -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', + }, + } + }) + } + ], }