1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
|
use crate::{Fingerprint, Id};
use serde::{Deserialize, Serialize};
use std::fmt;
#[derive(Debug, Serialize, Deserialize, PartialEq)]
pub struct UserAtRest {
pub fingerprint: Fingerprint,
pub user: User,
}
/// A Student
///
/// - [`user_id`]: Can only be one of the preapproved students (who are enlisted in the course)
/// - [`public_key`]: A PEM format public key "---- BEGIN" and all
/// - [`balance`]: User's current Gradecoin amount
///
/// This should ideally include the fingerprint as well?
#[derive(Serialize, Deserialize, Debug, PartialEq)]
pub struct User {
pub user_id: MetuId,
pub public_key: String,
pub balance: u16,
#[serde(skip, default = "bool::default")]
pub is_bot: bool,
}
impl fmt::Display for User {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
write!(f, "{}", self.user_id.get_id())
}
}
impl fmt::Display for UserAtRest {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
write!(f, "{}", self.user)
}
}
#[derive(Serialize, Deserialize, Debug, PartialEq, Clone)]
pub struct MetuId {
id: Id,
passwd: String,
}
impl fmt::Display for MetuId {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
write!(f, "{}", self.id)
}
}
impl MetuId {
pub fn new(id: String, passwd: String) -> Self {
MetuId { id, passwd }
}
pub fn get_id(&self) -> &Id {
&self.id
}
pub fn get_passwd(&self) -> &String {
&self.passwd
}
}
|