Skip to content

Commit

Permalink
notification: improve password reset notifications
Browse files Browse the repository at this point in the history
* Improves reset instruction notification.
* Adds a custom template for reset notice notification.
* Closes rero#1387.

Co-Authored-by: Alicia Zangger <alicia.zangger@rero.ch>
  • Loading branch information
Alicia Zangger committed Jan 13, 2021
1 parent c6342df commit e446e95
Show file tree
Hide file tree
Showing 8 changed files with 85 additions and 6 deletions.
3 changes: 3 additions & 0 deletions rero_ils/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -214,6 +214,9 @@ def _(x):
SECURITY_EMAIL_SENDER = SUPPORT_EMAIL
#: Email subject for account registration emails.
SECURITY_EMAIL_SUBJECT_REGISTER = _("Welcome to RERO-ILS!")
#: Email subjects for password reset
SECURITY_EMAIL_SUBJECT_PASSWORD_RESET = _('RERO ID password reset')
SECURITY_EMAIL_SUBJECT_PASSWORD_NOTICE = _('Your RERO ID password has been reset')
#: Redis session storage URL.
ACCOUNTS_SESSION_REDIS_URL = 'redis://localhost:6379/1'
#: Enable session/user id request tracing. This feature will add X-Session-ID
Expand Down
17 changes: 17 additions & 0 deletions rero_ils/filter.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@
from invenio_i18n.ext import current_i18n
from markupsafe import Markup

from .modules.patrons.api import Patron


def node_assets(package, patterns=[
'runtime*.js', 'polyfills*.js', 'main*.js'], _type='js', tags=''):
Expand Down Expand Up @@ -134,3 +136,18 @@ def empty_data(data, replacement_string='No data'):
else:
msg = '<em class="no-data">{0}</em>'.format(replacement_string)
return Markup(msg)


def lib_url(user):
"""Return organisation viewcode.
:param user - invenio user to get viewcode
"""
viewcode = current_app.config.get('RERO_ILS_SEARCH_GLOBAL_VIEW_CODE')
patron = Patron.get_patron_by_user(user)
if patron is not None:
viewcode = patron.get_organisation().get('code')
return '{base_url}/{viewcode}'.format(
base_url=current_app.config.get('RERO_ILS_APP_URL'),
viewcode=viewcode
)
7 changes: 4 additions & 3 deletions rero_ils/modules/ext.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,8 @@
from .patron_transactions.listener import enrich_patron_transaction_data
from .patrons.listener import create_subscription_patron_transaction, \
enrich_patron_data, update_from_profile
from ..filter import empty_data, format_date_filter, jsondumps, node_assets, \
text_to_id, to_pretty_json
from ..filter import empty_data, format_date_filter, jsondumps, lib_url, \
node_assets, text_to_id, to_pretty_json


class REROILSAPP(object):
Expand All @@ -63,7 +63,7 @@ def __init__(self, app=None):
# it is require for Flask-Security see:
# https://pythonhosted.org/Flask-Security/customizing.html#emails
ils_loader = jinja2.ChoiceLoader([
jinja2.PackageLoader('rero_ils', 'templates'),
jinja2.PackageLoader('rero_ils', 'theme/templates'),
app.jinja_loader
])
app.jinja_loader = ils_loader
Expand All @@ -75,6 +75,7 @@ def __init__(self, app=None):
app.add_template_filter(text_to_id, name='text_to_id')
app.add_template_filter(jsondumps, name='jsondumps')
app.add_template_filter(empty_data, name='empty_data')
app.add_template_filter(lib_url, name='lib_url')
app.jinja_env.add_extension('jinja2.ext.do')
self.register_signals(app)

Expand Down
12 changes: 11 additions & 1 deletion rero_ils/theme/templates/security/email/reset_instructions.html
Original file line number Diff line number Diff line change
Expand Up @@ -18,4 +18,14 @@

#}

<p><a href="{{ reset_link.replace('/api', '') }}">{{ _('Click here to reset your password') }}</a></p>
{%- if user.profile.first_name and user.profile.last_name %}
<p>{{ _('Dear') }} {{ user.profile.first_name }} {{ user.profile.last_name }},</p>
{%- else %}
<p>{{ _('Dear patron') }},</p>
{%- endif %}
<p>{{ _('Someone requested that the password for your RERO ID account be reset.') }}</p>
<p><a href="{{ reset_link.replace('/api', '') }}">{{ _('Reset my password') }}</a></p>
<p>{{ _("If you didn't request this, you can ignore this e-mail. Your password won't change until you create a new password.") }}</p>
<p>{{ _('Best regards') }}</p>
<p>{{ _('Your library') }}</p>
<p>{{ user | lib_url }}</p>
13 changes: 11 additions & 2 deletions rero_ils/theme/templates/security/email/reset_instructions.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,12 @@
{{ _('Click the link below to reset your password:') }}

{{ reset_link.replace('/api', '') }}
{%- if user.profile.first_name and user.profile.last_name %}
<p>{{ _('Dear') }} {{ user.profile.first_name }} {{ user.profile.last_name }},</p>
{%- else %}
<p>{{ _('Dear patron') }},</p>
{%- endif %}
<p>{{ _('Someone requested that the password for your RERO ID account be reset.') }}</p>
<p><a href="{{ reset_link.replace('/api', '') }}">{{ _('Reset my password') }}</a></p>
<p>{{ _("If you didn't request this, you can ignore this e-mail. Your password won't change until you create a new password.") }}</p>
<p>{{ _('Best regards') }}</p>
<p>{{ _('Your library') }}</p>
<p>{{ user | lib_url }}</p>
29 changes: 29 additions & 0 deletions rero_ils/theme/templates/security/email/reset_notice.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
{# -*- coding: utf-8 -*-

RERO ILS
Copyright (C) 2021 RERO
Copyright (C) 2015-2018 CERN

This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as published by
the Free Software Foundation, version 3 of the License.

This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Affero General Public License for more details.

You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.

#}

{%- if user.profile.first_name and user.profile.last_name %}
<p>{{ _('Dear') }} {{ user.profile.first_name }} {{ user.profile.last_name }},</p>
{%- else %}
<p>{{ _('Dear patron') }},</p>
{%- endif %}
<p>{{ _('Your password has been successfully reset.') }}</p>
<p>{{ _('Best regards') }}</p>
<p>{{ _('Your library') }}</p>
<p>{{ user | lib_url }}</p>
9 changes: 9 additions & 0 deletions rero_ils/theme/templates/security/email/reset_notice.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{%- if user.profile.first_name and user.profile.last_name %}
<p>{{ _('Dear') }} {{ user.profile.first_name }} {{ user.profile.last_name }},</p>
{%- else %}
<p>{{ _('Dear patron') }},</p>
{%- endif %}
<p>{{ _('Your password has been successfully reset.') }}</p>
<p>{{ _('Best regards') }}</p>
<p>{{ _('Your library') }}</p>
<p>{{ user | lib_url }}</p>
1 change: 1 addition & 0 deletions tests/ui/patrons/test_patrons_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,7 @@ def test_patron_create(app, roles, lib_martigny, librarian_martigny_data_tmp,
ptrn = Patron.create(
librarian_martigny_data_tmp,
dbcommit=True,
reindex=True,
delete_pid=False
)
user = User.query.filter_by(id=ptrn.get('user_id')).first()
Expand Down

0 comments on commit e446e95

Please sign in to comment.