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