-
Notifications
You must be signed in to change notification settings - Fork 1
/
models.py
131 lines (105 loc) · 4.32 KB
/
models.py
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
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
"""Below we will define the necessary pydantic models to use in our application."""
from uuid import UUID, uuid4
from datetime import datetime
from typing import Optional, List
from pydantic import BaseModel, EmailStr #pylint: disable=no-name-in-module
class User(BaseModel): # pylint: disable=too-few-public-methods
"""
Represents a user in our application.
Attributes:
username (str): The user's username.
key (UUID, optional): The user's unique identifier. Defaults to a randomly generated UUID.
email (EmailStr): The user's email address.
user_password (str, optional): The user's password. Defaults to None.
disabled (bool, optional): Whether the user account is disabled. Defaults to False.
friends (List[str], optional): A list of the user's friends. Defaults to an empty list.
otp_secret (str, optional): The user's one-time password secret. Defaults to None.
"""
username: str
email: EmailStr
user_password : Optional[str]
disabled: bool = False
friends: List[str] = []
otp_secret: Optional[str] = None
class Reader(BaseModel): # pylint: disable=too-few-public-methods
"""A helper class for the message creation process.
Attributes:
username (str or None): The username of the reader.
encrypted_sym_key (str or None): The encrypted symmetric key for the message.
"""
username: str or None = None
encrypted_sym_key: str or None = None
class Thought(BaseModel): # pylint: disable=too-few-public-methods
"""
Represents a thought with a username, key, title, content, rating, and creation date.
Attributes:
username (str): The username of the author of the thought.
key (Optional[UUID], optional): The unique identifier of the thought. Defaults to a new UUID4 instance.
title (str): The title of the thought.
content (str): The content of the thought.
rating (Optional[float], optional): The rating of the thought. Defaults to 0.0.
creation_date (Optional[datetime], optional): The creation date of the thought. Defaults to None.
"""
username: str
key: Optional[UUID] = uuid4()
title: str
content: str
rating: Optional[float] = 0.0
creation_date: Optional[datetime]
class Token(BaseModel): # pylint: disable=too-few-public-methods
"""Class defining our JWT token.
Attributes:
access_token (str): The access token string.
token_type (str): The type of token (e.g., "bearer").
"""
access_token: str
token_type: str
class TokenData(BaseModel): # pylint: disable=too-few-public-methods
"""
Helper class for the authentication process.
Attributes:
username (str or None): The username associated with the authentication process. Defaults to None.
"""
username: str or None = None
class UserInDB(User): # pylint: disable=too-few-public-methods
"""Helper class for the authentication process.
This class inherits from the User class and includes an additional property for hashed password.
Attributes:
hashed_pw (str): The hashed password for the user.
"""
hashed_pw: str
class PubKey(BaseModel): # pylint: disable=too-few-public-methods
"""
A class representing a public key.
Attributes:
pub_key (str): The string representation of the public key.
Note:
This class is a subclass of BaseModel and inherits all its attributes and methods.
"""
pub_key: str
class KeyStore(BaseModel): # pylint: disable=too-few-public-methods
"""
A class representing a key store that stores a public key and a symmetric key.
Attributes:
pub_key (str): A string representing the public key.
symmetric_key (str): A string representing the symmetric key.
"""
pub_key : str
symmetric_key : str
class SymKeyRequest(BaseModel): # pylint: disable=too-few-public-
"""
A request model for symmetric key exchange between a user and their friend.
Attributes:
-----------
user_password : str
The user's password.
friend_username : str
The username of the user's friend.
"""
user_password : str
friend_username : str
class PasswordResetUser(BaseModel):
username : str
class MessageObject(BaseModel):
friend_username : str
message : str