diff options
author | Yigit Sever | 2021-04-20 00:43:21 +0300 |
---|---|---|
committer | Yigit Sever | 2021-04-20 00:43:21 +0300 |
commit | a53ccc6f5ca64d46abb94ae743dc5d063a87959e (patch) | |
tree | 75feb35db75b627d6e7e1a333b22094b58fca780 | |
parent | 10afcb0b0ea8794b5b14acedba48bf291b164e41 (diff) | |
download | gradecoin-a53ccc6f5ca64d46abb94ae743dc5d063a87959e.tar.gz gradecoin-a53ccc6f5ca64d46abb94ae743dc5d063a87959e.tar.bz2 gradecoin-a53ccc6f5ca64d46abb94ae743dc5d063a87959e.zip |
Bugfix
Users cannot authenticate twice now
-rw-r--r-- | src/handlers.rs | 12 | ||||
-rw-r--r-- | src/schema.rs | 6 |
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 | ||
256 | impl 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)] |
258 | pub struct AuthRequest { | 264 | pub struct AuthRequest { |