Fix all Errors n Warns
This commit is contained in:
@ -1,6 +1,5 @@
|
||||
use {
|
||||
std::{
|
||||
sync::Arc,
|
||||
collections::HashMap,
|
||||
any::type_name,
|
||||
time::{
|
||||
@ -14,6 +13,7 @@ use {
|
||||
chrono::DateTime,
|
||||
serde_json::{
|
||||
Value as Json,
|
||||
Map as JsonMap,
|
||||
json,
|
||||
},
|
||||
rsa::{
|
||||
@ -37,10 +37,8 @@ use {
|
||||
},
|
||||
skytable::{
|
||||
query,
|
||||
pool::ConnectionMgrTcp,
|
||||
error::Error as SkyError,
|
||||
},
|
||||
bb8::Pool,
|
||||
http_body_util::BodyExt,
|
||||
hyper::{
|
||||
Request,
|
||||
@ -59,6 +57,7 @@ use {
|
||||
html::*,
|
||||
Users,
|
||||
Sites,
|
||||
APIV0_LIFETIME,
|
||||
},
|
||||
};
|
||||
|
||||
@ -379,7 +378,7 @@ pub async fn get_user(pool: DBPool, login: String) -> Res<Users, SkyError> {
|
||||
Ok(q?)
|
||||
}
|
||||
|
||||
fn get_cookies(headers: HeaderMap) -> HashMap<String, String> {
|
||||
pub fn get_cookies(headers: HeaderMap) -> HashMap<String, String> {
|
||||
let header = headers.get(hyper::header::COOKIE);
|
||||
let cookies = match header.is_none() {
|
||||
false => header.unwrap().to_str().unwrap(),
|
||||
@ -389,7 +388,7 @@ fn get_cookies(headers: HeaderMap) -> HashMap<String, String> {
|
||||
double_split(cookies.to_owned(), ";", "=")
|
||||
}
|
||||
|
||||
async fn authorize_user(pool: DBPool, token: String, session: String) {
|
||||
pub async fn authorize_user(pool: DBPool, token: String, session: String) {
|
||||
let mut con = pool.get().await.unwrap();
|
||||
|
||||
let data: JsonMap<String, Json> = jwt_verify(pool.clone(), &token)
|
||||
|
31
src/main.rs
31
src/main.rs
@ -10,18 +10,13 @@ use {
|
||||
collections::HashMap,
|
||||
process::exit,
|
||||
},
|
||||
chrono::{
|
||||
DateTime,
|
||||
},
|
||||
http_body_util::{
|
||||
Full,
|
||||
BodyExt,
|
||||
},
|
||||
hyper::{
|
||||
StatusCode,
|
||||
Request,
|
||||
Response,
|
||||
Method,
|
||||
HeaderMap,
|
||||
header::HeaderValue,
|
||||
body::{
|
||||
@ -37,28 +32,8 @@ use {
|
||||
tokio::{
|
||||
net::TcpListener,
|
||||
},
|
||||
rsa::{
|
||||
pkcs1::{
|
||||
EncodeRsaPublicKey,
|
||||
EncodeRsaPrivateKey,
|
||||
},
|
||||
RsaPrivateKey,
|
||||
RsaPublicKey,
|
||||
},
|
||||
jsonwebtoken as jwt,
|
||||
jwt::{
|
||||
Header,
|
||||
Algorithm,
|
||||
TokenData,
|
||||
Validation,
|
||||
EncodingKey,
|
||||
DecodingKey,
|
||||
encode as jwt_encode,
|
||||
decode as jwt_decode,
|
||||
},
|
||||
serde_json::{
|
||||
Value as Json,
|
||||
Map as JsonMap,
|
||||
json,
|
||||
},
|
||||
skytable::{
|
||||
@ -75,7 +50,6 @@ use {
|
||||
},
|
||||
urlencoding::{
|
||||
encode as url_encode,
|
||||
decode as url_decode,
|
||||
},
|
||||
crate::{
|
||||
types::{
|
||||
@ -84,7 +58,6 @@ use {
|
||||
},
|
||||
html::*,
|
||||
funcs::*,
|
||||
url,
|
||||
},
|
||||
};
|
||||
|
||||
@ -97,10 +70,10 @@ type FullBytes = Result<Response<Full<Bytes>>>;
|
||||
const PORT: u16 = 8083;
|
||||
|
||||
const DB_POOL: u32 = 32;
|
||||
const DB_ADDR: &str = "192.168.1.49";
|
||||
const DB_ADDR: &str = "127.0.0.1";
|
||||
const DB_PORT: u16 = 2003;
|
||||
const DB_USER: &str = "root";
|
||||
const DB_PASS: &str = "rootpass12345678";
|
||||
const DB_PASS: &str = "5a14775a-a490-4212345678";
|
||||
|
||||
const TOKEN_LIFETIME: u32 = 300;
|
||||
const REFRESH_LIFETIME: u32 = 2_678_400;
|
||||
|
@ -1,3 +1,22 @@
|
||||
use {
|
||||
hyper::{
|
||||
Request,
|
||||
body::Incoming,
|
||||
Method,
|
||||
StatusCode,
|
||||
header::HeaderValue,
|
||||
},
|
||||
crate::{
|
||||
AUTHORIZE_HTML,
|
||||
DBPool,
|
||||
Result,
|
||||
build_html,
|
||||
double_split,
|
||||
authorize_user,
|
||||
},
|
||||
};
|
||||
|
||||
|
||||
pub async fn authorize(req: Request<Incoming>, pool: DBPool, token: String) -> Result<(String, StatusCode, HeaderValue)> {
|
||||
// TODO: Forward for versions.
|
||||
if *req.method() == Method::POST {
|
||||
|
@ -1,3 +1,15 @@
|
||||
use {
|
||||
hyper::{
|
||||
StatusCode,
|
||||
header::HeaderValue,
|
||||
},
|
||||
crate::{
|
||||
INDEX_HTML,
|
||||
build_html,
|
||||
},
|
||||
};
|
||||
|
||||
|
||||
pub fn index() -> (String, StatusCode, HeaderValue) {
|
||||
let restype: HeaderValue = "text/html".parse().unwrap();
|
||||
(build_html(INDEX_HTML), StatusCode::OK, restype)
|
||||
|
@ -1,96 +1,25 @@
|
||||
use {
|
||||
std::{
|
||||
sync::Arc,
|
||||
net::SocketAddr,
|
||||
collections::HashMap,
|
||||
process::exit,
|
||||
},
|
||||
chrono::{
|
||||
DateTime,
|
||||
},
|
||||
http_body_util::{
|
||||
Full,
|
||||
BodyExt,
|
||||
},
|
||||
hyper::{
|
||||
StatusCode,
|
||||
Request,
|
||||
Response,
|
||||
Method,
|
||||
HeaderMap,
|
||||
header::HeaderValue,
|
||||
body::{
|
||||
Bytes,
|
||||
Incoming,
|
||||
},
|
||||
server::conn::http1 as Server,
|
||||
service::service_fn,
|
||||
},
|
||||
hyper_util::{
|
||||
rt::TokioIo,
|
||||
},
|
||||
tokio::{
|
||||
net::TcpListener,
|
||||
},
|
||||
rsa::{
|
||||
pkcs1::{
|
||||
EncodeRsaPublicKey,
|
||||
EncodeRsaPrivateKey,
|
||||
},
|
||||
RsaPrivateKey,
|
||||
RsaPublicKey,
|
||||
},
|
||||
jsonwebtoken as jwt,
|
||||
jwt::{
|
||||
Header,
|
||||
Algorithm,
|
||||
TokenData,
|
||||
Validation,
|
||||
EncodingKey,
|
||||
DecodingKey,
|
||||
encode as jwt_encode,
|
||||
decode as jwt_decode,
|
||||
},
|
||||
serde_json::{
|
||||
Value as Json,
|
||||
Map as JsonMap,
|
||||
json,
|
||||
},
|
||||
skytable::{
|
||||
query,
|
||||
Config,
|
||||
pool::{
|
||||
self,
|
||||
ConnectionMgrTcp
|
||||
},
|
||||
error::Error as SkyError,
|
||||
},
|
||||
bb8::{
|
||||
Pool,
|
||||
},
|
||||
urlencoding::{
|
||||
encode as url_encode,
|
||||
decode as url_decode,
|
||||
},
|
||||
crate::{
|
||||
types::{
|
||||
users::Users,
|
||||
sites::Sites,
|
||||
},
|
||||
Result,
|
||||
DBPool,
|
||||
html::*,
|
||||
funcs::*,
|
||||
url::{
|
||||
api,
|
||||
login,
|
||||
},
|
||||
},
|
||||
};
|
||||
|
||||
type Res<T, E> = std::result::Result<T, E>;
|
||||
type Result<T> = std::result::Result<T, Box<dyn std::error::Error + Send + Sync>>;
|
||||
type DBPool = Arc<Pool<ConnectionMgrTcp>>;
|
||||
type FullBytes = Result<Response<Full<Bytes>>>;
|
||||
|
||||
|
||||
pub async fn login(req: Request<Incoming>, pool: DBPool, headers: &mut HeaderMap) -> Result<(String, StatusCode, HeaderValue)> {
|
||||
let mut body = build_html(LOGIN_HTML);
|
||||
|
@ -1,3 +1,15 @@
|
||||
use {
|
||||
hyper::{
|
||||
StatusCode,
|
||||
header::HeaderValue,
|
||||
},
|
||||
crate::{
|
||||
NF_HTML,
|
||||
build_html,
|
||||
},
|
||||
};
|
||||
|
||||
|
||||
pub fn nf() -> (String, StatusCode, HeaderValue) {
|
||||
let restype: HeaderValue = "text/html".parse().unwrap();
|
||||
(build_html(NF_HTML), StatusCode::NOT_FOUND, restype)
|
||||
|
@ -1,3 +1,15 @@
|
||||
use {
|
||||
hyper::{
|
||||
StatusCode,
|
||||
header::HeaderValue,
|
||||
},
|
||||
crate::{
|
||||
build_html,
|
||||
RECOVER_HTML,
|
||||
},
|
||||
};
|
||||
|
||||
|
||||
pub fn recover() -> (String, StatusCode, HeaderValue) {
|
||||
let restype: HeaderValue = "text/html".parse().unwrap();
|
||||
(build_html(RECOVER_HTML), StatusCode::OK, restype)
|
||||
|
@ -1,3 +1,25 @@
|
||||
use {
|
||||
hyper::{
|
||||
body::Incoming,
|
||||
HeaderMap,
|
||||
Method,
|
||||
Request,
|
||||
header::HeaderValue,
|
||||
StatusCode,
|
||||
},
|
||||
crate::{
|
||||
Result,
|
||||
DBPool,
|
||||
REG_HTML,
|
||||
build_html,
|
||||
set_location,
|
||||
create_user,
|
||||
double_split,
|
||||
get_body_from_request,
|
||||
},
|
||||
};
|
||||
|
||||
|
||||
pub async fn register(req: Request<Incoming>, pool: DBPool, headers: &mut HeaderMap) -> Result<(String, StatusCode, HeaderValue)> {
|
||||
let mut body = "".to_owned();
|
||||
let mut status = StatusCode::OK;
|
||||
|
@ -1,3 +1,20 @@
|
||||
use {
|
||||
hyper::{
|
||||
Request,
|
||||
StatusCode,
|
||||
body::Incoming,
|
||||
header::HeaderValue,
|
||||
},
|
||||
crate::{
|
||||
Res,
|
||||
DBPool,
|
||||
SkyError,
|
||||
get_user,
|
||||
build_html,
|
||||
},
|
||||
};
|
||||
|
||||
|
||||
pub async fn user(req: Request<Incoming>, pool: DBPool) -> Res<(String, StatusCode, HeaderValue), SkyError> {
|
||||
let uri: &str = req.uri().path().as_ref();
|
||||
let login = &uri[2..uri.len()];
|
||||
|
Reference in New Issue
Block a user