@cryptotaxi247 / CoPilot / commits / 6b0cd784

smtp model to store creds and smtp settings (#14)

* smtp model to store creds and smtp settings * precommit fixes

taylor_socfortress committed Jul 12, 2023 at 14:16 UTC 6b0cd784b72d0941dd5135fa9ffb2509f9aea204
1 file changed +70
backend/app/models/smtp.py new
+70
@@ -0,0 +1,70 @@
1 +from datetime import datetime
2 +
3 +from sqlalchemy import Column
4 +from sqlalchemy import DateTime
5 +from sqlalchemy import Integer
6 +from sqlalchemy import String
7 +
8 +from app import db
9 +from app import ma
10 +
11 +
12 +# Path: backend\app\models.py
13 +class EmailCredentials(db.Model):
14 + """
15 + Class for storing user email credentials and SMTP settings.
16 + This class inherits from SQLAlchemy's Model class.
17 + """
18 +
19 + id: Column[Integer] = db.Column(db.Integer, primary_key=True)
20 + email: Column[String] = db.Column(db.String(100), nullable=False, unique=True)
21 + password: Column[String] = db.Column(db.String(100), nullable=False)
22 + smtp_server: Column[String] = db.Column(db.String(100), nullable=False)
23 + smtp_port: Column[Integer] = db.Column(db.Integer, nullable=False)
24 + timestamp: Column[DateTime] = db.Column(db.DateTime, default=datetime.utcnow)
25 +
26 + def __init__(self, email: str, password: str, smtp_server: str, smtp_port: int):
27 + """
28 + Initialize a new instance of the EmailCredentials class.
29 +
30 + :param email: The email of the user.
31 + :param password: The email password of the user.
32 + :param smtp_server: The SMTP server.
33 + :param smtp_port: The SMTP port.
34 + """
35 + self.email = email
36 + self.password = password
37 + self.smtp_server = smtp_server
38 + self.smtp_port = smtp_port
39 +
40 + def __repr__(self) -> str:
41 + """
42 + Returns a string representation of the EmailCredentials instance.
43 +
44 + :return: A string representation of the email.
45 + """
46 + return f"<EmailCredentials {self.email}>"
47 +
48 +
49 +class EmailCredentialsSchema(ma.Schema):
50 + """
51 + Schema for serializing and deserializing instances of the EmailCredentials class.
52 + """
53 +
54 + class Meta:
55 + """
56 + Meta class defines the fields to be serialized/deserialized.
57 + """
58 +
59 + fields: tuple = (
60 + "id",
61 + "email",
62 + "password",
63 + "smtp_server",
64 + "smtp_port",
65 + "timestamp",
66 + )
67 +
68 +
69 +email_credentials_schema: EmailCredentialsSchema = EmailCredentialsSchema()
70 +email_credentials_schemas: EmailCredentialsSchema = EmailCredentialsSchema(many=True)