Skip to content

Commit a158e32

Browse files
committed
two factor authentication
1 parent 7eaa093 commit a158e32

File tree

2 files changed

+35
-1
lines changed

2 files changed

+35
-1
lines changed

src/main.rs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ mod new_players;
2727
mod player;
2828
mod stickyban;
2929
mod ticket;
30+
mod twofactor;
3031
mod whitelist;
3132

3233
#[rocket::async_trait]
@@ -139,7 +140,11 @@ fn rocket() -> _ {
139140
routes![whitelist::get_all_whitelistees],
140141
)
141142
.mount(
142-
format!{"{}/NewPlayers", base_url},
143+
format! {"{}/NewPlayers", base_url},
143144
routes![new_players::get_new_players],
144145
)
146+
.mount(
147+
format!("{}/TwoFactor", base_url),
148+
routes![twofactor::twofactor_validate],
149+
)
145150
}

src/twofactor.rs

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
use rocket_db_pools::Connection;
2+
use sqlx::query;
3+
4+
use crate::{admin::Admin, Cmdb};
5+
6+
#[get("/?<cid>&<ip>")]
7+
pub async fn twofactor_validate(
8+
mut db: Connection<Cmdb>,
9+
admin: Admin,
10+
cid: &str,
11+
ip: &str,
12+
) -> String {
13+
match query("UPDATE twofactor SET approved = 1 WHERE cid = ? AND ckey = ? AND ip = ?")
14+
.bind(&cid)
15+
.bind(&admin.username)
16+
.bind(&ip)
17+
.execute(&mut **db)
18+
.await
19+
{
20+
Ok(res) => {
21+
if res.rows_affected() > 0 {
22+
"Two factor request updated.".to_string()
23+
} else {
24+
format!("An error occured: could not find match for ckey: {}, cid: {}, ip: {}.", &cid, &admin.username, &ip)
25+
}
26+
}
27+
Err(err) => format!("An error occured: {:?}", err).to_string(),
28+
}
29+
}

0 commit comments

Comments
 (0)