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
#![deny(clippy::cargo)]
use serde::{Deserialize, Serialize};

/// User object
#[derive(Deserialize, Serialize)]
pub struct User {
    pub id: i64,
    pub name: String,
}

/// May be returned for any endpoint when said endpoint has a failure
#[derive(Deserialize, Serialize)]
pub struct ApiError {
    pub error: String,
}

/// Returned by the /auth/token and /auth/totp routes. Always use /auth/token first, you will be granted a temporary Bearer token if needs_totp is true, you can then call /auth/totp with the Bearer token and TOTP authcode.
#[derive(Deserialize, Serialize)]
pub struct LoginResponse {
    pub token: String,
    pub needs_totp: bool,
}

/// For requesting to the /auth/totp route. You must also have a temporary TOTP authtoken first!
#[derive(Deserialize, Serialize)]
pub struct TotpRequest {
    pub code: String,
}

#[derive(Deserialize, Serialize)]
pub struct MessageCreate {
    pub contents: String,
}

#[derive(Serialize, Deserialize)]
pub struct UserCreate {
    pub email: String,
    pub name: String,
    pub password: String,
    pub pubkey: String,
    pub privkey: String,
    pub security_level: UserSecurityLevel,
}

#[derive(Serialize, Deserialize)]
pub enum UserSecurityLevel {
    Max,
    Reasonable,
    Low,
}

impl ToString for UserSecurityLevel {
    fn to_string(&self) -> String {
        match self {
            Self::Max => "Max".to_string(),
            Self::Reasonable => "Reasonable".to_string(),
            Self::Low => "Low".to_string(),
        }
    }
}