forked from Github-Mirrors/canaille
Factorized the logo base64ification
This commit is contained in:
parent
f29fe7b575
commit
1795a54c0c
2 changed files with 31 additions and 11 deletions
|
@ -1,10 +1,8 @@
|
||||||
import base64
|
|
||||||
import email.message
|
import email.message
|
||||||
import hashlib
|
import hashlib
|
||||||
import pkg_resources
|
import pkg_resources
|
||||||
import logging
|
import logging
|
||||||
import smtplib
|
import smtplib
|
||||||
import urllib.request
|
|
||||||
|
|
||||||
from flask import (
|
from flask import (
|
||||||
Blueprint,
|
Blueprint,
|
||||||
|
@ -25,6 +23,7 @@ from .forms import (
|
||||||
PasswordResetForm,
|
PasswordResetForm,
|
||||||
ForgottenPasswordForm,
|
ForgottenPasswordForm,
|
||||||
)
|
)
|
||||||
|
from .apputils import base64logo
|
||||||
from .flaskutils import current_user, user_needed, moderator_needed
|
from .flaskutils import current_user, user_needed, moderator_needed
|
||||||
from .models import User
|
from .models import User
|
||||||
|
|
||||||
|
@ -227,15 +226,7 @@ def forgotten():
|
||||||
hash=profile_hash(user.uid[0], user.userPassword[0]),
|
hash=profile_hash(user.uid[0], user.userPassword[0]),
|
||||||
_external=True,
|
_external=True,
|
||||||
)
|
)
|
||||||
logo = None
|
logo, logo_extension = base64logo()
|
||||||
logo_extension = None
|
|
||||||
if current_app.config.get("LOGO"):
|
|
||||||
logo_extension = current_app.config["LOGO"].split(".")[-1]
|
|
||||||
try:
|
|
||||||
with urllib.request.urlopen(current_app.config.get("LOGO")) as f:
|
|
||||||
logo = base64.b64encode(f.read()).decode("utf-8")
|
|
||||||
except (urllib.error.HTTPError, urllib.error.URLError):
|
|
||||||
pass
|
|
||||||
|
|
||||||
subject = _("Password reset on {website_name}").format(
|
subject = _("Password reset on {website_name}").format(
|
||||||
website_name=current_app.config.get("NAME", reset_url)
|
website_name=current_app.config.get("NAME", reset_url)
|
||||||
|
|
29
canaille/apputils.py
Normal file
29
canaille/apputils.py
Normal file
|
@ -0,0 +1,29 @@
|
||||||
|
import base64
|
||||||
|
import urllib.request
|
||||||
|
from flask import current_app, request
|
||||||
|
|
||||||
|
|
||||||
|
def base64logo():
|
||||||
|
logo_url = current_app.config.get("LOGO")
|
||||||
|
if not logo_url:
|
||||||
|
return None, None
|
||||||
|
|
||||||
|
logo_extension = logo_url.split(".")[-1]
|
||||||
|
if not logo_url.startswith("http"):
|
||||||
|
if current_app.config.get("SERVER_NAME"):
|
||||||
|
logo_url = "{}://{}/{}".format(
|
||||||
|
current_app.config.get("PREFERRED_URL_SCHEME"),
|
||||||
|
current_app.config.get("SERVER_NAME"),
|
||||||
|
logo_url,
|
||||||
|
)
|
||||||
|
else:
|
||||||
|
logo_url = "{}{}".format(request.url_root, logo_url)
|
||||||
|
|
||||||
|
try:
|
||||||
|
with urllib.request.urlopen(logo_url) as f:
|
||||||
|
logo = base64.b64encode(f.read()).decode("utf-8")
|
||||||
|
except (urllib.error.HTTPError, urllib.error.URLError):
|
||||||
|
logo = None
|
||||||
|
logo_extension = None
|
||||||
|
|
||||||
|
return logo, logo_extension
|
Loading…
Reference in a new issue