Add authorize page
This commit is contained in:
54
src/funcs.rs
Normal file
54
src/funcs.rs
Normal 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()
|
||||
}
|
Reference in New Issue
Block a user