Skip to content

Commit

Permalink
Merge pull request #122 from colab/revert-119-change-passwd-signal
Browse files Browse the repository at this point in the history
Revert "Send Django signals when user is created and password is changed"
  • Loading branch information
MatheusFaria committed Nov 30, 2015
2 parents c449fb6 + b0a0250 commit 9eb1b7a
Show file tree
Hide file tree
Showing 5 changed files with 3 additions and 47 deletions.
9 changes: 2 additions & 7 deletions colab/accounts/forms.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
from django.utils.translation import ugettext_lazy as _
from django.utils.safestring import mark_safe

from .signals import user_created

from .utils.validators import validate_social_account
from .utils import mailman

Expand Down Expand Up @@ -242,14 +242,9 @@ def clean_password2(self):

def save(self, commit=True):
user = super(UserCreationForm, self).save(commit=False)
password = self.cleaned_data["password1"]
user.set_password(password)

user.set_password(self.cleaned_data["password1"])
if commit:
user.save()

user_created.send(user.__class__, user=user, password=password)

return user


Expand Down
14 changes: 0 additions & 14 deletions colab/accounts/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,20 +9,11 @@
from django.utils.crypto import get_random_string
from django.utils.translation import ugettext_lazy as _

from .signals import user_created, user_password_changed
from .utils import mailman


class ColabUserManager(UserManager):

def _create_user(self, username, email, password,
is_staff, is_superuser, **kwargs):
args = (username, email, password, is_staff, is_superuser)
user = super(ColabUserManager, self)._create_user(*args, **kwargs)

user_created.send(user.__class__, user=user, password=password)
return user

def create_user(self, username, email=None, password=None, **extra_fields):

# It creates a valid password for users
Expand Down Expand Up @@ -77,11 +68,6 @@ def save(self, *args, **kwargs):
self.username = self.username.lower()
super(User, self).save(*args, **kwargs)

def set_password(self, raw_password):
super(User, self).set_password(raw_password)
if self.pk:
user_password_changed.send(User, user=self, password=raw_password)


# We need to have `email` field set as unique but Django does not
# support field overriding (at least not until 1.6).
Expand Down
6 changes: 0 additions & 6 deletions colab/accounts/signals.py

This file was deleted.

19 changes: 0 additions & 19 deletions colab/accounts/tests/test_user.py
Original file line number Diff line number Diff line change
Expand Up @@ -374,22 +374,3 @@ def test_update_user_bio_invalid_whitespace(self):
self.authenticate_user()
self.validate_non_mandatory_fields('bio', '', ' ')
self.user.delete()

@mock.patch('colab.accounts.signals.user_password_changed.send')
@mock.patch('colab.accounts.signals.user_created.send')
def test_user_created_signal(self, user_created_send,
user_password_changed_send):
user = User.objects.create_user(
username='test_user',
password='12345',
email='test@example.com',
)
user_created_send.assert_called_with(User, user=user, password='12345')
user_password_changed_send.assert_not_called()

@mock.patch('colab.accounts.signals.user_password_changed.send')
def test_user_password_changed_signal(self, user_password_changed_send):
user = User.objects.first()
user.set_password('54321')
user_password_changed_send.assert_called_with(User, user=user,
password='54321')
2 changes: 1 addition & 1 deletion colab/accounts/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
{'template_name':'registration/password_reset_form_custom.html'},
name="password_reset"),

url(r'^change-password/?$', auth_views.password_change,
url(r'^change-password/?$',auth_views.password_change,
{'template_name':'registration/password_change_form_custom.html'},
name='password_change'),

Expand Down

0 comments on commit 9eb1b7a

Please sign in to comment.