env variables
This commit is contained in:
parent
91c13307aa
commit
c4d64f6ac7
18 changed files with 44 additions and 27 deletions
1
.vscode/settings.json
vendored
1
.vscode/settings.json
vendored
|
|
@ -2,6 +2,7 @@
|
|||
"cSpell.language": "en,de-DE",
|
||||
"cSpell.words": [
|
||||
"Chiara",
|
||||
"dotenv",
|
||||
"Hobbithöhle",
|
||||
"mailtrap",
|
||||
"Masala",
|
||||
|
|
|
|||
4
backend/src/backend/.env
Normal file
4
backend/src/backend/.env
Normal file
|
|
@ -0,0 +1,4 @@
|
|||
BACKEND_URL="http://localhost:8000"
|
||||
FRONTEND_URL="http://localhost:4321"
|
||||
SECRET="IamALocalSecretAndMustBeReplacedInProduction"
|
||||
ENVIRONMENT="local"
|
||||
BIN
backend/src/backend/__pycache__/config.cpython-314.pyc
Normal file
BIN
backend/src/backend/__pycache__/config.cpython-314.pyc
Normal file
Binary file not shown.
Binary file not shown.
6
backend/src/backend/config.py
Normal file
6
backend/src/backend/config.py
Normal file
|
|
@ -0,0 +1,6 @@
|
|||
import os
|
||||
|
||||
ENVIRONMENT = os.environ["ENVIRONMENT"]
|
||||
SECRET_KEY = os.environ["SECRET"]
|
||||
FRONTEND_URL = os.environ["FRONTEND_URL"]
|
||||
BACKEND_URL = os.environ["BACKEND_URL"]
|
||||
Binary file not shown.
Binary file not shown.
Binary file not shown.
|
|
@ -1,3 +1,5 @@
|
|||
from backend.config import SECRET_KEY
|
||||
import os
|
||||
from fastapi.security import HTTPBasicCredentials
|
||||
from fastapi import Security
|
||||
from fastapi.security import HTTPBearer
|
||||
|
|
@ -10,13 +12,11 @@ from backend.models.user import User
|
|||
from backend.internal.database import get_session
|
||||
from sqlmodel import Session
|
||||
from fastapi import HTTPException
|
||||
from fastapi.security.oauth2 import OAuth2PasswordBearer
|
||||
from fastapi import Depends
|
||||
from datetime import datetime
|
||||
from datetime import timedelta
|
||||
|
||||
|
||||
SECRET_KEY = "secret-key"
|
||||
ALGORITHM = "HS256"
|
||||
ACCESS_TOKEN_EXPIRE_DAYS = 360
|
||||
|
||||
|
|
|
|||
|
|
@ -20,7 +20,7 @@
|
|||
<span>Abbestellen</span>
|
||||
</a>
|
||||
|
||||
<a id="admin" href="https://blauwasser-mausis.de">Approve</a>
|
||||
<a id="admin" href="https://backend.blauwasser-mausis.de/?secret={{data.secret}}">Approve</a>
|
||||
</div>
|
||||
</body>
|
||||
|
||||
|
|
|
|||
|
|
@ -7,10 +7,12 @@
|
|||
|
||||
<body>
|
||||
<div>
|
||||
<h1>Willkommen, {{user.name}}</h1>
|
||||
<h1>Willkommen, {{data.name}}</h1>
|
||||
<p>Du hast dich bei Blauwasser-Mausis.de angemeldet. Solltest du das nicht gewesen sein, dann lösche die Daten einfach über den untenstehenden Link.</p>
|
||||
|
||||
<a href="https://blauwasser-mausis.de/blog/bootsuche-england">
|
||||
<p>Dein persönlicher Code, um alle Funktionen nutzen zu können: {{data.user_code}}</p>
|
||||
|
||||
<a href="https://backend.blauwasser-mausis.de/bootsuche-england">
|
||||
<span>Daten löschen</span>
|
||||
</a>
|
||||
</div>
|
||||
|
|
|
|||
|
|
@ -1,8 +1,8 @@
|
|||
from backend.config import ENVIRONMENT
|
||||
from mailtrap import Mail
|
||||
import mailtrap as mt
|
||||
from jinja2 import Environment, FileSystemLoader
|
||||
|
||||
|
||||
class ArticleData():
|
||||
def __init__(self, title, subtitle, description, link):
|
||||
self.title=title
|
||||
|
|
@ -27,9 +27,6 @@ def send_newsletter_admin_approval(data: ArticleData ):
|
|||
template = env.get_template('approval.jinja')
|
||||
output = template.render(data=data)
|
||||
|
||||
# with open("src/backend/internal/jinja_templates/output.html", "w") as f:
|
||||
# f.write(output)
|
||||
|
||||
mail = mt.Mail(
|
||||
sender=mt.Address(email="newsletter@blauwasser-mausis.de", name="Flaschenpost"),
|
||||
to=[mt.Address(email="blauwasser-mausis@proton.me")],
|
||||
|
|
@ -40,8 +37,15 @@ def send_newsletter_admin_approval(data: ArticleData ):
|
|||
|
||||
|
||||
def send_mail(mail: Mail):
|
||||
client = mt.MailtrapClient(token="<YOUR_API_TOKEN>")
|
||||
client.send(mail)
|
||||
if ENVIRONMENT == "local":
|
||||
print(f"Mail sent: {mail.subject}")
|
||||
else:
|
||||
client = mt.MailtrapClient(token="<YOUR_API_TOKEN>")
|
||||
client.send(mail)
|
||||
|
||||
def send_batch_mail():
|
||||
pass
|
||||
mt.BatchMail(
|
||||
sender=mt.Address(email="newsletter@blauwasser-mausis.de", name="Flaschenpost"),
|
||||
subject="Flaschenpost | Blauwasser-Mausis"
|
||||
|
||||
)
|
||||
|
|
|
|||
|
|
@ -1,4 +1,5 @@
|
|||
|
||||
from backend.config import FRONTEND_URL
|
||||
from backend.internal.authentication import create_access_token
|
||||
from backend.internal.mail_util import AdminApprovalData
|
||||
from backend.internal.mail_util import send_newsletter_admin_approval
|
||||
|
|
@ -6,15 +7,13 @@ from datetime import timedelta
|
|||
from datetime import datetime
|
||||
import feedparser
|
||||
|
||||
FEED_URL="http://localhost:4321/rss.xml"
|
||||
|
||||
def check_blog_rss_and_send_admin_mail():
|
||||
feed = feedparser.parse(FEED_URL)
|
||||
feed = feedparser.parse(f"{FRONTEND_URL}/rss.xml")
|
||||
for article in feed.entries:
|
||||
date_string = str(article["published"])
|
||||
date_object = datetime.strptime(date_string, '%a, %d %b %Y %H:%M:%S %Z')
|
||||
|
||||
if date_object > (datetime.now() - timedelta(days=1)):
|
||||
if date_object > (datetime.now() - timedelta(days=16)):
|
||||
title = str(article["title"])
|
||||
description = str(article["summary"])
|
||||
subtitle = str(article["subtitle"])
|
||||
|
|
|
|||
|
|
@ -1,13 +1,15 @@
|
|||
from dotenv import load_dotenv
|
||||
load_dotenv()
|
||||
|
||||
from backend.internal.rss_reader import check_blog_rss_and_send_admin_mail
|
||||
from .routers import users, comments
|
||||
from .routers import users, comments, newsletters
|
||||
from backend.internal.database import create_db_and_tables
|
||||
from fastapi import APIRouter
|
||||
from fastapi import FastAPI
|
||||
from fastapi_crons import Crons, get_cron_router
|
||||
from fastapi_crons import Crons
|
||||
|
||||
|
||||
# TODO: Newsletter
|
||||
# TODO: env
|
||||
# TODO: TLS
|
||||
# TODO: Deploy
|
||||
|
||||
|
|
@ -27,3 +29,4 @@ router = APIRouter()
|
|||
|
||||
app.include_router(users.router)
|
||||
app.include_router(comments.router)
|
||||
app.include_router(newsletters.router)
|
||||
Binary file not shown.
Binary file not shown.
|
|
@ -1,9 +1,8 @@
|
|||
from fastapi import Form
|
||||
from fastapi import Depends
|
||||
from fastapi import APIRouter
|
||||
|
||||
router = APIRouter(
|
||||
prefix="newsletter",
|
||||
prefix="/newsletter",
|
||||
tags=[""],
|
||||
dependencies=[],
|
||||
responses={404: {"description": "Not found"}},
|
||||
|
|
@ -18,14 +18,13 @@ from fastapi import APIRouter
|
|||
from fastapi_limiter.depends import RateLimiter
|
||||
|
||||
router = APIRouter(
|
||||
prefix="",
|
||||
tags=[""],
|
||||
prefix="/users",
|
||||
dependencies=[],
|
||||
responses={404: {"description": "Not found"}},
|
||||
)
|
||||
|
||||
@router.post(
|
||||
"/users",
|
||||
"/",
|
||||
status_code=201,
|
||||
dependencies=[Depends(RateLimiter(limiter=Limiter(Rate(1, Duration.MINUTE))))]
|
||||
)
|
||||
|
|
@ -55,7 +54,7 @@ def login(user_code: str = Form(), session: Session = Depends(get_session)) -> s
|
|||
return create_access_token({"sub": user.user_code})
|
||||
|
||||
@router.post(
|
||||
"users/forgot",
|
||||
"/forgot",
|
||||
dependencies=[Depends(RateLimiter(limiter=Limiter(Rate(1, Duration.MINUTE))))]
|
||||
)
|
||||
def forgot_user_code(email: str = Form(), session: Session = Depends(get_session)):
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue