Make sms code task use a reference too

- makes the fire text callback behave in consistent way
This commit is contained in:
Martyn Inglis
2016-03-10 15:51:11 +00:00
parent 1f22f2b7cc
commit 2922712f0b
5 changed files with 42 additions and 27 deletions

View File

@@ -295,7 +295,9 @@ def send_email(service_id, notification_id, subject, from_address, encrypted_not
def send_sms_code(encrypted_verification):
verification_message = encryption.decrypt(encrypted_verification)
try:
firetext_client.send_sms(verification_message['to'], verification_message['secret_code'])
firetext_client.send_sms(
verification_message['to'], verification_message['secret_code'], 'send-sms-code'
)
except FiretextClientException as e:
current_app.logger.exception(e)

View File

@@ -51,20 +51,16 @@ class FiretextClient(SmsClient):
def get_name(self):
return self.name
def send_sms(self, to, content, notification_id=None):
def send_sms(self, to, content, reference):
data = {
"apiKey": self.api_key,
"from": self.from_number,
"to": to.replace('+', ''),
"message": content
"message": content,
"reference": reference
}
if notification_id:
data.update({
"reference": notification_id
})
start_time = monotonic()
try:
response = request(

View File

@@ -45,19 +45,22 @@ def process_firetext_response():
current_app.logger.info(
"Firetext callback with no reference"
)
return jsonify(result="success", message="Firetext callback succeeded"), 200
return jsonify(result="error", message="Firetext callback failed: reference missing"), 400
notification_id = request.form['reference']
reference = request.form['reference']
status = request.form['status']
if reference == 'send-sms-code':
return jsonify(result="success", message="Firetext callback succeeded: send-sms-code"), 200
try:
uuid.UUID(notification_id, version=4)
uuid.UUID(reference, version=4)
except ValueError:
current_app.logger.info(
"Firetext callback with invalid reference {}".format(notification_id)
"Firetext callback with invalid reference {}".format(reference)
)
return jsonify(
result="error", message="Firetext callback with invalid reference {}".format(notification_id)
result="error", message="Firetext callback with invalid reference {}".format(reference)
), 400
notification_status = firetext_response_status.get(status, None)
@@ -67,15 +70,15 @@ def process_firetext_response():
)
return jsonify(result="error", message="Firetext callback failed: status {} not found.".format(status)), 400
notification = notifications_dao.get_notification_by_id(notification_id)
notification = notifications_dao.get_notification_by_id(reference)
if not notification:
current_app.logger.info(
"Firetext callback failed: notification {} not found. Status {}".format(notification_id, status)
"Firetext callback failed: notification {} not found. Status {}".format(reference, status)
)
return jsonify(
result="error",
message="Firetext callback failed: notification {} not found. Status {}".format(
notification_id,
reference,
notification_status['firetext_message']
)
), 404
@@ -83,14 +86,14 @@ def process_firetext_response():
if not notification_status['success']:
current_app.logger.info(
"Firetext delivery failed: notification {} has error found. Status {}".format(
notification_id,
reference,
firetext_response_status[status]['firetext_message']
)
)
notification.status = notification_status['notify_status']
notifications_dao.dao_update_notification(notification)
return jsonify(
result="success", message="Firetext callback succeeded. reference {} updated".format(notification_id)
result="success", message="Firetext callback succeeded. reference {} updated".format(reference)
), 200