Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
E
edx-platform
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
edx
edx-platform
Commits
7a9d142a
Commit
7a9d142a
authored
May 04, 2012
by
pmitros
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #27 from MITx/user_integrity_error
Remove some race conditions in user signups
parents
c2f5f1d4
2a073a23
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
15 additions
and
11 deletions
+15
-11
djangoapps/student/views.py
+15
-11
No files found.
djangoapps/student/views.py
View file @
7a9d142a
...
...
@@ -13,7 +13,7 @@ from django.contrib.auth.models import User
from
django.core.context_processors
import
csrf
from
django.core.mail
import
send_mail
from
django.core.validators
import
validate_email
,
validate_slug
,
ValidationError
from
django.db
import
connection
from
django.db
import
IntegrityError
from
django.http
import
HttpResponse
,
Http404
from
django.shortcuts
import
redirect
from
mitxmako.shortcuts
import
render_to_response
,
render_to_string
...
...
@@ -162,15 +162,6 @@ def create_account(request, post_override=None):
# Confirm username and e-mail are unique. TODO: This should be in a transaction
if
len
(
User
.
objects
.
filter
(
username
=
post_vars
[
'username'
]))
>
0
:
js
[
'value'
]
=
"An account with this username already exists."
return
HttpResponse
(
json
.
dumps
(
js
))
if
len
(
User
.
objects
.
filter
(
email
=
post_vars
[
'email'
]))
>
0
:
js
[
'value'
]
=
"An account with this e-mail already exists."
return
HttpResponse
(
json
.
dumps
(
js
))
u
=
User
(
username
=
post_vars
[
'username'
],
email
=
post_vars
[
'email'
],
is_active
=
False
)
...
...
@@ -178,7 +169,20 @@ def create_account(request, post_override=None):
r
=
Registration
()
# TODO: Rearrange so that if part of the process fails, the whole process fails.
# Right now, we can have e.g. no registration e-mail sent out and a zombie account
u
.
save
()
try
:
u
.
save
()
except
IntegrityError
:
# Figure out the cause of the integrity error
if
len
(
User
.
objects
.
filter
(
username
=
post_vars
[
'username'
]))
>
0
:
js
[
'value'
]
=
"An account with this username already exists."
return
HttpResponse
(
json
.
dumps
(
js
))
if
len
(
User
.
objects
.
filter
(
email
=
post_vars
[
'email'
]))
>
0
:
js
[
'value'
]
=
"An account with this e-mail already exists."
return
HttpResponse
(
json
.
dumps
(
js
))
raise
r
.
register
(
u
)
up
=
UserProfile
(
user
=
u
)
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment