diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/routes/login.rs | 16 |
1 files changed, 13 insertions, 3 deletions
diff --git a/src/routes/login.rs b/src/routes/login.rs index bd7eaf1..9bb4efa 100644 --- a/src/routes/login.rs +++ b/src/routes/login.rs @@ -2,6 +2,7 @@ use actix_session::Session; use actix_web::http::header::LOCATION; use actix_web::{get, post, web, HttpResponse}; use serde::Deserialize; +use uuid::Uuid; use crate::error::PinussyError; use crate::notification::{Kind, Notification}; @@ -10,15 +11,24 @@ use crate::Pinussy; use crate::Result; #[get("/login")] -async fn get() -> HttpResponse { - HttpResponse::Ok().body(render!(templates::login_html, None).unwrap()) +async fn get(session: Session, state: web::Data<Pinussy>) -> Result<HttpResponse> { + if let Some(user_id) = session.get::<Uuid>("user_id")? { + if state.db.users().read(user_id).await.is_ok() { + return Ok(HttpResponse::SeeOther() + .insert_header((LOCATION, "/")) + .finish()); + } else { + session.purge() + } + } + Ok(HttpResponse::Ok().body(render!(templates::login_html, None).unwrap())) } #[derive(Deserialize)] struct LoginForm { username: String, password: String, - rememberme: Option<String>, + // rememberme: Option<String>, } #[post("/login")] |