Compare commits

..

No commits in common. "0ea283435e856341d8166a27d2f77b0268c959bd" and "350fe68bf72516ea4f07a89799728e16c154afae" have entirely different histories.

18 changed files with 93 additions and 277 deletions

View file

@ -2,12 +2,11 @@
"cSpell.language": "en,de-DE",
"cSpell.words": [
"Chiara",
"dotenv",
"Folierung",
"dotenv",
"Hobbithöhle",
"mailtrap",
"Masala",
"mausis",
"Pomorie",
"Reinke",
"rundgelutschte",

View file

@ -1,5 +1,5 @@
BACKEND_URL="http://localhost:8000"
FRONTEND_URL="http://localhost:4322"
FRONTEND_URL="http://localhost:4321"
JWT_SECRET="IamALocalSecretAndMustBeReplacedInProduction"
ENVIRONMENT="local"
MAILTRAP_API_TOKEN="FakedyFake"

View file

@ -6,25 +6,21 @@
</head>
<body>
<div id="card">
<div class="center"">
<img src=" https://blauwasser-mausis.de/BWM_512.webp">
</div>
<h4 class="accent">Neuer Artikel</h4>
<p>{{data.date}} | Autor: {{data.author}} | Lesezeit: {{data.time2read}} min</p>
<h1>{{data.title}}</h1>
<h2>{{data.subtitle}}</h2>
<div>
<h1>Neuer Artikel:</h1>
<h3>{{data.title}}</h3>
<h4>{{data.subtitle}}</h4>
<p>{{data.description}}</p>
<a href={{data.link}}>
<button>⚓︎ Zum Artikel</button>
</a>
<hr>
<div class="center"><a id="hide" href="https://blauwasser-mausis.de/user">
<span>Abbestellen</span>
</a></p>
</div>
<a id="admin" href="https://backend.blauwasser-mausis.de/admin/newsletter/{{data.secret}}">Approve</a>
<a href={{data.link}}>
<button>Zum Artikel</button>
</a>
<a href="https://blauwasser-mausis.de/blog/bootsuche-england">
<span>Abbestellen</span>
</a>
<a id="admin" href="https://backend.blauwasser-mausis.de/?secret={{data.secret}}">Approve</a>
</div>
</body>
@ -39,54 +35,18 @@
}
#card {
background-image: linear-gradient(to bottom, #1d3238, #3c6a7b);
padding: 16px 32px;
border-radius: 8px;
}
.center {
div {
display: flex;
flex-direction: row;
justify-content: center;
align-items: center;
flex-direction: column;
background-color: lightgrey;
padding: 32px 64px;
border-radius: 3px;
}
img {
width: 88px;
padding: 0 0 16px 0;
}
h1,
h2,
h3,
h4,
p {
color: white;
}
.accent {
color: #ffff00;
font-weight: 600;
}
#hide {
color: #bbbebf;
font-size: 12px;
font-weight: 700;
}
h1,
h2,
h3,
h4,
p,
hr {
margin: 16px 0 16px 0;
}
p {
line-height: 1.5;
font-size: 14px;
h4 {
margin: 0;
}
button {
@ -94,14 +54,6 @@
background-color: azure;
border-radius: 3px;
border: none;
font-weight: 700;
color: #1d3238;
margin: 16px 0 24px 0;
width: 100%;
}
hr {
width: 100%;
}
#admin {

View file

@ -6,23 +6,19 @@
</head>
<body>
<div id="card">
<div class="center"">
<img src=" https://blauwasser-mausis.de/BWM_512.webp">
</div>
<h4 class="accent">Neuer Artikel</h4>
<p>{{data.date}} | Autor: {{data.author}} | Lesezeit: {{data.time2read}} min</p>
<h1>{{data.title}}</h1>
<h2>{{data.subtitle}}</h2>
<p>{{data.description}}</p>
<a href={{data.link}}>
<button>⚓︎ Zum Artikel</button>
<div>
<h1>Hey {{data.user.name}}, es gibt einen neuen Artikel:</h1>
<h3>{{data.article.title}}</h3>
<h4>{{data.article.subtitle}}</h4>
<p>{{data.article.description}}</p>
<a href={{data.article.link}}>
<button>Zum Artikel</button>
</a>
<a href="https://blauwasser-mausis.de/">
<span>Abbestellen</span>
</a>
<hr>
<div class="center"><a id="hide" href="https://blauwasser-mausis.de/user">
<span>Abbestellen</span>
</a></p>
</div>
</div>
</body>
@ -37,54 +33,18 @@
}
#card {
background-image: linear-gradient(to bottom, #1d3238, #3c6a7b);
padding: 16px 32px;
border-radius: 8px;
}
.center {
div {
display: flex;
flex-direction: row;
justify-content: center;
align-items: center;
flex-direction: column;
background-color: lightgrey;
padding: 32px 64px;
border-radius: 3px;
}
img {
width: 88px;
padding: 0 0 16px 0;
}
h1,
h2,
h3,
h4,
p {
color: white;
}
.accent {
color: #ffff00;
font-weight: 600;
}
#hide {
color: #bbbebf;
font-size: 12px;
font-weight: 700;
}
h1,
h2,
h3,
h4,
p,
hr {
margin: 16px 0 16px 0;
}
p {
line-height: 1.5;
font-size: 14px;
h4 {
margin: 0;
}
button {
@ -92,13 +52,5 @@
background-color: azure;
border-radius: 3px;
border: none;
font-weight: 700;
color: #1d3238;
margin: 16px 0 24px 0;
width: 100%;
}
hr {
width: 100%;
}
</style>

View file

@ -6,30 +6,15 @@
</head>
<body>
<div id="card">
<div class="center"">
<img src="https://blauwasser-mausis.de/BWM_512.webp">
</div>
<div>
<p id="welcome"><strong>⚓︎ Willkommen {{data.name}},</strong> du hast dich erfolgreich registriert.</p>
<p id="code-text">Dein persönlicher Code zum Anmelden: </p>
<p class="accent">{{data.user_code}}</p>
<p id="info-text">Du erhälst nun eine Mail, wenn wir einen neuen Artikel veröffentlichen. Auch die
zukünftigen Features des Blogs (z.B. Kommentare) kannst du so nutzen.
<br />
Alle Einstellung kannst du jederzeit in deinem Profil anpassen.
</p>
<a href="https://blauwasser-mausis.de/login">
<button>⚓︎ Jetzt einloggen ⚓︎</button>
</a>
</div>
<hr>
<div class="center">
<p class="hide">Du hast dich nicht registriert? Einfach <a class="hide"
href="https://blauwasser-mausis.de/user">hier</a>
löschen. </p>
</div>
</div>
<div>
<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>
<p>Dein persönlicher Code, um alle Funktionen nutzen zu können: {{data.user_code}}</p>
<a href="https://blauwasser-mausis.de/">
<span>Daten löschen</span>
</a>
</div>
</body>
@ -44,70 +29,12 @@
}
#card {
background-image: linear-gradient(to bottom, #1d3238, #3c6a7b);
padding: 16px 32px;
border-radius: 8px;
}
.center {
div {
display: flex;
flex-direction: row;
justify-content: center;
}
img {
width: 88px;
padding: 0 0 16px 0;
}
p {
color: white;
}
#welcome {
padding-bottom: 8px;
font-size: 1.1rem;
}
#code-text {
margin: 0;
}
.accent {
color: #ffff00;
font-weight: 600;
padding: 0px;
margin: 0;
font-size: 1.4rem;
}
#info-text {
padding-top: 12px;
}
p {
line-height: 1.5;
font-size: 0.9rem;
}
button {
padding: 12px;
background-color: azure;
align-items: center;
flex-direction: column;
background-color: lightgrey;
padding: 32px 64px;
border-radius: 3px;
border: none;
font-weight: 700;
color: #1d3238;
margin: 16px 0 24px 0;
width: 100%;
}
hr {
width: 100%;
color: white;
}
.hide {
color: #bbbebf;
}
</style>

