aboutsummaryrefslogtreecommitdiffstats
path: root/src/student.rs
blob: 2b9c5bdc7dc558f490fc75cef3624d4a501e9a9b (plain)
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
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,
}

#[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
    }
}