From 2420b69d430714ef21f26cb5ab511eec155cd000 Mon Sep 17 00:00:00 2001 From: philipp Date: Tue, 6 Jun 2023 12:26:48 +0200 Subject: [PATCH 1/3] fix tests --- src/model/planned_event.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/model/planned_event.rs b/src/model/planned_event.rs index 6284a74..046ea4a 100644 --- a/src/model/planned_event.rs +++ b/src/model/planned_event.rs @@ -279,6 +279,6 @@ mod test { let pool = testdb!(); let actual = PlannedEvent::get_ics_feed(&pool).await; - assert_eq!("BEGIN:VCALENDAR\nVERSION:2.0\nPRODID:-//rudernlinz.at//Trips//DE\nX-WR-CALNAME:Ruderausfahrten\nBEGIN:VEVENT\nUID:1@rudernlinz.at\nDTSTART;TZID=Europe/Vienna:19700101T100000\nSUMMARY:test-planned-event\nEND:VEVENT\nEND:VCALENDAR", actual); + assert_eq!("BEGIN:VCALENDAR\r\nVERSION:2.0\r\nPRODID:ics-rs\r\nBEGIN:VEVENT\r\nUID:1@rudernlinz.at\r\nDTSTAMP:19900101T180000\r\nDTSTART:19700101T100000\r\nSUMMARY:test-planned-event\r\nEND:VEVENT\r\nEND:VCALENDAR\r\n", actual); } } From 179bd5dfc3be13bd847e87fad4f157c94a19673b Mon Sep 17 00:00:00 2001 From: philipp Date: Tue, 6 Jun 2023 22:42:22 +0200 Subject: [PATCH 2/3] add shame list --- shame.txt | 1 + 1 file changed, 1 insertion(+) create mode 100644 shame.txt diff --git a/shame.txt b/shame.txt new file mode 100644 index 0000000..9ec9e50 --- /dev/null +++ b/shame.txt @@ -0,0 +1 @@ +2023-06-06: Phil Baillon um 19:10 für 18 Uhr Fahrt abgemeldet From d7417804a0b7bdd84f0b7cf0ffa3db1684da4ca6 Mon Sep 17 00:00:00 2001 From: philipp Date: Wed, 7 Jun 2023 00:07:11 +0200 Subject: [PATCH 3/3] renew cookies on every action; increase cookie timeout to 3 months --- src/model/user.rs | 10 +++++++++- src/rest/auth.rs | 8 ++++++-- 2 files changed, 15 insertions(+), 3 deletions(-) diff --git a/src/model/user.rs b/src/model/user.rs index 99e41e3..86355f5 100644 --- a/src/model/user.rs +++ b/src/model/user.rs @@ -3,11 +3,13 @@ use std::ops::Deref; use argon2::{password_hash::SaltString, Argon2, PasswordHasher}; use rocket::{ async_trait, - http::Status, + http::{Cookie, Status}, request::{self, FromRequest, Outcome}, + time::{Duration, OffsetDateTime}, Request, }; use serde::{Deserialize, Serialize}; +use serde_json::json; use sqlx::{FromRow, SqlitePool}; #[derive(FromRow, Debug, Serialize, Deserialize)] @@ -178,6 +180,12 @@ impl<'r> FromRequest<'r> for User { Ok(user) => { let db = req.rocket().state::().unwrap(); user.logged_in(db).await; + + let user_json: String = format!("{}", json!(user)); + let mut cookie = Cookie::new("loggedin_user", user_json); + cookie.set_expires(OffsetDateTime::now_utc() + Duration::weeks(12)); + req.cookies().add_private(cookie); + Outcome::Success(user) } Err(_) => { diff --git a/src/rest/auth.rs b/src/rest/auth.rs index b98650a..f54d99c 100644 --- a/src/rest/auth.rs +++ b/src/rest/auth.rs @@ -5,7 +5,9 @@ use rocket::{ post, request::FlashMessage, response::{Flash, Redirect}, - routes, FromForm, Route, State, + routes, + time::{Duration, OffsetDateTime}, + FromForm, Route, State, }; use rocket_dyn_templates::{context, tera, Template}; use serde_json::json; @@ -96,7 +98,9 @@ async fn updatepw( user.update_pw(db, updatepw.password).await; let user_json: String = format!("{}", json!(user)); - cookies.add_private(Cookie::new("loggedin_user", user_json)); + let mut cookie = Cookie::new("loggedin_user", user_json); + cookie.set_expires(OffsetDateTime::now_utc() + Duration::weeks(12)); + cookies.add_private(cookie); Log::create(db, format!("User {} set her password.", user.name)).await;