Commit 9eb1b7a9a068067bded52b97738be7caf2045c72
Exists in
master
and in
3 other branches
Merge pull request #122 from colab/revert-119-change-passwd-signal
Revert "Send Django signals when user is created and password is changed"
Showing
5 changed files
with
3 additions
and
47 deletions
Show diff stats
colab/accounts/forms.py
| @@ -17,7 +17,7 @@ from django.utils.text import capfirst | @@ -17,7 +17,7 @@ from django.utils.text import capfirst | ||
| 17 | from django.utils.translation import ugettext_lazy as _ | 17 | from django.utils.translation import ugettext_lazy as _ |
| 18 | from django.utils.safestring import mark_safe | 18 | from django.utils.safestring import mark_safe |
| 19 | 19 | ||
| 20 | -from .signals import user_created | 20 | + |
| 21 | from .utils.validators import validate_social_account | 21 | from .utils.validators import validate_social_account |
| 22 | from .utils import mailman | 22 | from .utils import mailman |
| 23 | 23 | ||
| @@ -242,14 +242,9 @@ class UserCreationForm(UserForm): | @@ -242,14 +242,9 @@ class UserCreationForm(UserForm): | ||
| 242 | 242 | ||
| 243 | def save(self, commit=True): | 243 | def save(self, commit=True): |
| 244 | user = super(UserCreationForm, self).save(commit=False) | 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 | if commit: | 246 | if commit: |
| 249 | user.save() | 247 | user.save() |
| 250 | - | ||
| 251 | - user_created.send(user.__class__, user=user, password=password) | ||
| 252 | - | ||
| 253 | return user | 248 | return user |
| 254 | 249 | ||
| 255 | 250 |
colab/accounts/models.py
| @@ -9,20 +9,11 @@ from django.core.urlresolvers import reverse | @@ -9,20 +9,11 @@ from django.core.urlresolvers import reverse | ||
| 9 | from django.utils.crypto import get_random_string | 9 | from django.utils.crypto import get_random_string |
| 10 | from django.utils.translation import ugettext_lazy as _ | 10 | from django.utils.translation import ugettext_lazy as _ |
| 11 | 11 | ||
| 12 | -from .signals import user_created, user_password_changed | ||
| 13 | from .utils import mailman | 12 | from .utils import mailman |
| 14 | 13 | ||
| 15 | 14 | ||
| 16 | class ColabUserManager(UserManager): | 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 | def create_user(self, username, email=None, password=None, **extra_fields): | 17 | def create_user(self, username, email=None, password=None, **extra_fields): |
| 27 | 18 | ||
| 28 | # It creates a valid password for users | 19 | # It creates a valid password for users |
| @@ -77,11 +68,6 @@ class User(AbstractUser): | @@ -77,11 +68,6 @@ class User(AbstractUser): | ||
| 77 | self.username = self.username.lower() | 68 | self.username = self.username.lower() |
| 78 | super(User, self).save(*args, **kwargs) | 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 | # We need to have `email` field set as unique but Django does not | 72 | # We need to have `email` field set as unique but Django does not |
| 87 | # support field overriding (at least not until 1.6). | 73 | # support field overriding (at least not until 1.6). |
colab/accounts/signals.py
colab/accounts/tests/test_user.py
| @@ -374,22 +374,3 @@ class UserTest(TestCase): | @@ -374,22 +374,3 @@ class UserTest(TestCase): | ||
| 374 | self.authenticate_user() | 374 | self.authenticate_user() |
| 375 | self.validate_non_mandatory_fields('bio', '', ' ') | 375 | self.validate_non_mandatory_fields('bio', '', ' ') |
| 376 | self.user.delete() | 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,7 +29,7 @@ urlpatterns = patterns('', | ||
| 29 | {'template_name':'registration/password_reset_form_custom.html'}, | 29 | {'template_name':'registration/password_reset_form_custom.html'}, |
| 30 | name="password_reset"), | 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 | {'template_name':'registration/password_change_form_custom.html'}, | 33 | {'template_name':'registration/password_change_form_custom.html'}, |
| 34 | name='password_change'), | 34 | name='password_change'), |
| 35 | 35 |