Permalink
Browse files

Added some signals to login/signup forms

  • Loading branch information...
1 parent 06e4377 commit a1b238625cb3f9576454b290558e7c73823106a3 @paltman paltman committed Jan 12, 2012
Showing with 23 additions and 3 deletions.
  1. +17 −1 pinax/apps/account/forms.py
  2. +6 −2 pinax/apps/account/signals.py
View
18 pinax/apps/account/forms.py
@@ -17,6 +17,7 @@
from timezones.forms import TimeZoneField
from pinax.apps.account.models import Account, PasswordReset
+from pinax.apps.account.signals import user_login_attempt, user_signed_up, user_sign_up_attempt
from pinax.apps.account.utils import perform_login, change_password
@@ -98,6 +99,11 @@ def clean(self):
raise forms.ValidationError(error)
return self.cleaned_data
+ def is_valid(self, *args, **kwargs):
+ result = super(LoginForm, self).is_valid(*args, **kwargs)
+ user_login_attempt.send(sender=LoginForm, username=self.data["username"], result=result)
+ return result
+
def login(self, request):
perform_login(request, self.user)
if self.cleaned_data["remember"]:
@@ -241,11 +247,21 @@ def save(self, request=None):
return new_user
+ def is_valid(self, *args, **kwargs):
+ result = super(SignupForm, self).is_valid(*args, **kwargs)
+ user_sign_up_attempt.send(
+ sender=SignupForm,
+ username=self.data["username"],
+ email=self.data["email"],
+ result=result
+ )
+ return result
+
def after_signup(self, user, **kwargs):
"""
An extension point for subclasses.
"""
- pass
+ user_signed_up.send(sender=SignupForm, user=user)
@brosner
brosner Feb 21, 2012

This signal should never be called from this method. The interface doesn't require children to call this method on the parent. Thus resulting in this signal never firing for some projects. It would be better to call this after we call after_signup.

class OpenIDSignupForm(SignupForm):
View
8 pinax/apps/account/signals.py
@@ -1,5 +1,9 @@
import django.dispatch
-
+# @@@ this is the exact same as in django.contrib.auth not sure why it's duped here
user_logged_in = django.dispatch.Signal(providing_args=["request", "user"])
-password_changed = django.dispatch.Signal(providing_args=["user",])
+
+password_changed = django.dispatch.Signal(providing_args=["user",])
+user_login_attempt = django.dispatch.Signal(providing_args=["username", "result"])
+user_sign_up_attempt = django.dispatch.Signal(providing_args=["username", "email", "result"])
+user_signed_up = django.dispatch.Signal(providing_args=["user"])

0 comments on commit a1b2386

Please sign in to comment.