diff options
| author | Yigit Sever | 2022-04-11 19:01:42 +0300 |
|---|---|---|
| committer | Yigit Sever | 2022-04-11 19:01:42 +0300 |
| commit | 426e83ec6fba028692bed334803ae9d3a645cb18 (patch) | |
| tree | a92c2d62f54e28493d1d3b3ddfc185c1ed5cf4a5 /src/student.rs | |
| parent | 04c3b4597a995d73e6925c5391bfa27d27f298b7 (diff) | |
| download | gradecoin-426e83ec6fba028692bed334803ae9d3a645cb18.tar.gz gradecoin-426e83ec6fba028692bed334803ae9d3a645cb18.tar.bz2 gradecoin-426e83ec6fba028692bed334803ae9d3a645cb18.zip | |
[WIP] Spring cleaning
Diffstat (limited to 'src/student.rs')
| -rw-r--r-- | src/student.rs | 96 |
1 files changed, 96 insertions, 0 deletions
diff --git a/src/student.rs b/src/student.rs new file mode 100644 index 0000000..4b7acf1 --- /dev/null +++ b/src/student.rs | |||
| @@ -0,0 +1,96 @@ | |||
| 1 | use crate::Fingerprint; | ||
| 2 | use lazy_static::lazy_static; | ||
| 3 | use serde::{Deserialize, Serialize}; | ||
| 4 | use std::{collections::HashSet, fmt}; | ||
| 5 | |||
| 6 | #[derive(Debug, Serialize, Deserialize, PartialEq)] | ||
| 7 | pub struct UserAtRest { | ||
| 8 | pub fingerprint: Fingerprint, | ||
| 9 | pub user: User, | ||
| 10 | } | ||
| 11 | |||
| 12 | /// A Student | ||
| 13 | /// | ||
| 14 | /// - [`user_id`]: Can only be one of the preapproved students (who are enlisted in the course) | ||
| 15 | /// - [`public_key`]: A PEM format public key "---- BEGIN" and all | ||
| 16 | /// - [`balance`]: User's current Gradecoin amount | ||
| 17 | /// | ||
| 18 | /// This should ideally include the fingerprint as well? | ||
| 19 | #[derive(Serialize, Deserialize, Debug, PartialEq)] | ||
| 20 | pub struct User { | ||
| 21 | pub user_id: MetuId, | ||
| 22 | pub public_key: String, | ||
| 23 | pub balance: u16, | ||
| 24 | #[serde(skip, default = "bool::default")] | ||
| 25 | pub is_bot: bool, | ||
| 26 | } | ||
| 27 | |||
| 28 | /// The values are hard coded in [`static@OUR_STUDENTS`] so `MetuId::new`() can accept/reject values based on that | ||
| 29 | #[derive(Serialize, Deserialize, Debug, PartialEq, Clone)] | ||
| 30 | pub struct MetuId { | ||
| 31 | id: String, | ||
| 32 | passwd: String, | ||
| 33 | } | ||
| 34 | |||
| 35 | impl fmt::Display for MetuId { | ||
| 36 | fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { | ||
| 37 | write!(f, "{}", self.id) | ||
| 38 | } | ||
| 39 | } | ||
| 40 | |||
| 41 | impl MetuId { | ||
| 42 | pub fn new(id: String, pwd: String) -> Option<Self> { | ||
| 43 | if OUR_STUDENTS.contains(&(&*id, &*pwd)) { | ||
| 44 | Some(MetuId { id, passwd: pwd }) | ||
| 45 | } else { | ||
| 46 | None | ||
| 47 | } | ||
| 48 | } | ||
| 49 | } | ||
| 50 | |||
| 51 | // TODO: remove this, read from a yaml or something, then MetuId::new gets a self <11-04-22, yigit> // | ||
| 52 | |||
| 53 | // Students who are authorized to have Gradecoin accounts | ||
| 54 | lazy_static! { | ||
| 55 | static ref OUR_STUDENTS: HashSet<(&'static str, &'static str)> = { | ||
| 56 | [ | ||
| 57 | ("e254275", "DtNX1qk4YF4saRH"), | ||
| 58 | ("e223687", "cvFEs4XLjuGBD1v"), | ||
| 59 | ("e211024", "voQAcxiKJmEXYRT"), | ||
| 60 | ("e209888", "O75dli6AQtz2tUi"), | ||
| 61 | ("e223725", "xXuTD3Y4tyrv2Jz"), | ||
| 62 | ("e209362", "N7wGm5XU5zVWOWu"), | ||
| 63 | ("e209898", "aKBFfB8fZMq8pVn"), | ||
| 64 | ("e230995", "TgcHGlqeFhQGx42"), | ||
| 65 | ("e223743", "YVWVSWuIHplJk9C"), | ||
| 66 | ("e223747", "8LAeHrsjnwXh59Q"), | ||
| 67 | ("e223749", "HMFeJqVOzwCPHbc"), | ||
| 68 | ("e223751", "NjMsxmtmy2VOwMW"), | ||
| 69 | ("e188126", "QibuPdV2gXfsVJW"), | ||
| 70 | ("e209913", "kMxJvl2vHSWCy4A"), | ||
| 71 | ("e203608", "mfkkR0MWurk6Rp1"), | ||
| 72 | ("e233013", "GCqHxdOaDj2pWXx"), | ||
| 73 | ("e216982", "2Z0xmgCStnj5qg5"), | ||
| 74 | ("e217185", "BcaZNlzlhPph7A3"), | ||
| 75 | ("e223780", "2KvVxKUQaA9H4sn"), | ||
| 76 | ("e194931", "hsC0Wb8PQ5vzwdQ"), | ||
| 77 | ("e223783", "ETUJA3kt1QYvJai"), | ||
| 78 | ("e254550", "rPRjX0A4NefvKWi"), | ||
| 79 | ("e217203", "lN3IWhGyCrGfkk5"), | ||
| 80 | ("e217477", "O9xlMaa7LanC82w"), | ||
| 81 | ("e223786", "UxI6czykJfp9T9N"), | ||
| 82 | ("e231060", "VJgziofQQPCoisH"), | ||
| 83 | ("e223795", "pmcTCKox99NFsqp"), | ||
| 84 | ("e223715", "1H5QuOYI1b2r9ET"), | ||
| 85 | ("e181932", "THANKYOUHAVEFUN"), | ||
| 86 | ("bank", "P7oxDm30g1jeIId"), | ||
| 87 | ("friend_1", "not_used"), | ||
| 88 | ("friend_2", "not_used"), | ||
| 89 | ("friend_3", "not_used"), | ||
| 90 | ("friend_4", "not_used"), | ||
| 91 | ] | ||
| 92 | .iter() | ||
| 93 | .copied() | ||
| 94 | .collect() | ||
| 95 | }; | ||
| 96 | } | ||
