Commit cb89a2f3e8e8e9e9ad643da89e3b3b25bca0e1c1
1 parent
688b8c11
Exists in
master
and in
4 other branches
New signal for user created
Showing
5 changed files
with
26 additions
and
18 deletions
Show diff stats
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 | - | |
| 20 | +from .signals import user_created | |
| 21 | 21 | from .utils.validators import validate_social_account |
| 22 | 22 | from .utils import mailman |
| 23 | 23 | |
| ... | ... | @@ -242,9 +242,14 @@ class UserCreationForm(UserForm): |
| 242 | 242 | |
| 243 | 243 | def save(self, commit=True): |
| 244 | 244 | user = super(UserCreationForm, self).save(commit=False) |
| 245 | - user.set_password(self.cleaned_data["password1"]) | |
| 245 | + password = self.cleaned_data["password1"] | |
| 246 | + user.set_password(password) | |
| 247 | + | |
| 246 | 248 | if commit: |
| 247 | 249 | user.save() |
| 250 | + | |
| 251 | + user_created.send(user.__class__, user=user, password=password) | |
| 252 | + | |
| 248 | 253 | return user |
| 249 | 254 | |
| 250 | 255 | ... | ... |
colab/accounts/models.py
| ... | ... | @@ -9,11 +9,19 @@ 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 | |
| 12 | 13 | from .utils import mailman |
| 13 | 14 | |
| 14 | 15 | |
| 15 | 16 | class ColabUserManager(UserManager): |
| 16 | 17 | |
| 18 | + def _create_user(self, *args, **kwargs): | |
| 19 | + user = super(ColabUserManager, self)._create_user(*args, **kwargs) | |
| 20 | + password = kwargs.get('password') | |
| 21 | + | |
| 22 | + user_created.send(user.__class__, user=user, password=password) | |
| 23 | + return user | |
| 24 | + | |
| 17 | 25 | def create_user(self, username, email=None, password=None, **extra_fields): |
| 18 | 26 | |
| 19 | 27 | # It creates a valid password for users |
| ... | ... | @@ -68,6 +76,11 @@ class User(AbstractUser): |
| 68 | 76 | self.username = self.username.lower() |
| 69 | 77 | super(User, self).save(*args, **kwargs) |
| 70 | 78 | |
| 79 | + def set_password(self, raw_password): | |
| 80 | + super(User, self).set_password(raw_password) | |
| 81 | + if self.pk: | |
| 82 | + user_password_changed.send(User, user=self, password=raw_password) | |
| 83 | + | |
| 71 | 84 | |
| 72 | 85 | # We need to have `email` field set as unique but Django does not |
| 73 | 86 | # support field overriding (at least not until 1.6). | ... | ... |
colab/accounts/signals.py
colab/accounts/urls.py
| ... | ... | @@ -3,7 +3,7 @@ from django.conf import settings |
| 3 | 3 | from django.conf.urls import patterns, url |
| 4 | 4 | |
| 5 | 5 | from .views import (UserProfileDetailView, UserProfileUpdateView, |
| 6 | - ManageUserSubscriptionsView, colab_password_change) | |
| 6 | + ManageUserSubscriptionsView) | |
| 7 | 7 | |
| 8 | 8 | from colab.accounts import views |
| 9 | 9 | from django.contrib.auth import views as auth_views |
| ... | ... | @@ -29,7 +29,8 @@ urlpatterns = patterns('', |
| 29 | 29 | {'template_name':'registration/password_reset_form_custom.html'}, |
| 30 | 30 | name="password_reset"), |
| 31 | 31 | |
| 32 | - url(r'^change-password/?$', colab_password_change, | |
| 32 | + url(r'^change-password/?$', auth_views.password_change, | |
| 33 | + {'template_name':'registration/password_change_form_custom.html'}, | |
| 33 | 34 | name='password_change'), |
| 34 | 35 | |
| 35 | 36 | url(r'^change-password-done/?$', | ... | ... |
colab/accounts/views.py
| ... | ... | @@ -2,7 +2,6 @@ |
| 2 | 2 | from collections import OrderedDict |
| 3 | 3 | |
| 4 | 4 | from django.contrib import messages |
| 5 | -from django.contrib.auth.views import password_change | |
| 6 | 5 | from django.db.models import Count |
| 7 | 6 | from django.contrib.auth import get_user_model |
| 8 | 7 | from django.utils.translation import ugettext as _ |
| ... | ... | @@ -18,7 +17,6 @@ from colab.search.utils import get_collaboration_data, get_visible_threads |
| 18 | 17 | from colab.accounts.models import User |
| 19 | 18 | |
| 20 | 19 | from .forms import (UserCreationForm, ListsForm, UserUpdateForm) |
| 21 | -from .signals import user_password_changed | |
| 22 | 20 | from .utils import mailman |
| 23 | 21 | |
| 24 | 22 | |
| ... | ... | @@ -214,13 +212,3 @@ def myaccount_redirect(request, route): |
| 214 | 212 | url = '/'.join(('/account', request.user.username, route)) |
| 215 | 213 | |
| 216 | 214 | return redirect(url) |
| 217 | - | |
| 218 | - | |
| 219 | -def colab_password_change(request): | |
| 220 | - template_name = 'registration/password_change_form_custom.html' | |
| 221 | - response = password_change(request, template_name) | |
| 222 | - if response.status_code == 302: | |
| 223 | - user_password_changed.send(sender=colab_password_change.__name__, | |
| 224 | - user=request.user, | |
| 225 | - password=request.POST.get('new_password1')) | |
| 226 | - return response | ... | ... |