Commit b0a0250bc53d62e91a3e0d165de9b83e050b166d

Authored by Matheus de Sousa Faria
1 parent c449fb6b

Revert "Send Django signals when user is created and password is changed"

colab/accounts/forms.py
... ... @@ -17,7 +17,7 @@ from django.utils.text import capfirst
17 17 from django.utils.translation import ugettext_lazy as _
18 18 from django.utils.safestring import mark_safe
19 19  
20   -from .signals import user_created
  20 +
21 21 from .utils.validators import validate_social_account
22 22 from .utils import mailman
23 23  
... ... @@ -242,14 +242,9 @@ class UserCreationForm(UserForm):
242 242  
243 243 def save(self, commit=True):
244 244 user = super(UserCreationForm, self).save(commit=False)
245   - password = self.cleaned_data["password1"]
246   - user.set_password(password)
247   -
  245 + user.set_password(self.cleaned_data["password1"])
248 246 if commit:
249 247 user.save()
250   -
251   - user_created.send(user.__class__, user=user, password=password)
252   -
253 248 return user
254 249  
255 250  
... ...
colab/accounts/models.py
... ... @@ -9,20 +9,11 @@ from django.core.urlresolvers import reverse
9 9 from django.utils.crypto import get_random_string
10 10 from django.utils.translation import ugettext_lazy as _
11 11  
12   -from .signals import user_created, user_password_changed
13 12 from .utils import mailman
14 13  
15 14  
16 15 class ColabUserManager(UserManager):
17 16  
18   - def _create_user(self, username, email, password,
19   - is_staff, is_superuser, **kwargs):
20   - args = (username, email, password, is_staff, is_superuser)
21   - user = super(ColabUserManager, self)._create_user(*args, **kwargs)
22   -
23   - user_created.send(user.__class__, user=user, password=password)
24   - return user
25   -
26 17 def create_user(self, username, email=None, password=None, **extra_fields):
27 18  
28 19 # It creates a valid password for users
... ... @@ -77,11 +68,6 @@ class User(AbstractUser):
77 68 self.username = self.username.lower()
78 69 super(User, self).save(*args, **kwargs)
79 70  
80   - def set_password(self, raw_password):
81   - super(User, self).set_password(raw_password)
82   - if self.pk:
83   - user_password_changed.send(User, user=self, password=raw_password)
84   -
85 71  
86 72 # We need to have `email` field set as unique but Django does not
87 73 # support field overriding (at least not until 1.6).
... ...
colab/accounts/signals.py
... ... @@ -1,6 +0,0 @@
1   -
2   -from django.dispatch import Signal
3   -
4   -
5   -user_created = Signal(providing_args=['user', 'password'])
6   -user_password_changed = Signal(providing_args=['user', 'password'])
colab/accounts/tests/test_user.py
... ... @@ -374,22 +374,3 @@ class UserTest(TestCase):
374 374 self.authenticate_user()
375 375 self.validate_non_mandatory_fields('bio', '', ' ')
376 376 self.user.delete()
377   -
378   - @mock.patch('colab.accounts.signals.user_password_changed.send')
379   - @mock.patch('colab.accounts.signals.user_created.send')
380   - def test_user_created_signal(self, user_created_send,
381   - user_password_changed_send):
382   - user = User.objects.create_user(
383   - username='test_user',
384   - password='12345',
385   - email='test@example.com',
386   - )
387   - user_created_send.assert_called_with(User, user=user, password='12345')
388   - user_password_changed_send.assert_not_called()
389   -
390   - @mock.patch('colab.accounts.signals.user_password_changed.send')
391   - def test_user_password_changed_signal(self, user_password_changed_send):
392   - user = User.objects.first()
393   - user.set_password('54321')
394   - user_password_changed_send.assert_called_with(User, user=user,
395   - password='54321')
... ...
colab/accounts/urls.py
... ... @@ -29,7 +29,7 @@ urlpatterns = patterns('',
29 29 {'template_name':'registration/password_reset_form_custom.html'},
30 30 name="password_reset"),
31 31  
32   - url(r'^change-password/?$', auth_views.password_change,
  32 + url(r'^change-password/?$',auth_views.password_change,
33 33 {'template_name':'registration/password_change_form_custom.html'},
34 34 name='password_change'),
35 35  
... ...