mirror of
https://github.com/GSA/notifications-api.git
synced 2026-02-04 18:31:13 -05:00
initial
This commit is contained in:
@@ -2,6 +2,7 @@ import os
|
|||||||
import re
|
import re
|
||||||
from time import monotonic
|
from time import monotonic
|
||||||
|
|
||||||
|
from app.utils import hilite
|
||||||
import botocore
|
import botocore
|
||||||
import phonenumbers
|
import phonenumbers
|
||||||
from boto3 import client
|
from boto3 import client
|
||||||
@@ -48,7 +49,7 @@ class AwsSnsClient(SmsClient):
|
|||||||
|
|
||||||
def send_sms(self, to, content, reference, sender=None, international=False):
|
def send_sms(self, to, content, reference, sender=None, international=False):
|
||||||
matched = False
|
matched = False
|
||||||
|
print(hilite(f"TO {to}"))
|
||||||
for match in phonenumbers.PhoneNumberMatcher(to, "US"):
|
for match in phonenumbers.PhoneNumberMatcher(to, "US"):
|
||||||
matched = True
|
matched = True
|
||||||
to = phonenumbers.format_number(
|
to = phonenumbers.format_number(
|
||||||
|
|||||||
@@ -80,21 +80,36 @@ def send_sms_to_provider(notification):
|
|||||||
|
|
||||||
# We start by trying to get the phone number from a job in s3. If we fail, we assume
|
# We start by trying to get the phone number from a job in s3. If we fail, we assume
|
||||||
# the phone number is for the verification code on login, which is not a job.
|
# the phone number is for the verification code on login, which is not a job.
|
||||||
|
print(f"IN THE TRY AND JOB_ID is {notification.job_id}")
|
||||||
recipient = None
|
recipient = None
|
||||||
try:
|
# It is our 2facode, maybe
|
||||||
recipient = get_phone_number_from_s3(
|
if notification.job_id is None:
|
||||||
notification.service_id,
|
print(f"IN THE IF AND WE ARE GOING TO GET THE 2FA KEY")
|
||||||
notification.job_id,
|
|
||||||
notification.job_row_number,
|
|
||||||
)
|
|
||||||
except Exception:
|
|
||||||
# It is our 2facode, maybe
|
|
||||||
key = f"2facode-{notification.id}".replace(" ", "")
|
key = f"2facode-{notification.id}".replace(" ", "")
|
||||||
|
print(hilite(f"KEY IS SEND_TO_PROVIDERS IS {key}"))
|
||||||
recipient = redis_store.get(key)
|
recipient = redis_store.get(key)
|
||||||
|
|
||||||
if recipient:
|
if recipient:
|
||||||
recipient = recipient.decode("utf-8")
|
recipient = recipient.decode("utf-8")
|
||||||
|
|
||||||
|
print(hilite(f"RECIPIENT IN SEND TO PROVIDERS IS {recipient}"))
|
||||||
|
else:
|
||||||
|
print(f"IN THE ELSE AND WE ARE GOING TO GET FROM S3")
|
||||||
|
try:
|
||||||
|
recipient = get_phone_number_from_s3(
|
||||||
|
notification.service_id,
|
||||||
|
notification.job_id,
|
||||||
|
notification.job_row_number,
|
||||||
|
)
|
||||||
|
except Exception:
|
||||||
|
# It is our 2facode, maybe
|
||||||
|
key = f"2facode-{notification.id}".replace(" ", "")
|
||||||
|
print(hilite(f"KEY IS SEND_TO_PROVIDERS IS {key}"))
|
||||||
|
recipient = redis_store.get(key)
|
||||||
|
print(hilite(f"RECIPIENT IN SEND TO PROVIDERS IS {recipient}"))
|
||||||
|
|
||||||
|
if recipient:
|
||||||
|
recipient = recipient.decode("utf-8")
|
||||||
|
|
||||||
if recipient is None:
|
if recipient is None:
|
||||||
si = notification.service_id
|
si = notification.service_id
|
||||||
ji = notification.job_id
|
ji = notification.job_id
|
||||||
|
|||||||
@@ -53,7 +53,7 @@ from app.user.users_schema import (
|
|||||||
post_verify_code_schema,
|
post_verify_code_schema,
|
||||||
post_verify_webauthn_schema,
|
post_verify_webauthn_schema,
|
||||||
)
|
)
|
||||||
from app.utils import url_with_token, utc_now
|
from app.utils import hilite, url_with_token, utc_now
|
||||||
from notifications_utils.recipients import is_us_phone_number, use_numeric_sender
|
from notifications_utils.recipients import is_us_phone_number, use_numeric_sender
|
||||||
|
|
||||||
user_blueprint = Blueprint("user", __name__)
|
user_blueprint = Blueprint("user", __name__)
|
||||||
@@ -307,8 +307,9 @@ def send_user_2fa_code(user_id, code_type):
|
|||||||
|
|
||||||
|
|
||||||
def send_user_sms_code(user_to_send_to, data):
|
def send_user_sms_code(user_to_send_to, data):
|
||||||
|
print(hilite("SEND_USER_SMS_CODE"))
|
||||||
recipient = data.get("to") or user_to_send_to.mobile_number
|
recipient = data.get("to") or user_to_send_to.mobile_number
|
||||||
|
print(hilite(f"RECIPIENT {recipient}"))
|
||||||
secret_code = create_secret_code()
|
secret_code = create_secret_code()
|
||||||
personalisation = {"verify_code": secret_code}
|
personalisation = {"verify_code": secret_code}
|
||||||
|
|
||||||
@@ -372,6 +373,7 @@ def create_2fa_code(
|
|||||||
key = f"2facode-{saved_notification.id}".replace(" ", "")
|
key = f"2facode-{saved_notification.id}".replace(" ", "")
|
||||||
recipient = str(recipient)
|
recipient = str(recipient)
|
||||||
redis_store.set(key, recipient, ex=60 * 60)
|
redis_store.set(key, recipient, ex=60 * 60)
|
||||||
|
print(hilite(f"SET REDIS 2facode-{saved_notification.id} to {recipient}"))
|
||||||
|
|
||||||
# Assume that we never want to observe the Notify service's research mode
|
# Assume that we never want to observe the Notify service's research mode
|
||||||
# setting for this notification - we still need to be able to log into the
|
# setting for this notification - we still need to be able to log into the
|
||||||
|
|||||||
Reference in New Issue
Block a user