login cookie expiration
This commit is contained in:
parent
10f6dfdf96
commit
d6ac6c38ac
1
Cargo.lock
generated
1
Cargo.lock
generated
@ -2673,6 +2673,7 @@ dependencies = [
|
|||||||
"rocket_dyn_templates",
|
"rocket_dyn_templates",
|
||||||
"rss",
|
"rss",
|
||||||
"sqlx",
|
"sqlx",
|
||||||
|
"time",
|
||||||
"tokio",
|
"tokio",
|
||||||
"url",
|
"url",
|
||||||
"uuid",
|
"uuid",
|
||||||
|
@ -19,3 +19,4 @@ url = { version = "2.5", features = ["serde"] }
|
|||||||
feed-rs = "2.3.1"
|
feed-rs = "2.3.1"
|
||||||
reqwest = { version = "0.12.12", features = ["json"] }
|
reqwest = { version = "0.12.12", features = ["json"] }
|
||||||
tokio = "1.43.0"
|
tokio = "1.43.0"
|
||||||
|
time = "0.3.37"
|
||||||
|
@ -1,3 +1,5 @@
|
|||||||
|
use time::Duration;
|
||||||
|
|
||||||
use rocket::http::{Cookie, CookieJar, Status};
|
use rocket::http::{Cookie, CookieJar, Status};
|
||||||
use rocket::serde::{json::Json, Deserialize, Serialize};
|
use rocket::serde::{json::Json, Deserialize, Serialize};
|
||||||
use rocket_db_pools::Connection;
|
use rocket_db_pools::Connection;
|
||||||
@ -219,7 +221,12 @@ pub async fn login(
|
|||||||
|
|
||||||
// Set session cookie
|
// Set session cookie
|
||||||
let user_id = Uuid::parse_str(&user.id).map_err(|_| Status::InternalServerError)?;
|
let user_id = Uuid::parse_str(&user.id).map_err(|_| Status::InternalServerError)?;
|
||||||
cookies.add_private(Cookie::new("user_id", user_id.to_string()));
|
|
||||||
|
//TODO make this user-configurable
|
||||||
|
let max_age = Duration::days(6);
|
||||||
|
let mut cookie = Cookie::new("user_id", user_id.to_string());
|
||||||
|
cookie.set_max_age(max_age);
|
||||||
|
cookies.add_private(cookie);
|
||||||
|
|
||||||
Ok(Json(LoginResponse {
|
Ok(Json(LoginResponse {
|
||||||
user_id,
|
user_id,
|
||||||
|
Loading…
Reference in New Issue
Block a user