Move work to notebook
This commit is contained in:
@ -41,10 +41,11 @@ async fn auth(req: Request<Incoming>, _pool: DBPool) -> Json {
|
||||
.or(Some(&"".to_string()))
|
||||
.unwrap());
|
||||
match sess.as_str() {
|
||||
"" => json!({"error": true, "msg": "No session in url"}),
|
||||
"" => json!({"error": true, "msg": "No session in request"}),
|
||||
x if x.len() > 128 => json!({"error": true, "msg": "Session len is too long"}),
|
||||
_ => json!({
|
||||
"error": false,
|
||||
"link": format!("https://auth.bitheaven.ru/authorize?session={}", sess)
|
||||
"link": format!("https://auth.bitheaven.ru/authorize?v=0&session={}", sess)
|
||||
})
|
||||
}
|
||||
}
|
||||
|
19
src/funcs.rs
19
src/funcs.rs
@ -7,6 +7,7 @@ use {
|
||||
UNIX_EPOCH,
|
||||
},
|
||||
},
|
||||
webhook::client::WebhookClient,
|
||||
urlencoding::decode as url_decode,
|
||||
uuid::Uuid,
|
||||
crate::{
|
||||
@ -53,3 +54,21 @@ pub fn time_mcs() -> u128 {
|
||||
.unwrap()
|
||||
.as_micros()
|
||||
}
|
||||
|
||||
pub async fn discord_wh_send(text: String) {
|
||||
let url: &str = "https://discord.com/api/webhooks/1228566682902204537/RXaWpZplEGzU88O8c4mD4qzXp1PDBrrp93nGvdijaY7mBXp27xc0EsThHUeU0431PQOZ";
|
||||
let client: WebhookClient = WebhookClient::new(url);
|
||||
client.send(|message| message
|
||||
.username("Bit.Auth")
|
||||
// .avatar_url("")
|
||||
.embed(|embed| embed
|
||||
.title("Error")
|
||||
.description(&text)
|
||||
// .footer("Footer", Some(String::from(IMAGE_URL)))
|
||||
// .image(IMAGE_URL)
|
||||
// .thumbnail(IMAGE_URL)
|
||||
// .author("bitheaven", Some(String::from(IMAGE_URL)), Some(String::from(IMAGE_URL)))
|
||||
// .field("name", "value", false)
|
||||
)
|
||||
).await.unwrap();
|
||||
}
|
||||
|
23
src/main.rs
23
src/main.rs
@ -181,13 +181,6 @@ async fn handle_connection(req: Request<Incoming>, pool: DBPool, ip: String) ->
|
||||
x if x.starts_with("/api/") => {},
|
||||
_ => 'jwt_check: {
|
||||
if token == "" { break 'jwt_check; }
|
||||
/* if token != "" {
|
||||
parts.status = StatusCode::FOUND;
|
||||
set_cookie(&mut headers, "token", "");
|
||||
set_location(&mut headers, "/login");
|
||||
parts.headers = headers;
|
||||
return Ok(Response::from_parts(parts, Full::new(Bytes::new())));
|
||||
}*/
|
||||
|
||||
let is_live = jwt_verify(pool.clone(), &token)
|
||||
.await?
|
||||
@ -272,9 +265,6 @@ async fn handle_connection(req: Request<Incoming>, pool: DBPool, ip: String) ->
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// if x == "/authorize" {
|
||||
// }
|
||||
}
|
||||
}
|
||||
|
||||
@ -359,6 +349,7 @@ async fn uri_login(req: Request<Incoming>, pool: DBPool, headers: &mut HeaderMap
|
||||
}
|
||||
|
||||
async fn uri_authorize(req: Request<Incoming>, pool: DBPool, token: String) -> Result<(String, StatusCode, HeaderValue)> {
|
||||
// TODO: Forward for versions.
|
||||
if *req.method() == Method::POST {
|
||||
let r = double_split(req.uri().query().or(Some("")).unwrap().to_owned(), "&", "=");
|
||||
|
||||
@ -368,7 +359,7 @@ async fn uri_authorize(req: Request<Incoming>, pool: DBPool, token: String) -> R
|
||||
_ => "".to_owned()
|
||||
};
|
||||
|
||||
if session != "" {
|
||||
if session != "" && session.len() <= 128 {
|
||||
authorize_user(pool.clone(), token, session).await;
|
||||
}
|
||||
}
|
||||
@ -560,8 +551,14 @@ async fn login_user(pool: DBPool, data: HashMap<String, String>) -> Res<(String,
|
||||
let q = con
|
||||
.query_parse::<Users>(&query!("SELECT * FROM bitauth.users WHERE uuid = ?", uuid.clone()))
|
||||
.await;
|
||||
// TODO: Send to admin notify about trouble!
|
||||
if q.is_err() { return Ok(ret); };
|
||||
if q.is_err() {
|
||||
discord_wh_send(
|
||||
format!("Пизда тут, ну тип, да, какая-то ебень с uuid, чел потерялся...\n`{}`\n**{}**", uuid, login)
|
||||
).await;
|
||||
return Ok(ret);
|
||||
}
|
||||
|
||||
// TODO: Say to user about trouble.
|
||||
|
||||
let q = q.unwrap();
|
||||
if bcrypt::verify(pass, q.password.as_str()).unwrap() {
|
||||
|
Reference in New Issue
Block a user