Add session lifetime

This commit is contained in:
BitHeaven 2024-04-02 19:51:28 +05:00
parent e3229f41a4
commit c12d7fb01c
2 changed files with 9 additions and 4 deletions

View File

@ -72,7 +72,7 @@ async fn auth_get(req: Request<Incoming>, pool: DBPool) -> Json {
_ => res.unwrap() _ => res.unwrap()
}; };
match login { match login.as_str() {
"" => json!({"error": true, "msg": "Not auth yet"}), "" => json!({"error": true, "msg": "Not auth yet"}),
_ => json!({"error": false, "login": login, "uuid": uuid}) _ => json!({"error": false, "login": login, "uuid": uuid})
} }

View File

@ -100,6 +100,8 @@ const DB_PASS: &str = "rootpass12345678";
const TOKEN_LIFETIME: u32 = 300; const TOKEN_LIFETIME: u32 = 300;
const REFRESH_LIFETIME: u32 = 2_678_400; const REFRESH_LIFETIME: u32 = 2_678_400;
const APIV0_LIFETIME: u32 = 120;
#[tokio::main] #[tokio::main]
async fn main() -> Result<()> { async fn main() -> Result<()> {
@ -373,11 +375,13 @@ async fn authorize_user(pool: DBPool, token: String, session: String) {
r#"INSERT INTO bitauth.v0 { r#"INSERT INTO bitauth.v0 {
session: ?, session: ?,
login: ?, login: ?,
uuid: ? uuid: ?,
expire: ?,
}"#, }"#,
session, session,
login, login,
uuid uuid,
time() + APIV0_LIFETIME
)).await; )).await;
} }
@ -484,7 +488,8 @@ async fn init_tables(pool: DBPool) -> Res<(), SkyError> {
CREATE MODEL IF NOT EXISTS bitauth.v0( CREATE MODEL IF NOT EXISTS bitauth.v0(
session: string, session: string,
login: string, login: string,
uuid: string uuid: string,
expire: uint32,
) )
"#)).await; "#)).await;