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
edba397a
Commit
edba397a
authored
Nov 05, 2014
by
Renzo Lucioni
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Return more helpful error messages when a resource conflict occurs
parent
8a0507c9
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
41 additions
and
23 deletions
+41
-23
common/djangoapps/user_api/tests/test_views.py
+14
-9
common/djangoapps/user_api/views.py
+27
-14
No files found.
common/djangoapps/user_api/tests/test_views.py
View file @
edba397a
...
...
@@ -832,9 +832,6 @@ class RegistrationViewTest(ApiTestCase):
u"required"
:
True
,
u"label"
:
u"Email"
,
u"placeholder"
:
u"username@domain.com"
,
u"instructions"
:
u"The email address you used to register with {platform_name}"
.
format
(
platform_name
=
settings
.
PLATFORM_NAME
),
u"restrictions"
:
{
"min_length"
:
account_api
.
EMAIL_MIN_LENGTH
,
"max_length"
:
account_api
.
EMAIL_MAX_LENGTH
...
...
@@ -913,9 +910,6 @@ class RegistrationViewTest(ApiTestCase):
u"required"
:
True
,
u"label"
:
u"Email"
,
u"placeholder"
:
u"username@domain.com"
,
"instructions"
:
"The email address you used to register with {platform_name}"
.
format
(
platform_name
=
settings
.
PLATFORM_NAME
),
u"restrictions"
:
{
"min_length"
:
account_api
.
EMAIL_MIN_LENGTH
,
"max_length"
:
account_api
.
EMAIL_MAX_LENGTH
...
...
@@ -1354,7 +1348,10 @@ class RegistrationViewTest(ApiTestCase):
"honor_code"
:
"true"
,
})
self
.
assertEqual
(
response
.
status_code
,
409
)
self
.
assertEqual
(
response
.
content
,
json
.
dumps
([
"email"
]))
self
.
assertEqual
(
response
.
content
,
"It looks like {} belongs to an existing account."
.
format
(
self
.
EMAIL
)
)
def
test_register_duplicate_username
(
self
):
# Register the first user
...
...
@@ -1376,7 +1373,10 @@ class RegistrationViewTest(ApiTestCase):
"honor_code"
:
"true"
,
})
self
.
assertEqual
(
response
.
status_code
,
409
)
self
.
assertEqual
(
response
.
content
,
json
.
dumps
([
"username"
]))
self
.
assertEqual
(
response
.
content
,
"It looks like {} belongs to an existing account."
.
format
(
self
.
USERNAME
)
)
def
test_register_duplicate_username_and_email
(
self
):
# Register the first user
...
...
@@ -1398,7 +1398,12 @@ class RegistrationViewTest(ApiTestCase):
"honor_code"
:
"true"
,
})
self
.
assertEqual
(
response
.
status_code
,
409
)
self
.
assertEqual
(
response
.
content
,
json
.
dumps
([
"email"
,
"username"
]))
self
.
assertEqual
(
response
.
content
,
"It looks like {} and {} belong to an existing account."
.
format
(
self
.
EMAIL
,
self
.
USERNAME
)
)
def
_assert_reg_field
(
self
,
extra_fields_setting
,
expected_field
):
"""Retrieve the registration form description from the server and
...
...
common/djangoapps/user_api/views.py
View file @
edba397a
...
...
@@ -255,16 +255,36 @@ class RegistrationView(APIView):
HttpResponse: 302 if redirecting to another page.
"""
# Handle duplicate username/email
conflicts
=
account_api
.
check_account_exists
(
username
=
request
.
POST
.
get
(
'username'
),
email
=
request
.
POST
.
get
(
'email'
)
)
email
=
request
.
POST
.
get
(
'email'
)
username
=
request
.
POST
.
get
(
'username'
)
# Handle duplicate email/username
conflicts
=
account_api
.
check_account_exists
(
email
=
email
,
username
=
username
)
if
conflicts
:
if
all
(
conflict
in
conflicts
for
conflict
in
[
'email'
,
'username'
]):
# Translators: This message is shown to users who attempt to create a new
# account using both an email address and a username associated with an
# existing account.
error_msg
=
_
(
u"It looks like {email_address} and {username} belong to an existing account."
)
.
format
(
email_address
=
email
,
username
=
username
)
elif
'email'
in
conflicts
:
# Translators: This message is shown to users who attempt to create a new
# account using an email address associated with an existing account.
error_msg
=
_
(
u"It looks like {email_address} belongs to an existing account."
)
.
format
(
email_address
=
email
)
else
:
# Translators: This message is shown to users who attempt to create a new
# account using a username associated with an existing account.
error_msg
=
_
(
u"It looks like {username} belongs to an existing account."
)
.
format
(
username
=
username
)
return
HttpResponse
(
status
=
409
,
content
=
json
.
dumps
(
conflicts
)
,
content_type
=
"
application/jso
n"
content
=
error_msg
,
content_type
=
"
text/plai
n"
)
# For the initial implementation, shim the existing login view
...
...
@@ -281,18 +301,11 @@ class RegistrationView(APIView):
# a field on the registration form meant to hold the user's email address.
email_placeholder
=
_
(
u"username@domain.com"
)
# Translators: These instructions appear on the registration form, immediately
# below a field meant to hold the user's email address.
email_instructions
=
_
(
u"The email address you used to register with {platform_name}"
)
.
format
(
platform_name
=
settings
.
PLATFORM_NAME
)
form_desc
.
add_field
(
"email"
,
field_type
=
"email"
,
label
=
email_label
,
placeholder
=
email_placeholder
,
instructions
=
email_instructions
,
restrictions
=
{
"min_length"
:
account_api
.
EMAIL_MIN_LENGTH
,
"max_length"
:
account_api
.
EMAIL_MAX_LENGTH
,
...
...
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