From 06cec223b76fe637faddc48df982579064eb0bc1 Mon Sep 17 00:00:00 2001 From: alexandru-m-g Date: Mon, 12 Feb 2024 00:18:42 +0200 Subject: [PATCH] HDX-9424 sending username confirmation email --- .../ui_constants/onboarding/email_subjects.py | 1 + .../email_username_confirmation.html | 7 +++++ .../onboarding_username_confirmation_logic.py | 29 +++++++++++++++++++ .../ckanext/hdx_users/views/onboarding.py | 2 ++ 4 files changed, 39 insertions(+) create mode 100644 ckanext-hdx_theme/ckanext/hdx_theme/templates/email/content/onboarding/email_username_confirmation.html create mode 100644 ckanext-hdx_users/ckanext/hdx_users/controller_logic/onboarding_username_confirmation_logic.py diff --git a/ckanext-hdx_theme/ckanext/hdx_theme/helpers/ui_constants/onboarding/email_subjects.py b/ckanext-hdx_theme/ckanext/hdx_theme/helpers/ui_constants/onboarding/email_subjects.py index e922245a4b..0ac2d600c2 100644 --- a/ckanext-hdx_theme/ckanext/hdx_theme/helpers/ui_constants/onboarding/email_subjects.py +++ b/ckanext-hdx_theme/ckanext/hdx_theme/helpers/ui_constants/onboarding/email_subjects.py @@ -1,3 +1,4 @@ CONSTANTS = { 'EMAIL_CONFIRMATION': '''Verify your email address to confirm your HDX account''', + 'EMAIL_USERNAME_CONFIRMATION': '''Your new HDX account details''' } diff --git a/ckanext-hdx_theme/ckanext/hdx_theme/templates/email/content/onboarding/email_username_confirmation.html b/ckanext-hdx_theme/ckanext/hdx_theme/templates/email/content/onboarding/email_username_confirmation.html new file mode 100644 index 0000000000..5fbf448ffc --- /dev/null +++ b/ckanext-hdx_theme/ckanext/hdx_theme/templates/email/content/onboarding/email_username_confirmation.html @@ -0,0 +1,7 @@ +

Dear {{ data.user_fullname }},

+

Thank you for signing up to HDX.

+

Your HDX account username is: {{ data.username }}

+

You can also use your email address to login.

+Login to HDX +

Best wishes,

+

The HDX Team

diff --git a/ckanext-hdx_users/ckanext/hdx_users/controller_logic/onboarding_username_confirmation_logic.py b/ckanext-hdx_users/ckanext/hdx_users/controller_logic/onboarding_username_confirmation_logic.py new file mode 100644 index 0000000000..d8bdc592e4 --- /dev/null +++ b/ckanext-hdx_users/ckanext/hdx_users/controller_logic/onboarding_username_confirmation_logic.py @@ -0,0 +1,29 @@ +import logging + +import ckan.plugins.toolkit as tk + +import ckanext.hdx_users.helpers.mailer as hdx_mailer + +from ckan.types import ActionResult + + +log = logging.getLogger(__name__) + +h = tk.h + +def send_username_confirmation_email(user_dict: ActionResult.UserShow) -> bool: + subject = h.HDX_CONST('UI_CONSTANTS')['ONBOARDING']['EMAIL_SUBJECTS']['EMAIL_USERNAME_CONFIRMATION'] + + email_data = { + 'user_fullname': user_dict.get('fullname'), + 'username': user_dict['name'], + 'login_link': h.url_for('hdx_user_auth.new_login') + } + try: + hdx_mailer.mail_recipient([{'email': user_dict['email']}], subject, email_data, footer=user_dict['email'], + snippet='email/content/onboarding/email_username_confirmation.html') + return True + except Exception as e: + error_summary = str(e) + log.error(error_summary) + return False diff --git a/ckanext-hdx_users/ckanext/hdx_users/views/onboarding.py b/ckanext-hdx_users/ckanext/hdx_users/views/onboarding.py index 5818eb68d9..3c0d381ac9 100644 --- a/ckanext-hdx_users/ckanext/hdx_users/views/onboarding.py +++ b/ckanext-hdx_users/ckanext/hdx_users/views/onboarding.py @@ -14,6 +14,7 @@ config, current_user ) from ckan.types import Context, Schema, Response, DataDict +from ckanext.hdx_users.controller_logic.onboarding_username_confirmation_logic import send_username_confirmation_email from ckanext.hdx_users.helpers.onboarding import HDX_ONBOARDING_CAME_FROM, HDX_ONBOARDING_CAME_FROM_STATE from ckanext.hdx_users.views.user_view_helper import * @@ -182,6 +183,7 @@ def validate_account(token: str) -> str: 'fullname': user_dict.get('fullname', ''), 'url': h.url_for('hdx_user_auth.new_login') } + send_username_confirmation_email(user_dict) return render('onboarding/signup/account-validated.html', extra_vars=template_data)