Skip to content

Commit

Permalink
email: Fix user welcome.
Browse files Browse the repository at this point in the history
* Closes #684.

Co-Authored-by: Peter Weber <[email protected]>
  • Loading branch information
rerowep and rerowep committed Dec 2, 2021
1 parent 3f161bf commit 20a07e8
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 11 deletions.
4 changes: 3 additions & 1 deletion scripts/test
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@ fi
safety check -i 42194 -i 40459 -i 42050&& \
pydocstyle sonar tests docs && \
isort --check-only --diff "${SCRIPT_PATH}/.." && \
autoflake -rc --remove-all-unused-imports --ignore-init-module-imports . && \
autoflake -c -r --remove-all-unused-imports --ignore-init-module-imports . &> /dev/null || {
autoflake --remove-all-unused-imports -r --ignore-init-module-imports .
} && \
sphinx-build -qnNW docs docs/_build/html && \
pytest
2 changes: 1 addition & 1 deletion sonar/modules/users/templates/users/email/welcome/en.html
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<p>Dear {{ user.first_name }},</p>
<p>An account has been created for you on SONAR, the Insitutional repository of {{ user.organisation.name }}.</p>
<p>An account has been created for you on {{ platform_name }}.</p>
<p>To access it, please <a href="{{ reset_link.replace('/api', '') }}">reset your password.</a></p>
<p>Your login e-mail: {{ user.email }}</p>
{% if user.is_submitter %}
Expand Down
34 changes: 25 additions & 9 deletions sonar/modules/users/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@

"""Utils functions for user module."""

import markdown
from bs4 import BeautifulSoup
from flask_babelex import _
from flask_security import url_for_security
from flask_security.recoverable import generate_reset_password_token
Expand All @@ -31,14 +33,28 @@ def send_welcome_email(user_record, user):
:param user: User account.
"""
user_record = user_record.replace_refs()
code = user_record['organisation'].get('code', '')
plain_platform_name = 'SONAR'
platform_name = user_record['organisation'].get('platformName')
if platform_name:
html = markdown.markdown(platform_name)
plain_platform_name = ''.join(
BeautifulSoup(html).findAll(text=True)).replace('\n', ' - ')

token = generate_reset_password_token(user)
reset_link = url_for_security('reset_password',
token=token,
_external=True)

send_email([user_record['email']], _('Welcome to SONAR'),
'users/email/welcome', {
'user': user_record,
'reset_link': reset_link
})
reset_link = url_for_security(
'reset_password',
token=token,
next=f'/{code}',
_external=True
)

send_email(
[user_record['email']],
f'{_("Welcome to")} {plain_platform_name}',
'users/email/welcome', {
'user': user_record,
'reset_link': reset_link,
'platform_name': plain_platform_name
}
)

0 comments on commit 20a07e8

Please sign in to comment.