diff --git a/.vscode/settings.json b/.vscode/settings.json index 8900921..3b3d33b 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -2,4 +2,5 @@ "tailwindCSS.includeLanguages": { "rust": "html" }, + "rust-analyzer.showUnlinkedFileNotification": false, } diff --git a/Cargo.lock b/Cargo.lock index 2b93eba..e4abab3 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -351,6 +351,7 @@ version = "0.1.0" dependencies = [ "maud", "rocket", + "serde", "sqlx", ] @@ -1725,6 +1726,7 @@ dependencies = [ "sha2", "sqlx-core", "sqlx-mysql", + "sqlx-postgres", "sqlx-sqlite", "syn 1.0.109", "tempfile", diff --git a/Cargo.toml b/Cargo.toml index 6457660..19b0bee 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -8,4 +8,5 @@ edition = "2021" [dependencies] maud = { version = "0.26.0", features = ["rocket"] } rocket = "0.5.0" -sqlx = { version = "0.7.3", features = ["mysql"] } +serde = "1.0.196" +sqlx = { version = "0.7.3", features = ["postgres"] } diff --git a/sql/schema.sql b/sql/schema.sql new file mode 100644 index 0000000..7b63fcc --- /dev/null +++ b/sql/schema.sql @@ -0,0 +1,18 @@ +-- PostgreSQL schema for the database + +-- User table + +CREATE TABLE user ( + user_id SERIAL PRIMARY KEY, + user_email VARCHAR(50) NOT NULL, + user_password VARCHAR(255) NOT NULL, + user_names VARCHAR(50) NOT NULL, + user_surnames VARCHAR(50) NOT NULL, + + user_creation TIMESTAMP DEFAULT CURRENT_TIMESTAMP, + user_last_login TIMESTAMP DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP +); + + + + diff --git a/src/controller/mod.rs b/src/controller/mod.rs new file mode 100644 index 0000000..635ff07 --- /dev/null +++ b/src/controller/mod.rs @@ -0,0 +1,3 @@ + +pub mod user; + diff --git a/src/controller/user.rs b/src/controller/user.rs new file mode 100644 index 0000000..8b5d3c3 --- /dev/null +++ b/src/controller/user.rs @@ -0,0 +1,19 @@ +use maud::{Markup, html}; +use rocket::form::Form; + +#[derive(FromForm, Debug)] +pub struct UserCreate { + pub user_names: String, + pub user_surnames: String, + pub user_email: String, + pub user_password: String, +} + +#[post("/user", data = "")] +pub async fn create_user(user: Form) -> Markup { + println!("Got a user: {:?}", user); + + html! { + ":D" + } +} diff --git a/src/main.rs b/src/main.rs index ace50ce..8429044 100644 --- a/src/main.rs +++ b/src/main.rs @@ -1,32 +1,19 @@ use rocket::fs::FileServer; -use maud::{Markup, html, DOCTYPE}; +mod controller; +mod view; #[macro_use] extern crate rocket; -#[get("/")] -fn index() -> Markup { - html! { - (DOCTYPE) - html { - head { - title { "Hello, world!" } - link rel="stylesheet" type="text/css" href="/static/css/output.css"; - } - body { - h1 class="text-xl text-red-500 bg-slate-300 px-2 py-4 rounded-full font-black" { - "Hello, world!" - } - p { "Welcome to my website!" } - } - } - } -} - #[launch] fn rocket() -> _ { rocket::build() - .mount("/", routes![index]) + .mount("/", routes![ + view::index, + ]) + .mount("/f", routes![ + controller::user::create_user, + ]) .mount("/static", FileServer::from("static")) } diff --git a/src/view/mod.rs b/src/view/mod.rs new file mode 100644 index 0000000..45800dd --- /dev/null +++ b/src/view/mod.rs @@ -0,0 +1,32 @@ +use maud::{html, Markup, DOCTYPE}; + +#[get("/")] +pub fn index() -> Markup { + html! { + (DOCTYPE) + html lang="es" { + head { + title { "EEGSAC" } + link rel="stylesheet" type="text/css" href="/static/css/output.css"; + script defer src="https://unpkg.com/htmx.org@1.9.10" crossorigin="anonymous" {} + } + body { + h1 { "Registrar nuevo usuario" } + form + action="/f/user" + method="post" + { + input type="text" name="user_names" placeholder="Nombres"; + br; + input type="text" name="user_surnames" placeholder="Apellidos"; + br; + input type="email" name="user_email" placeholder="Correo electrónico"; + br; + input type="password" name="user_password" placeholder="Contraseña"; + br; + input type="submit" value="Registrar"; + } + } + } + } +} diff --git a/static/css/input.css b/static/css/input.css index b5c61c9..feda6b1 100644 --- a/static/css/input.css +++ b/static/css/input.css @@ -1,3 +1,13 @@ @tailwind base; @tailwind components; @tailwind utilities; + +:root { + --c-bg: #101010; + --c-on-bg: #dedede; +} + +html { + background-color: var(--c-bg); + color: var(--c-on-bg); +}