Commits

Marko Mrdjenovic committed d88aa02

added user_invited signal that provides a way to make sure users keep having invitations

Comments (0)

Files changed (2)

registration/backends/invitational/__init__.py

         
         """
         user, email = request.user, kwargs['email']
+        klass = self.invitation_model_class
         if user.is_authenticated():
             try:
                 User.objects.get(email=email)
                 raise UserAlreadyExists(_("User with the specified email already exists."))
             except User.DoesNotExist:
                 site = get_current_site(request)
-                return self.invitation_model_class.objects.send_invitation(user, 
-                                                                           email, 
-                                                                           site)
+                invitation = klass.objects.send_invitation(user, email, site)
+                if invitation:
+                    signals.user_invited.send(sender=self.__class__,
+                                              invitation=invitation,
+                                              request=request)
+                return invitation
         return None
     
     def get_invitation_form_class(self, request):
                                                     kwargs['email'],  \
                                                     kwargs['password1'],  \
                                                     kwargs['invitation_key']
+        klass = self.validation_model_class
         site = get_current_site(request)
-        new_user = self.validation_model_class.objects.create_user(username, email, 
+        new_user = klass.objects.create_user(username, email, 
                                                        password, site, 
                                                        invitation_key=invitation_key,
                                                        active=(not self.required_validation))
         this backend as the sender.
         
         """
-        validated = self.validation_model_class.objects.validate_email(validation_key)
+        klass = self.validation_model_class
+        validated = klass.objects.validate_email(validation_key)
         if validated:
             if self.required_validation:
                 validated.is_active = True
           spermitted.
         
         """
+        klass = self.invitation_model_class
         if not getattr(settings, 'REGISTRATION_OPEN', False):
             try:
                 if request.GET.get("invitation_key"):
-                    invite = self.invitation_model_class.objects.get(invitation_key=request.GET.get("invitation_key"))
+                    invite = klass.objects.get(invitation_key=request.GET.get("invitation_key"))
                     return True
                 else:
                     return False
-            except self.invitation_model_class.DoesNotExist:
+            except klass.DoesNotExist:
                 return False
         return True
     

registration/signals.py

 from django.dispatch import Signal
 
 
+# A user has been invited
+user_invited = Signal(providing_args=["invitation", "request"])
+
 # A new user has registered.
 user_registered = Signal(providing_args=["user", "request"])