Skip to content

Commit

Permalink
HDX-9424 sending username confirmation email
Browse files Browse the repository at this point in the history
  • Loading branch information
alexandru-m-g committed Feb 11, 2024
1 parent 840d88b commit 06cec22
Show file tree
Hide file tree
Showing 4 changed files with 39 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
CONSTANTS = {
'EMAIL_CONFIRMATION': '''Verify your email address to confirm your HDX account''',
'EMAIL_USERNAME_CONFIRMATION': '''Your new HDX account details'''
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
<p>Dear {{ data.user_fullname }},</p>
<p>Thank you for signing up to HDX.</p>
<p>Your HDX account username is: <em>{{ data.username }}</em></p>
<p>You can also use your email address to login.</p>
<a href="{{ data.login_link }}" target="_blank" title="Login to HDX" class="button">Login to HDX</a>
<p>Best wishes,</p>
<p>The HDX Team</p>
Original file line number Diff line number Diff line change
@@ -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
2 changes: 2 additions & 0 deletions ckanext-hdx_users/ckanext/hdx_users/views/onboarding.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 *

Expand Down Expand Up @@ -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)


Expand Down

0 comments on commit 06cec22

Please sign in to comment.