diff --git a/src/djangooidc/views.py b/src/djangooidc/views.py index 7b5c58527..bf5fe379e 100644 --- a/src/djangooidc/views.py +++ b/src/djangooidc/views.py @@ -101,25 +101,9 @@ def login_callback(request): user = authenticate(request=request, **userinfo) is_new_user = request.session.get("is_new_user", False) if user: - should_update_user = False - # Fixture users kind of exist in a superposition of verification types, - # because while the system "verified" them, if they login, - # we don't know how the user themselves was verified through login.gov until - # they actually try logging in. This edge-case only matters in non-production environments. - fixture_user = User.VerificationTypeChoices.FIXTURE_USER - is_fixture_user = user.verification_type and user.verification_type == fixture_user - - # Set the verification type if it doesn't already exist or if its a fixture user - if not user.verification_type or is_fixture_user: - user.set_user_verification_type() - should_update_user = True - - if is_new_user: - user.finished_setup = False - should_update_user = True - - if should_update_user: - user.save() + # Set login metadata about this user + # (verification_type for instance) + _set_authenticated_user_metadata(user, is_new_user) login(request, user) @@ -149,6 +133,30 @@ def login_callback(request): return error_page(request, err) +def _set_authenticated_user_metadata(user, is_new_user): + """Does checks on the recieved authenticated user from login_callback, + and updates fields accordingly. U""" + should_update_user = False + # Fixture users kind of exist in a superposition of verification types, + # because while the system "verified" them, if they login, + # we don't know how the user themselves was verified through login.gov until + # they actually try logging in. This edge-case only matters in non-production environments. + fixture_user = User.VerificationTypeChoices.FIXTURE_USER + is_fixture_user = user.verification_type and user.verification_type == fixture_user + + # Set the verification type if it doesn't already exist or if its a fixture user + if not user.verification_type or is_fixture_user: + user.set_user_verification_type() + should_update_user = True + + if is_new_user: + user.finished_setup = False + should_update_user = True + + if should_update_user: + user.save() + + def _requires_step_up_auth(userinfo): """if User.needs_identity_verification and step_up_acr_value not in ial returned from callback, return True""" diff --git a/src/registrar/views/contact.py b/src/registrar/views/contact.py index 322630b07..a0b99c4a0 100644 --- a/src/registrar/views/contact.py +++ b/src/registrar/views/contact.py @@ -2,6 +2,7 @@ from waffle.decorators import waffle_flag from urllib.parse import urlencode, urlunparse, urlparse, quote from django.urls import NoReverseMatch, reverse from registrar.forms.contact import ContactForm +from django.contrib.messages.views import SuccessMessageMixin from registrar.models.contact import Contact from registrar.templatetags.url_helpers import public_site_url from registrar.views.utility.permission_views import ContactPermissionView @@ -17,10 +18,13 @@ import logging logger = logging.getLogger(__name__) -class BaseContactView(ContactPermissionView): +class BaseContactView(SuccessMessageMixin, ContactPermissionView): """Provides a base view for the contact object. On get, the contact is saved in the session and on self.object.""" + def get_success_message(self): + return "Contact updated successfully." + def get(self, request, *args, **kwargs): """Sets the current contact in cache, defines the current object as self.object then returns render_to_response""" @@ -108,6 +112,9 @@ class ContactProfileSetupView(ContactFormBaseView): COMPLETE_SETUP = "complete_setup" TO_SPECIFIC_PAGE = "domain_request" + def get_success_message(self): + return "Your profile has been successfully updated." + # TODO - refactor @waffle_flag("profile_feature") @method_decorator(csrf_protect)