Redirect to login. Login view

master
Araozu 2024-06-23 20:45:30 -05:00
parent 759d271111
commit 330b6bdd4f
5 changed files with 61 additions and 8 deletions

View File

@ -1,17 +1,25 @@
use maud::Markup; use maud::Markup;
use rocket::http::Status; use rocket::{http::Status, response::Redirect};
mod utils; mod utils;
#[get("/")] #[get("/")]
pub fn homepage() -> Markup { pub fn homepage() -> Markup {
crate::view::homepage() crate::view::homepage()
} }
#[get("/new")] #[get("/new")]
pub fn new_definition(user: utils::User) -> (Status, Markup) { pub fn new_definition(_user: utils::User) -> (Status, Markup) {
todo!() todo!()
} }
#[get("/new", rank = 2)]
pub fn new_definition_redirect() -> Redirect {
println!("carita feliz :D");
Redirect::to("/login")
}
#[get("/login")]
pub fn login_page() -> Markup {
crate::view::login::login()
}

View File

@ -6,8 +6,7 @@ use rocket::{
/// Name of the header that stores the session ID of an user /// Name of the header that stores the session ID of an user
const RS_SESSION_ID: &str = "x-rs-session-id"; const RS_SESSION_ID: &str = "x-rs-session-id";
pub struct User { pub struct User {}
}
#[rocket::async_trait] #[rocket::async_trait]
impl<'r> FromRequest<'r> for User { impl<'r> FromRequest<'r> for User {
@ -18,7 +17,7 @@ impl<'r> FromRequest<'r> for User {
let _session_cookie = match session_cookie { let _session_cookie = match session_cookie {
Some(cookie) => cookie.value().to_string(), Some(cookie) => cookie.value().to_string(),
None => return Outcome::Error((Status::Unauthorized, "Unauthorized".into())), None => return Outcome::Forward(Status::Unauthorized),
}; };
// Check if session cookie is valid // Check if session cookie is valid

View File

@ -9,6 +9,14 @@ use rocket::fs::{relative, FileServer};
#[launch] #[launch]
fn rocket() -> _ { fn rocket() -> _ {
rocket::build() rocket::build()
.mount("/", routes![controller::homepage, controller::new_definition]) .mount(
"/",
routes![
controller::homepage,
controller::new_definition,
controller::new_definition_redirect,
controller::login_page,
],
)
.mount("/static", FileServer::from(relative!("static"))) .mount("/static", FileServer::from(relative!("static")))
} }

37
src/view/login.rs Normal file
View File

@ -0,0 +1,37 @@
use maud::{html, Markup};
use super::skeleton;
pub fn login() -> Markup {
skeleton(html! {
h1 class="text-3xl font-bold text-center my-4 fixed top-0 w-screen" {
"Jerguero"
}
div class="flex items-center h-screen w-full" {
div class="container mx-auto" {
p class="my-4 p-2 rounded bg-c-bg-2 text-c-on-bg" {
"¡Iniciá sesión para comenzar a crear definiciones!"
}
div class="my-4 py-4 px-2 rounded bg-c-bg-2 text-c-on-bg" {
div class="py-2" {
label class="text-sm opacity-85" for="login-email" {"Correo electronico:"}
br;
input class="inline-block w-full rounded bg-c-bg text-c-on-bg py-2 px-1" id="login-email";
}
div class="py-2" {
label class="text-sm opacity-85" for="login-password" {"Contraseña:"}
br;
input class="inline-block w-full rounded bg-c-bg text-c-on-bg py-2 px-1" id="login-password";
}
div class="text-center pt-2" {
button type="submit" class="py-1 px-2 rounded bg-c-primary text-c-on-primary hover:underline" {
"Iniciar sesión"
}
}
}
}
}
})
}

View File

@ -1,6 +1,7 @@
use maud::{html, Markup, DOCTYPE}; use maud::{html, Markup, DOCTYPE};
mod icons; mod icons;
pub mod login;
use icons::{bird, magnifying_glass}; use icons::{bird, magnifying_glass};