thoth_api/account/
model.rs

1use chrono::naive::NaiveDateTime;
2use serde::{Deserialize, Serialize};
3use uuid::Uuid;
4
5#[cfg(feature = "backend")]
6use crate::schema::account;
7
8#[cfg_attr(feature = "backend", derive(Queryable))]
9#[derive(Debug, PartialEq, Deserialize, Serialize)]
10pub struct Account {
11    pub account_id: Uuid,
12    pub name: String,
13    pub surname: String,
14    pub email: String,
15    pub hash: Vec<u8>,
16    pub salt: String,
17    pub is_admin: bool,
18    pub is_bot: bool,
19    pub is_active: bool,
20    pub registered: NaiveDateTime,
21    pub token: Option<String>,
22}
23
24#[cfg_attr(feature = "backend", derive(Insertable))]
25#[cfg_attr(feature = "backend", table_name = "account")]
26pub struct NewAccount {
27    pub name: String,
28    pub surname: String,
29    pub email: String,
30    pub hash: Vec<u8>,
31    pub salt: String,
32    pub is_admin: bool,
33    pub is_bot: bool,
34}
35
36#[derive(Debug)]
37pub struct AccountData {
38    pub name: String,
39    pub surname: String,
40    pub email: String,
41    pub password: String,
42    pub is_admin: bool,
43    pub is_bot: bool,
44}
45
46#[derive(Debug, Clone, Deserialize, Serialize)]
47pub struct Token {
48    pub sub: String,
49    pub exp: i64,
50    pub iat: i64,
51    pub jti: String,
52}
53
54#[derive(Clone)]
55pub struct DecodedToken {
56    pub jwt: Option<Token>,
57}
58
59#[derive(Debug, PartialEq, Deserialize, Serialize)]
60pub struct Session {
61    pub token: String,
62}
63
64#[derive(Debug, PartialEq, Deserialize, Serialize)]
65pub struct LoginCredentials {
66    pub email: String,
67    pub password: String,
68}
69
70#[derive(Debug, PartialEq, Deserialize, Serialize)]
71pub struct Login(pub Session);
72
73#[derive(Debug, PartialEq, Deserialize, Serialize)]
74pub struct LoginSession(pub Session);
75
76#[derive(Debug, PartialEq, Deserialize, Serialize)]
77pub struct Logout(pub Session);
78
79#[derive(Debug, PartialEq, Deserialize, Serialize)]
80pub struct LogoutResponse;
81
82impl Session {
83    pub fn new<T>(token: T) -> Self
84    where
85        String: From<T>,
86    {
87        Self {
88            token: token.into(),
89        }
90    }
91}