Add user status & fix get user

This commit is contained in:
root 2024-10-22 09:29:43 +02:00
parent f5f35855ce
commit 81023f2042
5 changed files with 343 additions and 399 deletions

722
Cargo.lock generated

File diff suppressed because it is too large Load Diff

View File

@ -1,6 +1,6 @@
[package]
name = "BitAuth"
version = "0.1.0"
version = "0.1.1"
edition = "2021"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

View File

@ -372,7 +372,7 @@ pub async fn get_user(pool: DBPool, login: String) -> Res<Users, SkyError> {
let mut con = pool.get().await.unwrap();
let q = con
.query_parse::<Users>(&query!("SELECT * FROM bitauth.users WHERE login = ?", login))
.query_parse::<Users>(&query!("SELECT * FROM bitauth.users_uuid WHERE login = ?", login))
.await;
Ok(q?)

View File

@ -7,6 +7,7 @@ pub const HEADER_HTML: &str = r#"
<a href="/">index</a>
<a href="/login">login</a>
<a href="/register">register</a>
<span>{USER_STATUS}</span>
<hr>
</header>
<main>
@ -16,7 +17,7 @@ pub const FOOTER_HTML: &str = r#"
</main>
<footer>
<hr>
Page time: PAGE_TIME&micro;s.
Page time: {PAGE_TIME}&micro;s.
Made by <a href="//bitheaven.ru/">BitHeaven</a>.
</footer>
</body>

View File

@ -67,13 +67,13 @@ type DBPool = Arc<Pool<ConnectionMgrTcp>>;
type FullBytes = Result<Response<Full<Bytes>>>;
const PORT: u16 = 8083;
const PORT: u16 = 8051;
const DB_POOL: u32 = 32;
const DB_ADDR: &str = "127.0.0.1";
const DB_PORT: u16 = 2003;
const DB_USER: &str = "root";
const DB_PASS: &str = "5a14775a-a490-4212345678";
const DB_PASS: &str = "dBk6wUAynGRRLsSF";
const TOKEN_LIFETIME: u32 = 300;
const REFRESH_LIFETIME: u32 = 2_678_400;
@ -258,7 +258,14 @@ async fn handle_connection(req: Request<Incoming>, pool: DBPool, ip: String) ->
headers.insert(hyper::header::CONTENT_TYPE, restype);
parts.headers = headers;
let body = body.replace("PAGE_TIME", &format!("{}", time_mcs() - t));
if logged {
let body = body.replace("{USER_STATUS}", "AUTHORIZED");
}
else {
let body = body.replace("{USER_STATUS}", "NOT AUTHORIZED");
}
let body = body.replace("{PAGE_TIME}", &format!("{}", time_mcs() - t));
Ok(Response::from_parts(parts, Full::new(Bytes::from(body))))
}