View file

@ -12,27 +12,21 @@ from jinja2 import Environment, FileSystemLoader
APP_ROOT = Path(__file__).resolve().parent.parent
class ArticleData():
def __init__(self, title, subtitle, description, link, date, author, time2read):
def __init__(self, title, subtitle, description, link):
self.title=title
self.subtitle=subtitle
self.description=description
self.link=link
self.date=date
self.author=author
self.time2read = time2read
title: str
subtitle: str
description: str
link: str
date: str
author: str
time2read: str
class AdminApprovalData(ArticleData):
def __init__(self,title, subtitle, description, link, date, author, time2read, secret):
ArticleData.__init__(self, title, subtitle, description, link, date, author, time2read)
def __init__(self,title, subtitle, description, link, secret):
ArticleData.__init__(self, title, subtitle, description, link)
self.secret = secret
secret: str
@ -44,7 +38,7 @@ def create_html_from_template(template_name: str, data):
return template.render(data=data)
def send_newsletter_admin_approval(data: ArticleData):
def send_newsletter_admin_approval(data: ArticleData ):
html = create_html_from_template("approval", data)
mail = mt.Mail(

View file

@ -1,3 +1,4 @@
from feedparser import FeedParserDict
from backend.config import FRONTEND_URL
from backend.internal.authentication import create_access_token
@ -12,17 +13,15 @@ def check_blog_rss_and_send_admin_mail():
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)):
title = str(article["title"])
description = str(article["summary"])
subtitle = str(article["subtitle"])
link = str(article["link"])
author = str(article["author"])
time2read = str(article["time2read"])
date = date_object.strftime('%d.%m.%y')
secret = create_access_token({"sub": title})
data = AdminApprovalData(title, subtitle, description, link, date, author, time2read, secret)
data = AdminApprovalData(title, subtitle, description, link, secret)
send_newsletter_admin_approval(data)
def find_article_by_title(title: str) -> FeedParserDict | None:

