summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
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>
})