Repository: cisagov/manage.get.gov

Issue:
Move first_login logic so that it occurs on all logins
### Issue description

Currently, we have a function (first_login in User.py) that is triggered when it is the users first time logging into our system. In this function, we are checking 1.) are they part of a transition domain, if so make sure there is a domain inviation for them and a domain information object, 2) for all domain invitations they have,  we add a user domain role to their account so they can access the domains.

The problem is when it comes time for transition, if anyone logs into our system BEFORE we run the migration scripts then they will already have a User row and account on our system and they will not trigger the checks above. This is a bit of a race condition that is easily avoided by just having the first_login logic triggered on every login.

### Acceptance criteria

- [ ] rename first_login and all uses of it  (as it is no longer used just at first login
- [ ] move the formerly named first_login to be called for all users. 
- [ ] add or update existing unit tests 

### Additional context

To accomplish the second AC above I suggest moving the highlight lint (user.first_login()) in the backend.py Authenticate function to right above the return on line 59 so it is called on each user. See picture below:
![image](https://github.com/cisagov/getgov/assets/109625347/39ca23f7-d547-4ce4-b32d-4f55e4aee4d9)


### Links to other issues

_No response_


Discussion:

Resolving patch:
diff --git a/src/djangooidc/backends.py b/src/djangooidc/backends.py
--- a/src/djangooidc/backends.py
+++ b/src/djangooidc/backends.py
@@ -49,13 +49,13 @@ def authenticate(self, request, **kwargs):
             user, created = UserModel.objects.update_or_create(**args)
             if created:
                 user = self.configure_user(user, **kwargs)
-                # run a newly created user's callback for a first-time login
-                user.first_login()
         else:
             try:
                 user = UserModel.objects.get_by_natural_key(username)
             except UserModel.DoesNotExist:
                 return None
+        # run this callback for a each login
+        user.on_each_login()
         return user
 
     def clean_username(self, username):
diff --git a/src/registrar/models/user.py b/src/registrar/models/user.py
--- a/src/registrar/models/user.py
+++ b/src/registrar/models/user.py
@@ -154,10 +154,10 @@ def check_transition_domains_on_login(self):
                 new_domain_info = DomainInformation(creator=self, domain=domain)
                 new_domain_info.save()
 
-    def first_login(self):
-        """Callback when the user is authenticated for the very first time.
+    def on_each_login(self):
+        """Callback each time the user is authenticated.
 
-        When a user first arrives on the site, we need to retrieve any domain
+        When a user arrives on the site each time, we need to retrieve any domain
         invitations that match their email address.
 
         We also need to check if they are logging in with the same e-mail


Test patch:
diff --git a/src/registrar/tests/test_models.py b/src/registrar/tests/test_models.py
--- a/src/registrar/tests/test_models.py
+++ b/src/registrar/tests/test_models.py
@@ -609,9 +609,9 @@ def test_retrieve_existing_role_no_error(self):
             self.invitation.retrieve()
         self.assertEqual(self.invitation.status, DomainInvitation.RETRIEVED)
 
-    def test_retrieve_on_first_login(self):
-        """A new user's first_login callback retrieves their invitations."""
-        self.user.first_login()
+    def test_retrieve_on_each_login(self):
+        """A user's authenticate on_each_login callback retrieves their invitations."""
+        self.user.on_each_login()
         self.assertTrue(UserDomainRole.objects.get(user=self.user, domain=self.domain))
 
 
@@ -640,19 +640,19 @@ def tearDown(self):
         User.objects.all().delete()
 
     def test_check_transition_domains_on_login(self):
-        """A new user's first_login callback checks transition domains.
+        """A user's on_each_login callback checks transition domains.
         Makes DomainInformation object."""
         self.domain, _ = Domain.objects.get_or_create(name=self.domain_name)
 
-        self.user.first_login()
+        self.user.on_each_login()
         self.assertTrue(DomainInformation.objects.get(domain=self.domain))
 
     def test_check_transition_domains_without_domains_on_login(self):
-        """A new user's first_login callback checks transition domains.
+        """A user's on_each_login callback checks transition domains.
         This test makes sure that in the event a domain does not exist
         for a given transition domain, both a domain and domain invitation
         are created."""
-        self.user.first_login()
+        self.user.on_each_login()
         self.assertTrue(Domain.objects.get(name=self.domain_name))
 
         domain = Domain.objects.get(name=self.domain_name)
diff --git a/src/registrar/tests/test_transition_domain_migrations.py b/src/registrar/tests/test_transition_domain_migrations.py
--- a/src/registrar/tests/test_transition_domain_migrations.py
+++ b/src/registrar/tests/test_transition_domain_migrations.py
@@ -237,7 +237,7 @@ def test_logins(self):
             user, user_created = User.objects.get_or_create(
                 email=invite.email, username=invite.email
             )
-            user.first_login()
+            user.on_each_login()
 
         # Analyze the tables
         expected_total_transition_domains = 8
diff --git a/src/registrar/tests/test_views.py b/src/registrar/tests/test_views.py
--- a/src/registrar/tests/test_views.py
+++ b/src/registrar/tests/test_views.py
@@ -1457,8 +1457,8 @@ def test_domain_invitation_flow(self):
         new_user = User.objects.create(username=EMAIL, email=EMAIL)
         # log them in to `self.app`
         self.app.set_user(new_user.username)
-        # and manually call the first login callback
-        new_user.first_login()
+        # and manually call the on each login callback
+        new_user.on_each_login()
 
         # Now load the home page and make sure our domain appears there
         home_page = self.app.get(reverse("home"))