Merge pull request #411 from alphagov/use-notify-to-send-email-verification-links

Use notify to send email verification links
This commit is contained in:
Rebecca Law
2016-06-13 15:21:32 +01:00
committed by GitHub
8 changed files with 136 additions and 38 deletions

View File

@@ -180,16 +180,10 @@ def process_job(job_id):
)
if template.template_type == 'email':
from_email = '"{}" <{}@{}>'.format(
service.name,
service.email_from,
current_app.config['NOTIFY_EMAIL_DOMAIN']
)
send_email.apply_async((
str(job.service_id),
create_uuid(),
from_email.encode('ascii', 'ignore').decode('ascii'),
'',
encrypted,
datetime.utcnow().strftime(DATETIME_FORMAT)),
{'reply_to_addresses': service.reply_to_email_address},
@@ -343,6 +337,9 @@ def send_email(service_id, notification_id, from_address, encrypted_notification
(provider.get_name(), str(reference), notification['to']), queue='research-mode'
)
else:
# First step setting the from_address here rather than the method creating the task
from_address = '"{}" <{}@{}>'.format(service.name, service.email_from, current_app.config[
'NOTIFY_EMAIL_DOMAIN']) if from_address == "" else from_address
reference = provider.send_email(
from_address,
notification['to'],

View File

@@ -387,7 +387,7 @@ def send_notification(notification_type):
send_email.apply_async((
service_id,
notification_id,
'"{}" <{}@{}>'.format(service.name, service.email_from, current_app.config['NOTIFY_EMAIL_DOMAIN']),
'',
encryption.encrypt(notification),
datetime.utcnow().strftime(DATETIME_FORMAT)
), queue='email')

View File

@@ -28,8 +28,8 @@ from app.schemas import (
from app.celery.tasks import (
send_sms,
email_reset_password,
email_registration_verification
)
email_registration_verification,
send_email)
from app.errors import register_errors
@@ -157,13 +157,23 @@ def send_user_email_verification(user_id):
secret_code = create_secret_code()
create_user_code(user_to_send_to, secret_code, 'email')
email = user_to_send_to.email_address
verification_message = {'to': email,
'name': user_to_send_to.name,
'url': _create_verification_url(user_to_send_to, secret_code)}
email_registration_verification.apply_async([encryption.encrypt(verification_message)],
queue='email-registration-verification')
template = dao_get_template_by_id(current_app.config['EMAIL_VERIFY_CODE_TEMPLATE_ID'])
message = {
'template': str(template.id),
'template_version': template.version,
'to': user_to_send_to.email_address,
'personalisation': {
'name': user_to_send_to.name,
'url': _create_verification_url(user_to_send_to, secret_code)
}
}
send_email.apply_async((
current_app.config['NOTIFY_SERVICE_ID'],
str(uuid.uuid4()),
'',
encryption.encrypt(message),
datetime.utcnow().strftime(DATETIME_FORMAT)
), queue='email-registration-verification')
return jsonify({}), 204