mirror of
https://github.com/GSA/notifications-api.git
synced 2025-12-21 07:51:13 -05:00
Use GOV.UK Notify service to send the forgot password email link using the template to create the message.
This commit is contained in:
@@ -217,11 +217,20 @@ def send_user_reset_password():
|
|||||||
|
|
||||||
user_to_send_to = get_user_by_email(email['email'])
|
user_to_send_to = get_user_by_email(email['email'])
|
||||||
|
|
||||||
reset_password_message = {'to': user_to_send_to.email_address,
|
template = dao_get_template_by_id(current_app.config['PASSWORD_RESET_TEMPLATE_ID'])
|
||||||
'name': user_to_send_to.name,
|
message = {
|
||||||
'reset_password_url': _create_reset_password_url(user_to_send_to.email_address)}
|
'template': str(template.id),
|
||||||
|
'template_version': template.version,
|
||||||
email_reset_password.apply_async([encryption.encrypt(reset_password_message)], queue='email-reset-password')
|
'to': user_to_send_to.email_address,
|
||||||
|
'personalisation': {
|
||||||
|
'user_name': user_to_send_to.name,
|
||||||
|
'url': _create_verification_url(user_to_send_to, _create_reset_password_url(user_to_send_to.email_address))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
send_email.apply_async([current_app.config['NOTIFY_SERVICE_ID'],
|
||||||
|
str(uuid.uuid4()),
|
||||||
|
encryption.encrypt(message),
|
||||||
|
datetime.utcnow().strftime(DATETIME_FORMAT)], queue='email-reset-password')
|
||||||
|
|
||||||
return jsonify({}), 204
|
return jsonify({}), 204
|
||||||
|
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
import json
|
import json
|
||||||
|
|
||||||
from flask import url_for
|
from flask import url_for, current_app
|
||||||
|
from freezegun import freeze_time
|
||||||
|
|
||||||
import app
|
import app
|
||||||
from app.models import (User, Permission, MANAGE_SETTINGS, MANAGE_TEMPLATES)
|
from app.models import (User, Permission, MANAGE_SETTINGS, MANAGE_TEMPLATES)
|
||||||
@@ -391,13 +392,15 @@ def test_set_user_permissions_remove_old(notify_api,
|
|||||||
assert query.first().permission == MANAGE_SETTINGS
|
assert query.first().permission == MANAGE_SETTINGS
|
||||||
|
|
||||||
|
|
||||||
|
@freeze_time("2016-01-01 11:09:00.061258")
|
||||||
def test_send_user_reset_password_should_send_reset_password_link(notify_api,
|
def test_send_user_reset_password_should_send_reset_password_link(notify_api,
|
||||||
sample_user,
|
sample_user,
|
||||||
mocker,
|
mocker,
|
||||||
mock_encryption):
|
mock_encryption):
|
||||||
with notify_api.test_request_context():
|
with notify_api.test_request_context():
|
||||||
with notify_api.test_client() as client:
|
with notify_api.test_client() as client:
|
||||||
mocker.patch('app.celery.tasks.email_reset_password.apply_async')
|
mocker.patch('uuid.uuid4', return_value='some_uuid') # for the notification id
|
||||||
|
mocker.patch('app.celery.tasks.send_email.apply_async')
|
||||||
data = json.dumps({'email': sample_user.email_address})
|
data = json.dumps({'email': sample_user.email_address})
|
||||||
auth_header = create_authorization_header()
|
auth_header = create_authorization_header()
|
||||||
resp = client.post(
|
resp = client.post(
|
||||||
@@ -406,8 +409,12 @@ def test_send_user_reset_password_should_send_reset_password_link(notify_api,
|
|||||||
headers=[('Content-Type', 'application/json'), auth_header])
|
headers=[('Content-Type', 'application/json'), auth_header])
|
||||||
|
|
||||||
assert resp.status_code == 204
|
assert resp.status_code == 204
|
||||||
app.celery.tasks.email_reset_password.apply_async.assert_called_once_with(['something_encrypted'],
|
app.celery.tasks.send_email.apply_async.assert_called_once_with(
|
||||||
queue='email-reset-password')
|
[str(current_app.config['NOTIFY_SERVICE_ID']),
|
||||||
|
'some_uuid',
|
||||||
|
"something_encrypted",
|
||||||
|
"2016-01-01T11:09:00.061258"],
|
||||||
|
queue="email-reset-password")
|
||||||
|
|
||||||
|
|
||||||
def test_send_user_reset_password_should_return_400_when_user_doesnot_exist(notify_api,
|
def test_send_user_reset_password_should_return_400_when_user_doesnot_exist(notify_api,
|
||||||
|
|||||||
Reference in New Issue
Block a user