View file

@ -1,3 +1,4 @@
from dotenv.main import load_dotenv
load_dotenv()

View file

@ -1,8 +1,12 @@
from sqlmodel._compat import ConfigDict
from uuid import uuid7
from datetime import datetime
from backend.internal.user_code_gen import generate_user_code
import uuid
from typing import TYPE_CHECKING
from sqlmodel import Relationship, SQLModel, Field
from sqlmodel import Field
from sqlmodel import Relationship
from sqlmodel import SQLModel
if TYPE_CHECKING:
from backend.models.comment import Comment
@ -14,7 +18,7 @@ class User(UserBase, table=True):
id: uuid.UUID = Field(default_factory=uuid.uuid7, primary_key=True)
email: str = Field(unique=True)
name: str = Field(unique=True)
user_code: str = Field(default_factory=generate_user_code, unique=True)
user_code: str = Field(default_factory=generate_user_code,unique=True)
subscription: bool = Field()
created_at: datetime = Field(default_factory=datetime.now)

View file

@ -1,4 +1,3 @@
from datetime import datetime
from mailtrap import Address
from backend.internal.mail_util import create_html_from_template
from mailtrap import BatchEmailRequest
@ -30,21 +29,17 @@ def approve_newsletter(secret: str = Form(), session: Session = Depends(get_sess
if title is not None:
article = find_article_by_title(title)
if article is not None:
date_object = datetime.strptime(str(article["pubDate"]), '%a, %d %b %Y %H:%M:%S %Z')
article_data = {
"title": article["title"],
"subtitle": article["subtitle"],
"description": article["summary"],
"link": article["link"],
"author": article["author"],
"time2read": article["time2read"],
"date": date_object.strftime('%d.%m.%y'),
}
subscribed_users = session.exec(select(User).where(User.subscription == True))
mails: list[BatchEmailRequest] = []
for user in subscribed_users:
html = create_html_from_template("newsletter", {"user": user, "article": article_data })
mail = BatchEmailRequest(to=[Address(email=user.email,name=user.name)], html=html)
mail = BatchEmailRequest(to=[Address(email=user.email,name=user.name)],html=html)
mails.append(mail)
send_batch_mail(mails)

View file

@ -37,7 +37,7 @@ router = APIRouter(
)
def register_user(new_user: NewUser, session: Session = Depends(get_session)):
user = User.model_validate(new_user)
if (user.name == ''):
raise HTTPException(HTTP_406_NOT_ACCEPTABLE, "Nutzername muss einen Wert enthalten")
elif(not validators.email(user.email)):

View file

@ -1,6 +1,6 @@
import { useState } from "preact/hooks";
import { api } from "../lib/api";
import { navigateBackAndReload, logout } from "./Util";
import { handleBackAndReload, logout } from "./Util";
import type { JSX } from "preact/jsx-runtime";
export default function DeleteUser() {
@ -20,7 +20,7 @@ export default function DeleteUser() {
} finally {
if (!hasError) {
logout()
navigateBackAndReload()
handleBackAndReload()
}
}
};

View file

@ -1,6 +1,6 @@
import { useEffect, useState } from 'preact/hooks';
import { api, AUTH_TOKEN_KEY } from '../lib/api';
import { getUser, navigateBackAndReload, navigatePathAndReload, saveUser } from './Util';
import { handleBackAndReload, saveUser } from './Util';
export default function LoginForm() {
const [userCode, setUserCode] = useState('');
@ -33,7 +33,7 @@ export default function LoginForm() {
}
hasError = true
} finally {
if (!hasError) navigateBackAndReload()
if (!hasError) handleBackAndReload()
}
}
};

