mirror of
https://github.com/spiral-project/ihatemoney.git
synced 2025-05-05 20:51:49 +02:00
Change default email address, refactored email error messages into a helper function
This commit is contained in:
parent
75a1640c37
commit
d8d1f94c95
10 changed files with 44 additions and 41 deletions
|
@ -14,7 +14,7 @@ ENV DEBUG="False" \
|
||||||
ALLOW_PUBLIC_PROJECT_CREATION="True" \
|
ALLOW_PUBLIC_PROJECT_CREATION="True" \
|
||||||
BABEL_DEFAULT_TIMEZONE="UTC" \
|
BABEL_DEFAULT_TIMEZONE="UTC" \
|
||||||
GREENLET_TEST_CPP="no" \
|
GREENLET_TEST_CPP="no" \
|
||||||
MAIL_DEFAULT_SENDER="('Budget manager', 'budget@notmyidea.org')" \
|
MAIL_DEFAULT_SENDER="('Budget manager', 'admin@email.com')" \
|
||||||
MAIL_PASSWORD="" \
|
MAIL_PASSWORD="" \
|
||||||
MAIL_PORT="25" \
|
MAIL_PORT="25" \
|
||||||
MAIL_SERVER="localhost" \
|
MAIL_SERVER="localhost" \
|
||||||
|
|
|
@ -13,7 +13,7 @@ services:
|
||||||
- ALLOW_PUBLIC_PROJECT_CREATION=True
|
- ALLOW_PUBLIC_PROJECT_CREATION=True
|
||||||
- BABEL_DEFAULT_TIMEZONE=UTC
|
- BABEL_DEFAULT_TIMEZONE=UTC
|
||||||
- GREENLET_TEST_CPP=no
|
- GREENLET_TEST_CPP=no
|
||||||
- MAIL_DEFAULT_SENDER=('Budget manager', 'budget@notmyidea.org')
|
- MAIL_DEFAULT_SENDER=('Budget manager', 'admin@email.com')
|
||||||
- MAIL_PASSWORD=
|
- MAIL_PASSWORD=
|
||||||
- MAIL_PORT=25
|
- MAIL_PORT=25
|
||||||
- MAIL_SERVER=localhost
|
- MAIL_SERVER=localhost
|
||||||
|
|
|
@ -79,7 +79,7 @@ for details.
|
||||||
A python tuple describing the name and email address to use when sending
|
A python tuple describing the name and email address to use when sending
|
||||||
emails.
|
emails.
|
||||||
|
|
||||||
- **Default value:** `("Budget manager", "budget@notmyidea.org")`
|
- **Default value:** `("Budget manager", "admin@email.com")`
|
||||||
- **Production value:** Any tuple you want.
|
- **Production value:** Any tuple you want.
|
||||||
|
|
||||||
## ACTIVATE_DEMO_PROJECT
|
## ACTIVATE_DEMO_PROJECT
|
||||||
|
|
|
@ -19,7 +19,7 @@ SQLALCHEMY_TRACK_MODIFICATIONS = False
|
||||||
SECRET_KEY = "{{ secret_key }}"
|
SECRET_KEY = "{{ secret_key }}"
|
||||||
|
|
||||||
# A python tuple describing the name and email adress of the sender of the mails.
|
# A python tuple describing the name and email adress of the sender of the mails.
|
||||||
MAIL_DEFAULT_SENDER = ("Budget manager", "budget@notmyidea.org") # CUSTOMIZE
|
MAIL_DEFAULT_SENDER = ("Budget manager", "admin@email.com") # CUSTOMIZE
|
||||||
|
|
||||||
# If set to True, a demonstration project will be activated.
|
# If set to True, a demonstration project will be activated.
|
||||||
ACTIVATE_DEMO_PROJECT = True
|
ACTIVATE_DEMO_PROJECT = True
|
||||||
|
|
|
@ -3,7 +3,7 @@ DEBUG = SQLACHEMY_ECHO = False
|
||||||
SQLALCHEMY_DATABASE_URI = "sqlite:////tmp/ihatemoney.db"
|
SQLALCHEMY_DATABASE_URI = "sqlite:////tmp/ihatemoney.db"
|
||||||
SQLALCHEMY_TRACK_MODIFICATIONS = False
|
SQLALCHEMY_TRACK_MODIFICATIONS = False
|
||||||
SECRET_KEY = "tralala"
|
SECRET_KEY = "tralala"
|
||||||
MAIL_DEFAULT_SENDER = ("Budget manager", "budget@notmyidea.org")
|
MAIL_DEFAULT_SENDER = ("Budget manager", "admin@email.com")
|
||||||
ACTIVATE_DEMO_PROJECT = True
|
ACTIVATE_DEMO_PROJECT = True
|
||||||
ADMIN_PASSWORD = ""
|
ADMIN_PASSWORD = ""
|
||||||
ALLOW_PUBLIC_PROJECT_CREATION = True
|
ALLOW_PUBLIC_PROJECT_CREATION = True
|
||||||
|
|
|
@ -6,4 +6,4 @@ SQLACHEMY_ECHO = DEBUG
|
||||||
|
|
||||||
SECRET_KEY = "supersecret"
|
SECRET_KEY = "supersecret"
|
||||||
|
|
||||||
MAIL_DEFAULT_SENDER = ("Budget manager", "budget@notmyidea.org")
|
MAIL_DEFAULT_SENDER = ("Budget manager", "admin@email.com")
|
||||||
|
|
|
@ -6,4 +6,4 @@ SQLACHEMY_ECHO = DEBUG
|
||||||
|
|
||||||
SECRET_KEY = "lalatra"
|
SECRET_KEY = "lalatra"
|
||||||
|
|
||||||
MAIL_DEFAULT_SENDER = ("Budget manager", "budget@notmyidea.org")
|
MAIL_DEFAULT_SENDER = ("Budget manager", "admin@email.com")
|
||||||
|
|
|
@ -26,7 +26,7 @@ class ConfigurationTestCase(BaseTestCase):
|
||||||
self.assertFalse(self.app.config["SQLALCHEMY_TRACK_MODIFICATIONS"])
|
self.assertFalse(self.app.config["SQLALCHEMY_TRACK_MODIFICATIONS"])
|
||||||
self.assertEqual(
|
self.assertEqual(
|
||||||
self.app.config["MAIL_DEFAULT_SENDER"],
|
self.app.config["MAIL_DEFAULT_SENDER"],
|
||||||
("Budget manager", "budget@notmyidea.org"),
|
("Budget manager", "admin@email.com"),
|
||||||
)
|
)
|
||||||
self.assertTrue(self.app.config["ACTIVATE_DEMO_PROJECT"])
|
self.assertTrue(self.app.config["ACTIVATE_DEMO_PROJECT"])
|
||||||
self.assertTrue(self.app.config["ALLOW_PUBLIC_PROJECT_CREATION"])
|
self.assertTrue(self.app.config["ALLOW_PUBLIC_PROJECT_CREATION"])
|
||||||
|
|
|
@ -12,7 +12,7 @@ import socket
|
||||||
|
|
||||||
from babel import Locale
|
from babel import Locale
|
||||||
from babel.numbers import get_currency_name, get_currency_symbol
|
from babel.numbers import get_currency_name, get_currency_symbol
|
||||||
from flask import current_app, escape, redirect, render_template
|
from flask import current_app, escape, flash, redirect, render_template
|
||||||
from flask_babel import get_locale, lazy_gettext as _
|
from flask_babel import get_locale, lazy_gettext as _
|
||||||
import jinja2
|
import jinja2
|
||||||
from markupsafe import Markup
|
from markupsafe import Markup
|
||||||
|
@ -47,6 +47,32 @@ def send_email(mail_message):
|
||||||
return True
|
return True
|
||||||
|
|
||||||
|
|
||||||
|
def flash_email_error(error_message, category="danger"):
|
||||||
|
"""Helper to flash a message for email errors. It will also show the
|
||||||
|
admin email as a contact if public project creation is allowed and
|
||||||
|
the MAIL_DEFAULT_SENDER is not the default value.
|
||||||
|
|
||||||
|
"""
|
||||||
|
admin_email = current_app.config.get("MAIL_DEFAULT_SENDER")
|
||||||
|
error_extension = "."
|
||||||
|
if (
|
||||||
|
admin_email
|
||||||
|
and admin_email[1] != "admin@email.com"
|
||||||
|
and current_app.config.get("ALLOW_PUBLIC_PROJECT_CREATION")
|
||||||
|
):
|
||||||
|
error_extension = " or contact the administrator at {}.".format(admin_email[1])
|
||||||
|
|
||||||
|
flash(
|
||||||
|
_(
|
||||||
|
error_message
|
||||||
|
+ " Please check the email configuration of the server {}".format(
|
||||||
|
error_extension
|
||||||
|
)
|
||||||
|
),
|
||||||
|
category=category,
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
class Redirect303(HTTPException, RoutingException):
|
class Redirect303(HTTPException, RoutingException):
|
||||||
|
|
||||||
"""Raise if the map requests a redirect. This is for example the case if
|
"""Raise if the map requests a redirect. This is for example the case if
|
||||||
|
|
|
@ -58,6 +58,7 @@ from ihatemoney.models import Bill, LoggingMode, Person, Project, db
|
||||||
from ihatemoney.utils import (
|
from ihatemoney.utils import (
|
||||||
LoginThrottler,
|
LoginThrottler,
|
||||||
Redirect303,
|
Redirect303,
|
||||||
|
flash_email_error,
|
||||||
format_form_errors,
|
format_form_errors,
|
||||||
get_members,
|
get_members,
|
||||||
list_of_dicts2csv,
|
list_of_dicts2csv,
|
||||||
|
@ -334,11 +335,9 @@ def create_project():
|
||||||
else:
|
else:
|
||||||
# Display the error as a simple "info" alert, because it's
|
# Display the error as a simple "info" alert, because it's
|
||||||
# not critical and doesn't prevent using the project.
|
# not critical and doesn't prevent using the project.
|
||||||
flash(
|
flash_email_error(
|
||||||
_(
|
|
||||||
"We tried to send you an reminder email, but there was an error. "
|
"We tried to send you an reminder email, but there was an error. "
|
||||||
"You can still use the project normally."
|
"You can still use the project normally.",
|
||||||
),
|
|
||||||
category="info",
|
category="info",
|
||||||
)
|
)
|
||||||
return redirect(url_for(".list_bills", project_id=project.id))
|
return redirect(url_for(".list_bills", project_id=project.id))
|
||||||
|
@ -363,26 +362,9 @@ def remind_password():
|
||||||
if success:
|
if success:
|
||||||
return redirect(url_for(".password_reminder_sent"))
|
return redirect(url_for(".password_reminder_sent"))
|
||||||
else:
|
else:
|
||||||
# Only display admin email if its not the default and public creation is allowed
|
flash_email_error(
|
||||||
admin_email = current_app.config.get("MAIL_DEFAULT_SENDER")
|
"Sorry, there was an error while sending you an email with "
|
||||||
error_extension = ""
|
"password reset instructions."
|
||||||
if (
|
|
||||||
admin_email
|
|
||||||
and admin_email[1] != "budget@notmyidea.org"
|
|
||||||
and current_app.config.get("ALLOW_PUBLIC_PROJECT_CREATION")
|
|
||||||
):
|
|
||||||
error_extension = "Contact the administrator at {}.".format(
|
|
||||||
admin_email[1]
|
|
||||||
)
|
|
||||||
|
|
||||||
flash(
|
|
||||||
_(
|
|
||||||
"Sorry, there was an error while sending you an email "
|
|
||||||
"with password reset instructions. "
|
|
||||||
"Please check the email configuration of the server "
|
|
||||||
"or contact the administrator. {}".format(error_extension)
|
|
||||||
),
|
|
||||||
category="danger",
|
|
||||||
)
|
)
|
||||||
# Fall-through: we stay on the same page and display the form again
|
# Fall-through: we stay on the same page and display the form again
|
||||||
return render_template("password_reminder.html", form=form)
|
return render_template("password_reminder.html", form=form)
|
||||||
|
@ -646,13 +628,8 @@ def invite():
|
||||||
flash(_("Your invitations have been sent"), category="success")
|
flash(_("Your invitations have been sent"), category="success")
|
||||||
return redirect(url_for(".list_bills"))
|
return redirect(url_for(".list_bills"))
|
||||||
else:
|
else:
|
||||||
flash(
|
flash_email_error(
|
||||||
_(
|
|
||||||
"Sorry, there was an error while trying to send the invitation emails."
|
"Sorry, there was an error while trying to send the invitation emails."
|
||||||
"Please check the email configuration of the server "
|
|
||||||
"or contact the administrator."
|
|
||||||
),
|
|
||||||
category="danger",
|
|
||||||
)
|
)
|
||||||
# Fall-through: we stay on the same page and display the form again
|
# Fall-through: we stay on the same page and display the form again
|
||||||
return render_template("send_invites.html", form=form)
|
return render_template("send_invites.html", form=form)
|
||||||
|
|
Loading…
Reference in a new issue