Retrieve domain invitations on first login

This commit is contained in:
Neil Martinsen-Burrell 2023-03-27 16:10:33 -05:00
parent 8338704315
commit e54dda3ddd
No known key found for this signature in database
GPG key ID: 6A3C818CC10D0184
4 changed files with 45 additions and 0 deletions

View file

@ -1,6 +1,8 @@
from django.contrib.auth.models import AbstractUser
from django.db import models
from .domain_invitation import DomainInvitation
from phonenumber_field.modelfields import PhoneNumberField # type: ignore
@ -31,3 +33,14 @@ class User(AbstractUser):
return self.email
else:
return self.username
def first_login(self):
"""Callback when the user is authenticated for the very first time.
When a user first arrives on the site, we need to retrieve any domain
invitations that match their email address.
"""
for invitation in DomainInvitation.objects.filter(
email=self.email, status=DomainInvitation.SENT
):
invitation.retrieve()