View file

@ -1,8 +1,8 @@
import { navigateBackAndReload } from "./Util";
import { handleBackAndReload } from "./Util";
export default function NavBack() {
return (
<button class="back-btn" onClick={navigateBackAndReload}>Zurück</button>
<button class="back-btn" onClick={handleBackAndReload}>Zurück</button>
);
}

View file

@ -1,7 +1,7 @@
import { useEffect, useState } from 'preact/hooks';
import { api, type User } from '../lib/api';
import React from 'preact/compat';
import { navigateBackAndReload, isEmailValid } from './Util';
import { handleBackAndReload, isEmailValid } from './Util';
export default function RegisterForm() {
const [user, setUser] = React.useState<User>({ 'email': '', 'name': '', 'subscription': true });
@ -31,7 +31,7 @@ export default function RegisterForm() {
}
hasError = true
} finally {
if (!hasError) navigateBackAndReload()
if (!hasError) handleBackAndReload()
}
};

View file

@ -1,7 +1,7 @@
import { useEffect, useState } from 'preact/hooks';
import { api, type User } from '../lib/api';
import React from 'preact/compat';
import { getUser, navigatePathAndReload, saveUser } from './Util';
import { getUser, saveUser } from './Util';
export default function ToggleSubscription() {
const [subscription, setSubscription] = React.useState<boolean>(false);
@ -10,7 +10,7 @@ export default function ToggleSubscription() {
useEffect(() => {
user = getUser()
if (!user) navigatePathAndReload("/login")
if (!user) navigation.back()
else setSubscription(user.subscription)
}, []);
@ -23,6 +23,7 @@ export default function ToggleSubscription() {
} catch (err) {
setError(err instanceof Error ? err.message : 'Update fehlgeschlagen');
hasError = true
console.log(hasError);
} finally {
if (!hasError) {
if (user) {

View file

@ -42,16 +42,11 @@ export function isTokenExpired(token: string): boolean {
}
}
export const navigateBackAndReload = () => {
export const handleBackAndReload = () => {
if (document.referrer) {
navigate(document.referrer, { history: 'replace' });
setTimeout(() => window.location.reload(), 50);
} else {
navigate('/');
}
};
export const navigatePathAndReload = (path: string) => {
navigate(path, { history: 'replace' });
setTimeout(() => window.location.reload(), 50);
}
};

View file

@ -1,11 +1,10 @@
import rss from '@astrojs/rss';
import { formatLocalizedDateString } from '../lib/formatDate';
import rss, { pagesGlobToRssItems } from '@astrojs/rss';
export async function GET(context) {
const posts = Object.values(
import.meta.glob("./blog/*.{md,mdx}", { eager: true })
);
);
return rss({
title: 'Blauwasser Mausis | Blog',
@ -13,18 +12,16 @@ export async function GET(context) {
site: context.site,
items: posts.map(post => ({
title: post.frontmatter.title,
pubDate: post.frontmatter.date,
pubDate: Date.parse(post.frontmatter.date),
description: post.frontmatter.description,
link: `/blog/${post.frontmatter.slug}`,
author: post.frontmatter.author,
customData: `
customData: `
<subtitle>
<![CDATA[${post.frontmatter.subtitle}]]>
</subtitle>
<time2read>
<![CDATA[${post.frontmatter.time2read}]]>
</time2read>
`,
})),
customData: `<language>de-de</language>`,