summaryrefslogtreecommitdiffstats
path: root/src/routes
diff options
context:
space:
mode:
authorLibravatar cel 🌸 <cel@blos.sm>2023-12-13 08:02:22 +0000
committerLibravatar cel 🌸 <cel@blos.sm>2023-12-13 08:02:22 +0000
commit04e2740c6f0fd9f1a88429c6df4a212f2f27bb39 (patch)
tree33fbaf2f38d6ee81b088514e7ce07935b0e230c9 /src/routes
parenta971d8c2dc519b1db805c72cf3395c188a98dff4 (diff)
downloadpinussy-04e2740c6f0fd9f1a88429c6df4a212f2f27bb39.tar.gz
pinussy-04e2740c6f0fd9f1a88429c6df4a212f2f27bb39.tar.bz2
pinussy-04e2740c6f0fd9f1a88429c6df4a212f2f27bb39.zip
add redirect from login page if already logged in
Diffstat (limited to '')
-rw-r--r--src/routes/login.rs16
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")]