Skip to content

Commit a881db6

Browse files
committed
this way instead
1 parent ef91c41 commit a881db6

File tree

2 files changed

+5
-22
lines changed

2 files changed

+5
-22
lines changed

src/admin.rs

Lines changed: 1 addition & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ use rocket::{
66

77
pub struct Admin {
88
pub username: String,
9-
pub ipv4_address: Option<String>,
109
}
1110

1211
#[derive(Debug)]
@@ -22,7 +21,6 @@ impl<'r> FromRequest<'r> for Admin {
2221
if cfg!(debug_assertions) {
2322
return request::Outcome::Success(Admin {
2423
username: "AdminBot".to_string(),
25-
ipv4_address: None,
2624
});
2725
}
2826

@@ -31,17 +29,8 @@ impl<'r> FromRequest<'r> for Admin {
3129
None => return request::Outcome::Error((Status::BadRequest, AdminError::Missing)),
3230
};
3331

34-
let mut ipv4_address = None;
35-
for header in req.headers().get("CF-Connecting-IP") {
36-
if header.contains('.') {
37-
ipv4_address = Some(header.to_string());
38-
break;
39-
}
40-
}
41-
4232
request::Outcome::Success(Admin {
43-
username: username.to_string(),
44-
ipv4_address
33+
username: username.to_string()
4534
})
4635
}
4736
}

src/twofactor.rs

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -3,16 +3,10 @@ use sqlx::query;
33

44
use crate::{admin::Admin, Cmdb};
55

6-
#[get("/<cid>")]
7-
pub async fn twofactor_validate(mut db: Connection<Cmdb>, admin: Admin, cid: String) -> String {
8-
let ip_addr = match &admin.ipv4_address {
9-
Some(string) => string,
10-
None => return "No IP address".to_string(),
11-
};
12-
13-
match query("UPDATE twofactor SET approved = 1 WHERE cid = ? AND ckey = ? AND ip = ?").bind(cid).bind(&admin.username).bind(ip_addr).execute(&mut **db).await {
14-
Ok(res) => if res.rows_affected() > 0 { "Two factor request updated.".to_string() } else { format!("An error occured: {}.", &ip_addr) },
6+
#[get("/?<cid>&<ip>")]
7+
pub async fn twofactor_validate(mut db: Connection<Cmdb>, admin: Admin, cid: &str, ip: &str) -> String {
8+
match query("UPDATE twofactor SET approved = 1 WHERE cid = ? AND ckey = ? AND ip = ?").bind(&cid).bind(&admin.username).bind(&ip).execute(&mut **db).await {
9+
Ok(res) => if res.rows_affected() > 0 { "Two factor request updated.".to_string() } else { format!("An error occured.") },
1510
Err(err) => format!("An error occured: {:?}", err).to_string(),
1611
}
17-
1812
}

0 commit comments

Comments
 (0)