Skip to content

Commit

Permalink
Wrapped user creation in db transaction block.
Browse files Browse the repository at this point in the history
Otherwise User object without attached EmailAddress may be created if something goes wrong during the process.
  • Loading branch information
nigma committed Feb 21, 2012
1 parent 1204cfd commit 25f5182
Showing 1 changed file with 7 additions and 6 deletions.
13 changes: 7 additions & 6 deletions pinax/apps/account/forms.py
Expand Up @@ -3,6 +3,7 @@
from django import forms
from django.conf import settings
from django.core.mail import send_mail
from django.db import transaction
from django.template.loader import render_to_string
from django.utils.translation import ugettext_lazy as _, ugettext
from django.utils.http import int_to_base36
Expand Down Expand Up @@ -197,13 +198,13 @@ def save(self, request=None):
# don't assume a username is available. it is a common removal if
# site developer wants to use email authentication.
username = self.cleaned_data.get("username")
new_user = self.create_user(username)

verified = self.handle_confirmation(new_user, request=request)

if EMAIL_VERIFICATION and not verified:
new_user.is_active = False
new_user.save()
with transaction.commit_on_success():
new_user = self.create_user(username)
verified = self.handle_confirmation(new_user, request=request)
if EMAIL_VERIFICATION and not verified:
new_user.is_active = False
new_user.save()

self.after_signup(new_user)

Expand Down

0 comments on commit 25f5182

Please sign in to comment.