aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/handlers.rs12
-rw-r--r--src/schema.rs6
2 files changed, 12 insertions, 6 deletions
diff --git a/src/handlers.rs b/src/handlers.rs
index e12d83e..6305560 100644
--- a/src/handlers.rs
+++ b/src/handlers.rs
@@ -229,8 +229,6 @@ pub async fn authenticate_user(
229 } 229 }
230 }; 230 };
231 231
232 let provided_id = request.student_id.clone();
233
234 let privileged_student_id = match MetuId::new(request.student_id, request.passwd) { 232 let privileged_student_id = match MetuId::new(request.student_id, request.passwd) {
235 Some(id) => id, 233 Some(id) => id,
236 None => { 234 None => {
@@ -243,18 +241,20 @@ pub async fn authenticate_user(
243 } 241 }
244 }; 242 };
245 243
244 // Students should be able to authenticate once
246 { 245 {
247 let userlist = db.users.read(); 246 let userlist = db.users.read();
248 247
249 if userlist.contains_key(&provided_id) { 248 for (_, user) in userlist.iter() {
250 let res_json = warp::reply::json(&GradeCoinResponse { 249 if user.user_id == privileged_student_id {
250 let res_json = warp::reply::json(&GradeCoinResponse {
251 res: ResponseType::Error, 251 res: ResponseType::Error,
252 message: 252 message:
253 "This user is already authenticated, do you think this is a mistake? Contact me" 253 "This user is already authenticated, do you think this is a mistake? Contact me"
254 .to_owned(), 254 .to_owned(),
255 }); 255 });
256 256 return Ok(warp::reply::with_status(res_json, StatusCode::BAD_REQUEST));
257 return Ok(warp::reply::with_status(res_json, StatusCode::BAD_REQUEST)); 257 }
258 } 258 }
259 } 259 }
260 260
diff --git a/src/schema.rs b/src/schema.rs
index 81bfc1b..40c6329 100644
--- a/src/schema.rs
+++ b/src/schema.rs
@@ -253,6 +253,12 @@ pub struct MetuId {
253 passwd: String, 253 passwd: String,
254} 254}
255 255
256impl MetuId {
257 pub fn quick_equal(&self, other: &str) -> bool {
258 self.id == other
259 }
260}
261
256/// The plaintext of the initial user authentication request 262/// The plaintext of the initial user authentication request
257#[derive(Serialize, Deserialize, Debug, PartialEq)] 263#[derive(Serialize, Deserialize, Debug, PartialEq)]
258pub struct AuthRequest { 264pub struct AuthRequest {