aboutsummaryrefslogtreecommitdiffstats
path: root/src/handlers.rs
diff options
context:
space:
mode:
authorYigit Sever2021-04-14 18:41:19 +0300
committerYigit Sever2021-04-14 19:12:51 +0300
commit99f9c5f918a6a9946015cf0e9f2e0054e28b3ab0 (patch)
treeacddaca634eed06c909c8d27c8c19fe11379d3ee /src/handlers.rs
parentbd4fafc54a23c1587eac662d14a88bcfadcfcb86 (diff)
downloadgradecoin-99f9c5f918a6a9946015cf0e9f2e0054e28b3ab0.tar.gz
gradecoin-99f9c5f918a6a9946015cf0e9f2e0054e28b3ab0.tar.bz2
gradecoin-99f9c5f918a6a9946015cf0e9f2e0054e28b3ab0.zip
[WIP] Address users by their fingerprint
Diffstat (limited to 'src/handlers.rs')
-rw-r--r--src/handlers.rs8
1 files changed, 5 insertions, 3 deletions
diff --git a/src/handlers.rs b/src/handlers.rs
index 5e957bb..cc4c6c3 100644
--- a/src/handlers.rs
+++ b/src/handlers.rs
@@ -12,7 +12,7 @@ use parking_lot::RwLockUpgradableReadGuard;
12use rsa::{PaddingScheme, RSAPrivateKey}; 12use rsa::{PaddingScheme, RSAPrivateKey};
13use serde::Serialize; 13use serde::Serialize;
14use serde_json; 14use serde_json;
15use sha2; 15use sha2::Sha256;
16use std::convert::Infallible; 16use std::convert::Infallible;
17use std::fs; 17use std::fs;
18use warp::{http::StatusCode, reply}; 18use warp::{http::StatusCode, reply};
@@ -152,6 +152,8 @@ pub async fn authenticate_user(
152 return Ok(warp::reply::with_status(res_json, StatusCode::BAD_REQUEST)); 152 return Ok(warp::reply::with_status(res_json, StatusCode::BAD_REQUEST));
153 } 153 }
154 154
155 let fingerprint = Sha256::digest(&request.public_key.as_bytes());
156
155 let new_user = User { 157 let new_user = User {
156 user_id: privileged_student_id, 158 user_id: privileged_student_id,
157 public_key: request.public_key, 159 public_key: request.public_key,
@@ -163,8 +165,8 @@ pub async fn authenticate_user(
163 fs::write(format!("users/{}.guy", new_user.user_id), user_json).unwrap(); 165 fs::write(format!("users/{}.guy", new_user.user_id), user_json).unwrap();
164 166
165 let mut userlist = RwLockUpgradableReadGuard::upgrade(userlist); 167 let mut userlist = RwLockUpgradableReadGuard::upgrade(userlist);
166 userlist.insert(provided_id, new_user); 168
167 // TODO: signature of the public key, please <11-04-21, yigit> // 169 userlist.insert(format!("{:x}", fingerprint), new_user);
168 170
169 let res_json = warp::reply::json(&GradeCoinResponse { 171 let res_json = warp::reply::json(&GradeCoinResponse {
170 res: ResponseType::Success, 172 res: ResponseType::Success,