Add session lifetime
This commit is contained in:
parent
c12d7fb01c
commit
73f5edf77f
@ -16,6 +16,7 @@ use {
|
|||||||
bb8::Pool,
|
bb8::Pool,
|
||||||
std::sync::Arc,
|
std::sync::Arc,
|
||||||
crate::{
|
crate::{
|
||||||
|
time,
|
||||||
double_split,
|
double_split,
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
@ -58,8 +59,8 @@ async fn auth_get(req: Request<Incoming>, pool: DBPool) -> Json {
|
|||||||
_ => ""
|
_ => ""
|
||||||
};
|
};
|
||||||
|
|
||||||
let res = con.query_parse::<(String, String)>(&query!(
|
let res = con.query_parse::<(String, String, u32)>(&query!(
|
||||||
"SELECT login, uuid FROM bitauth.v0 WHERE session = ?",
|
"SELECT login, uuid, expire FROM bitauth.v0 WHERE session = ?",
|
||||||
session
|
session
|
||||||
)).await;
|
)).await;
|
||||||
let _ = con.query_parse::<()>(&query!(
|
let _ = con.query_parse::<()>(&query!(
|
||||||
@ -67,13 +68,15 @@ async fn auth_get(req: Request<Incoming>, pool: DBPool) -> Json {
|
|||||||
session
|
session
|
||||||
)).await;
|
)).await;
|
||||||
|
|
||||||
let (login, uuid) = match res.is_ok() {
|
let (login, uuid, exp) = match res.is_ok() {
|
||||||
false => ("".to_owned(), "".to_owned()),
|
false => ("".to_owned(), "".to_owned(), 0),
|
||||||
_ => res.unwrap()
|
_ => res.unwrap()
|
||||||
};
|
};
|
||||||
|
|
||||||
match login.as_str() {
|
if login.as_str() == "" || exp < time() {
|
||||||
"" => json!({"error": true, "msg": "Not auth yet"}),
|
json!({"error": true, "msg": "Not auth yet"})
|
||||||
_ => json!({"error": false, "login": login, "uuid": uuid})
|
}
|
||||||
|
else {
|
||||||
|
json!({"error": false, "login": login, "uuid": uuid})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user