mirror of
https://github.com/GSA/notifications-api.git
synced 2026-08-17 04:58:50 -04:00
Merge pull request #840 from GSA/notify-admin-1277
fix login.gov to use user uuid instead of email (notify-admin-1277)
This commit is contained in:
@@ -25,6 +25,32 @@ def create_secret_code(length=6):
|
||||
return "{:0{length}d}".format(random_number, length=length)
|
||||
|
||||
|
||||
def get_login_gov_user(login_uuid, email_address):
|
||||
"""
|
||||
We want to check to see if the user is registered with login.gov
|
||||
If we can find the login.gov uuid in our user table, then they are.
|
||||
|
||||
Also, because we originally keyed off email address we might have a few
|
||||
older users who registered with login.gov but we don't know what their
|
||||
login.gov uuids are. Eventually the code that checks by email address
|
||||
should be removed.
|
||||
"""
|
||||
|
||||
print(User.query.filter_by(login_uuid=login_uuid).first())
|
||||
user = User.query.filter_by(login_uuid=login_uuid).first()
|
||||
if user:
|
||||
if user.email_address != email_address:
|
||||
save_user_attribute(user, {"email_address": email_address})
|
||||
return user
|
||||
# Remove this 1 July 2025, all users should have login.gov uuids by now
|
||||
user = User.query.filter_by(email_address=email_address).first()
|
||||
if user:
|
||||
save_user_attribute(user, {"login_uuid": login_uuid})
|
||||
return user
|
||||
|
||||
return None
|
||||
|
||||
|
||||
def save_user_attribute(usr, update_dict=None):
|
||||
db.session.query(User).filter_by(id=usr.id).update(update_dict or {})
|
||||
db.session.commit()
|
||||
|
||||
@@ -109,6 +109,7 @@ class User(db.Model):
|
||||
id = db.Column(UUID(as_uuid=True), primary_key=True, default=uuid.uuid4)
|
||||
name = db.Column(db.String, nullable=False, index=True, unique=False)
|
||||
email_address = db.Column(db.String(255), nullable=False, index=True, unique=True)
|
||||
login_uuid = db.Column(db.Text, nullable=True, index=True, unique=True)
|
||||
created_at = db.Column(
|
||||
db.DateTime,
|
||||
index=False,
|
||||
|
||||
@@ -19,6 +19,7 @@ from app.dao.users_dao import (
|
||||
create_secret_code,
|
||||
create_user_code,
|
||||
dao_archive_user,
|
||||
get_login_gov_user,
|
||||
get_user_and_accounts,
|
||||
get_user_by_email,
|
||||
get_user_by_id,
|
||||
@@ -537,6 +538,16 @@ def set_permissions(user_id, service_id):
|
||||
return jsonify({}), 204
|
||||
|
||||
|
||||
@user_blueprint.route("/get-login-gov-user", methods=["POST"])
|
||||
def get_user_login_gov_user():
|
||||
request_args = request.get_json()
|
||||
login_uuid = request_args["login_uuid"]
|
||||
email = request_args["email"]
|
||||
user = get_login_gov_user(login_uuid, email)
|
||||
result = user.serialize()
|
||||
return jsonify(data=result)
|
||||
|
||||
|
||||
@user_blueprint.route("/email", methods=["POST"])
|
||||
def fetch_user_by_email():
|
||||
email = email_data_request_schema.load(request.get_json())
|
||||
|
||||
Reference in New Issue
Block a user