Add authorize page
This commit is contained in:
@ -12,7 +12,10 @@ use {
|
||||
skytable::pool::ConnectionMgrTcp,
|
||||
bb8::Pool,
|
||||
std::sync::Arc,
|
||||
crate::double_split,
|
||||
crate::{
|
||||
funcs::type_of,
|
||||
double_split,
|
||||
},
|
||||
};
|
||||
|
||||
type Res<T, E> = std::result::Result<T, E>;
|
||||
@ -23,7 +26,6 @@ type DBPool = Arc<Pool<ConnectionMgrTcp>>;
|
||||
pub async fn api(req: Request<Incoming>, pool: DBPool) -> Json {
|
||||
let uri: &str = req.uri().path().as_ref();
|
||||
match &uri[7..uri.len()] {
|
||||
"/test" => json!({"error": false, "msg": "test"}),
|
||||
"/auth" => auth(req, pool.clone()).await,
|
||||
"/auth_get" => auth_get(req, pool.clone()).await,
|
||||
_ => json!({"error": true, "msg": "No endpoint"})
|
||||
@ -31,7 +33,19 @@ pub async fn api(req: Request<Incoming>, pool: DBPool) -> Json {
|
||||
}
|
||||
|
||||
async fn auth(req: Request<Incoming>, pool: DBPool) -> Json {
|
||||
json!({"error": false, "msg": "test auth endpoint v0"})
|
||||
let query = req.uri().query().or(Some("")).unwrap();
|
||||
let query = double_split(query.to_string(), "&", "=");
|
||||
let sess = std::string::String::from(query
|
||||
.get("session")
|
||||
.or(Some(&"".to_string()))
|
||||
.unwrap());
|
||||
match sess.as_str() {
|
||||
"" => json!({"error": true, "msg": "No session in url"}),
|
||||
_ => json!({
|
||||
"error": false,
|
||||
"link": format!("https://auth.bitheaven.ru/authorize?session={}", sess)
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
async fn auth_get(req: Request<Incoming>, pool: DBPool) -> Json {
|
||||
|
Reference in New Issue
Block a user