summaryrefslogtreecommitdiffstats
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
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
-rw-r--r--templates/login.rs.html4
2 files changed, 15 insertions, 5 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")]
diff --git a/templates/login.rs.html b/templates/login.rs.html
index 6dff4f4..a82c632 100644
--- a/templates/login.rs.html
+++ b/templates/login.rs.html
@@ -9,8 +9,8 @@
<input type="text" id="username" name="username" required="true" />
<label for="username">password:</label>
<input type="text" id="password" name="password" required="true" />
- <label for="rememberme">remember me:</label>
- <input type="checkbox" id="rememberme" name="rememberme" />
+ <!--<label for="rememberme">remember me:</label>
+ <input type="checkbox" id="rememberme" name="rememberme" />-->
<button type="submit">log in</button>
</form>
})