Projects update 2020-12-31

* Added German translation for mails
* Streamlined mail class with other class names
projects Release-V2-RC1
Domeniko Gentner 3 years ago
parent 01d20f4641
commit 313e98d920
  1. 4
      labertasche/blueprints/bp_comments/__init__.py
  2. 23
      labertasche/mail/__init__.py
  3. 40
      templates/mail/comment_confirmation_de-DE.html
  4. 16
      templates/mail/comment_confirmation_de-DE_txt.html
  5. 4
      templates/mail/comment_confirmation_en-US.html
  6. 16
      templates/mail/comment_confirmation_en-US_txt.html

@ -14,7 +14,7 @@ from flask_cors import cross_origin
from sqlalchemy import exc from sqlalchemy import exc
from labertasche.database import labertasche_db as db from labertasche.database import labertasche_db as db
from labertasche.helper import is_valid_json, default_timestamp, check_gravatar, export_location from labertasche.helper import is_valid_json, default_timestamp, check_gravatar, export_location
from labertasche.mail import mail from labertasche.mail import Mail
from labertasche.models import TComments, TLocation, TEmail, TProjects from labertasche.models import TComments, TLocation, TEmail, TProjects
from labertasche.settings import Smileys from labertasche.settings import Smileys
from secrets import compare_digest from secrets import compare_digest
@ -39,7 +39,7 @@ def check_and_insert_new_comment(name):
if compare_digest(request.method, "POST"): if compare_digest(request.method, "POST"):
smileys = Smileys() smileys = Smileys()
sender = mail() sender = Mail()
# Check length of content and abort if too long or too short # Check length of content and abort if too long or too short
if request.content_length > 2048: if request.content_length > 2048:

@ -18,10 +18,11 @@ from secrets import token_urlsafe
from labertasche.models import TProjects from labertasche.models import TProjects
from labertasche.database import labertasche_db as db from labertasche.database import labertasche_db as db
from labertasche.settings import Settings from labertasche.settings import Settings
from flask import render_template from labertasche.language import Language
from flask import render_template, request
class mail: class Mail:
def __init__(self): def __init__(self):
path = Path("/etc/labertasche/mail_credentials.json") path = Path("/etc/labertasche/mail_credentials.json")
@ -76,6 +77,7 @@ class mail:
return None, None return None, None
settings = Settings() settings = Settings()
language = Language(request)
confirm_digest = token_urlsafe(48) confirm_digest = token_urlsafe(48)
delete_digest = token_urlsafe(48) delete_digest = token_urlsafe(48)
@ -83,11 +85,20 @@ class mail:
confirm_url = f"{settings.weburl}/comments/{project.name}/confirm/{confirm_digest}" confirm_url = f"{settings.weburl}/comments/{project.name}/confirm/{confirm_digest}"
delete_url = f"{settings.weburl}/comments/{project.name}/delete/{delete_digest}" delete_url = f"{settings.weburl}/comments/{project.name}/delete/{delete_digest}"
txt_what = f"Hey there. You have made a comment on {project.blogurl}. Please confirm it by " \ html_tpl = f"mail/comment_confirmation_{language.browser_language}.html"
f"copying this link into your browser:\n{confirm_url}\n" \ txt_tpl = f"mail/comment_confirmation_{language.browser_language}_txt.html"
f"If you want to delete your comment for whatever reason, please use this link:\n{delete_url}"
html_what = render_template("comment_confirmation.html", if not Path(f"./templates/{html_tpl}").exists():
html_tpl = f"mail/comment_confirmation_en-US.html"
if not Path(f"./templates/{txt_tpl}").exists():
html_tpl = f"mail/comment_confirmation_en-US_txt.html"
txt_what = render_template(txt_tpl,
blogurl=project.blogurl,
confirmation_url=confirm_url,
deletion_url=delete_url).replace('<pre>', "").replace('</pre>', '')
html_what = render_template(html_tpl,
blogurl=project.blogurl, blogurl=project.blogurl,
confirmation_url=confirm_url, confirmation_url=confirm_url,
deletion_url=delete_url) deletion_url=delete_url)

