Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

smtp model to store creds and smtp settings #14

Merged
merged 2 commits into from
Jul 12, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
70 changes: 70 additions & 0 deletions backend/app/models/smtp.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
from datetime import datetime

from sqlalchemy import Column
from sqlalchemy import DateTime
from sqlalchemy import Integer
from sqlalchemy import String

from app import db
from app import ma


# Path: backend\app\models.py
class EmailCredentials(db.Model):
"""
Class for storing user email credentials and SMTP settings.
This class inherits from SQLAlchemy's Model class.
"""

id: Column[Integer] = db.Column(db.Integer, primary_key=True)
email: Column[String] = db.Column(db.String(100), nullable=False, unique=True)
password: Column[String] = db.Column(db.String(100), nullable=False)
smtp_server: Column[String] = db.Column(db.String(100), nullable=False)
smtp_port: Column[Integer] = db.Column(db.Integer, nullable=False)
timestamp: Column[DateTime] = db.Column(db.DateTime, default=datetime.utcnow)

def __init__(self, email: str, password: str, smtp_server: str, smtp_port: int):
"""
Initialize a new instance of the EmailCredentials class.

:param email: The email of the user.
:param password: The email password of the user.
:param smtp_server: The SMTP server.
:param smtp_port: The SMTP port.
"""
self.email = email
self.password = password
self.smtp_server = smtp_server
self.smtp_port = smtp_port

def __repr__(self) -> str:
"""
Returns a string representation of the EmailCredentials instance.

:return: A string representation of the email.
"""
return f"<EmailCredentials {self.email}>"


class EmailCredentialsSchema(ma.Schema):
"""
Schema for serializing and deserializing instances of the EmailCredentials class.
"""

class Meta:
"""
Meta class defines the fields to be serialized/deserialized.
"""

fields: tuple = (
"id",
"email",
"password",
"smtp_server",
"smtp_port",
"timestamp",
)


email_credentials_schema: EmailCredentialsSchema = EmailCredentialsSchema()
email_credentials_schemas: EmailCredentialsSchema = EmailCredentialsSchema(many=True)