Add authorize page

This commit is contained in:
2024-03-22 16:27:06 +05:00
parent 0ad0a8cf0b
commit 6a64f87bc5
4 changed files with 97 additions and 48 deletions

54
src/funcs.rs Normal file
View File

@ -0,0 +1,54 @@
use {
std::{
collections::HashMap,
any::type_name,
time::{
SystemTime,
UNIX_EPOCH,
},
},
urlencoding::decode as url_decode,
uuid::Uuid,
crate::{
html::*,
},
};
pub fn type_of<T>(_: T) -> &'static str {
type_name::<T>()
}
pub fn uuid_v4() -> Uuid {
Uuid::new_v4()
}
pub fn build_html(body: &str) -> String {
format!("{}{}{}{}", HEADER_HTML, CSS3, body, FOOTER_HTML)
}
pub fn double_split(body: String, first: &str, second: &str) -> HashMap<String, String> {
body.split(first)
.filter_map(|c| {
c.split_once(second)
.map(|(l, r)| (
l.trim().to_owned(),
format!("{}", url_decode(r).expect("UTF-8")).trim().to_owned()
))
})
.collect::<HashMap<String, String>>()
}
pub fn time() -> u32 {
SystemTime::now()
.duration_since(UNIX_EPOCH)
.unwrap()
.as_secs() as u32
}
pub fn time_ns() -> u128 {
SystemTime::now()
.duration_since(UNIX_EPOCH)
.unwrap()
.as_micros()
}