@ -0,0 +1,40 @@
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" lang="{{ i18n['html_language'] }}">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Dein Kommentar auf {{ blogurl }}</title>
</head>
<body style="background-color: #393f4d;color:white;width:70%;margin:0 auto;">
<table border="0" cellpadding="0" cellspacing="0" width='100%'>
<tr>
<td style="background-color:#feda6a;font-size:1.3em;color:black;padding:2%;">
<h1>Dein Kommentar auf {{ blogurl }}</h1>
</td>
</tr>
<tr>
<td>
<p style="font-size: 1.2em;line-height: 1.3em;padding-left:2%;">
Hallo, <br><br>
Du erhältst diese Email, weil du soeben einen Kommentar auf {{ blogurl }} hinterlassen hast.
<br><br>
Wenn du deinen Kommentar veröffentlichen willst, klicke bitte auf diesen <a style="color:#feda6a;" href="{{ confirmation_url }}">Link</a>.
<br>
Wenn du deinen Kommentar löschen willst, klicke bitte auf diesen <a style="color:#feda6a;" href="{{ deletion_url }}">Link</a>.
<br><br>
Wenn du glaubst, dass dies ein Fehler war oder jemand deine Email Adresse ohnen deinen Wissen verwendet hat, kontaktiere bitte
den Administrator von {{ blogurl }}.
</p>
</td>
</tr>
<tr>
<td style="border-top: 1px dashed #feda6a;padding-left:2%;">
<p style="font-size: 0.8em">
Powered by <a style="color:#feda6a;" href="https://labertasche.tuxstash.de">Labertasche</a>,
&nbsp;lizensiert via MIT license.
</p>
<td>
</tr>
</table>
</body>

@ -0,0 +1,16 @@
<pre>
Hallo,
Du erhältst diese Email, weil du soeben einen Kommentar auf {{ blogurl }} hinterlassen hast.
Wenn du deinen Kommentar veröffentlichen willst, kopiere bitte diesen Link in deinen Browser:
{{ confirmation_url }}
Wenn du deinen Kommentar löschen willst, kopiere bitte diesen Link in deinen Browser:
{{ deletion_url }}
Wenn du glaubst, dass dies ein Fehler war oder jemand deine Email Adresse ohnen deinen Wissen verwendet hat,
kontaktiere bitte den Administrator von {{ blogurl }}.
--------------------------------------------------------------------------------------------------------
Powered by Labertasche, lizensiert via MIT license: https://labertasche.tuxstash.de
</pre>

@ -17,13 +17,13 @@
<td> <td>
<p style="font-size: 1.2em;line-height: 1.3em;padding-left:2%;"> <p style="font-size: 1.2em;line-height: 1.3em;padding-left:2%;">
Hey there, <br><br> Hey there, <br><br>
You are receiving this mail, because you have recently made a comment on {{ blogurl }}. You are receiving this Mail, because you have recently made a comment on {{ blogurl }}.
<br><br> <br><br>
If you wish to publish your comment, please click this <a style="color:#feda6a;" href="{{ confirmation_url }}">link</a>. If you wish to publish your comment, please click this <a style="color:#feda6a;" href="{{ confirmation_url }}">link</a>.
<br> <br>
If you wish to delete your comment, please click this <a style="color:#feda6a;" href="{{ deletion_url }}">link</a>. If you wish to delete your comment, please click this <a style="color:#feda6a;" href="{{ deletion_url }}">link</a>.
<br><br> <br><br>
If this was in error or if someone used your mail address without your knowledge, please contact the site If this was in error or if someone used your Mail address without your knowledge, please contact the site
adminitrator at {{ blogurl }}. adminitrator at {{ blogurl }}.
</p> </p>
</td> </td>

@ -0,0 +1,16 @@
<pre>
Hey there,
You are receiving this Mail, because you have recently made a comment on {{ blogurl }}.
If you wish to publish your comment, please copy this into your browser:
{{ confirmation_url }}
If you wish to delete your comment, please copy this into your browser:
{{ deletion_url }}
If this was in error or if someone used your Mail address without your knowledge, please contact the site
adminitrator at {{ blogurl }}.
--------------------------------------------------------------------------------------------------------
Powered by Labertasche, licensed via MIT license: https://labertasche.tuxstash.de
</pre>
Loading…
Cancel
Save