Initial commit

This commit is contained in:
2026-11-05 08:28:15 +00:00
commit 08582a4f70
65 changed files with 1886 additions and 0 deletions
+20
View File
@@ -0,0 +1,20 @@
import os
class EnvironmentService:
def __init__(self):
self.LINE_COMMENTED = '#'
self.VALUE_SEPARATOR = '='
def LoadEnvFile(self, filepath:str):
with open(filepath, 'r') as file:
for line in file:
line = line.strip()
if line and not line.startswith(self.LINE_COMMENTED) and self.VALUE_SEPARATOR in line:
key,value = line.split(self.VALUE_SEPARATOR, 1)
self.Set(key, value) # os.environ[key] = value
def Get(self, key:str):
return os.getenv(key)
def Set(self, key: str, value):
os.environ[key] = value
+27
View File
@@ -0,0 +1,27 @@
import os
import smtplib
from email.mime.text import MIMEText
from email.mime.multipart import MIMEMultipart
# https://realpython.com/python-send-email/
class MailingService:
def __init__(self):
self.server = os.getenv('MAILING_SMTP_SERVER')
self.port = os.getenv('MAILING_SMTP_PORT')
self.user = os.getenv('MAILING_SMTP_USER')
self.password = os.getenv('MAILING_SMTP_PASSWORD')
def SendMessage(self, address: str, subject: str, content: str):
try:
message = MIMEMultipart()
message['From'] = self.user
message['To'] = address
message['Subject'] = subject
message.attach(MIMEText(content, 'plain'))
with smtplib.SMTP_SSL(self.server, self.port) as server:
server.login(self.user, self.password)
server.send_message(message)
server.quit()
except Exception as e:
print(e)
+22
View File
@@ -0,0 +1,22 @@
import os
import jwt
from datetime import datetime, timedelta
class TokenService:
def __init__(self):
self.SECRET = os.getenv('TOKEN_SECRET')
self.ALGORITHM = os.getenv('TOKEN_ALGORITHM')
self.LIVE_HOUR_MINUTES = os.getenv('TOKEN_LIVE')
def GenerateToken(self, payload):
payload['exp'] = datetime.now() + timedelta(minutes = int(self.LIVE_HOUR_MINUTES))
return jwt.encode(payload, self.SECRET, self.ALGORITHM)
def ValidateToken(self, token: str):
try:
if os.getenv('ENVIRONMENT') == 'Development' and token == "1":
return True
return jwt.decode(token, self.SECRET, algorithms = self.ALGORITHM)
except jwt.InvalidTokenError as e:
return False