minimal controller

main
Araozu 2024-02-09 19:59:21 -05:00
parent 18ffc5f7ae
commit 625fa9325b
9 changed files with 95 additions and 22 deletions

View File

@ -2,4 +2,5 @@
"tailwindCSS.includeLanguages": {
"rust": "html"
},
"rust-analyzer.showUnlinkedFileNotification": false,
}

2
Cargo.lock generated
View File

@ -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",

View File

@ -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"] }

18
sql/schema.sql Normal file
View File

@ -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
);

3
src/controller/mod.rs Normal file
View File

@ -0,0 +1,3 @@
pub mod user;

19
src/controller/user.rs Normal file
View File

@ -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 = "<user>")]
pub async fn create_user(user: Form<UserCreate>) -> Markup {
println!("Got a user: {:?}", user);
html! {
":D"
}
}

View File

@ -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"))
}

32
src/view/mod.rs Normal file
View File

@ -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";
}
}
}
}
}

View File

@ -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);
}