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
3ddddbe5
Commit
3ddddbe5
authored
Jan 16, 2012
by
Piotr Mitros
Browse files
Options
Browse Files
Download
Plain Diff
merge
parents
56c81a07
d909e891
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
50 additions
and
21 deletions
+50
-21
auth/views.py
+46
-17
settings.py
+4
-4
No files found.
auth/views.py
View file @
3ddddbe5
...
@@ -9,6 +9,7 @@ from models import Registration, UserProfile
...
@@ -9,6 +9,7 @@ from models import Registration, UserProfile
from
django.conf
import
settings
from
django.conf
import
settings
from
django.core.context_processors
import
csrf
from
django.core.context_processors
import
csrf
from
django.core.validators
import
validate_email
,
validate_slug
from
django.core.validators
import
validate_email
,
validate_slug
import
random
,
string
def
csrf_token
(
context
):
def
csrf_token
(
context
):
csrf_token
=
context
.
get
(
'csrf_token'
,
''
)
csrf_token
=
context
.
get
(
'csrf_token'
,
''
)
...
@@ -88,22 +89,25 @@ def change_setting(request):
...
@@ -88,22 +89,25 @@ def change_setting(request):
'language'
:
up
.
language
,
'language'
:
up
.
language
,
'location'
:
up
.
location
,}))
'location'
:
up
.
location
,}))
def
create_account
(
request
):
def
create_account
(
request
,
post_override
=
None
):
js
=
{
'success'
:
False
}
js
=
{
'success'
:
False
}
post_vars
=
post_override
if
post_override
else
request
.
POST
# Confirm we have a properly formed request
# Confirm we have a properly formed request
for
a
in
[
'username'
,
'email'
,
'password'
,
'location'
,
'language'
,
'name'
]:
for
a
in
[
'username'
,
'email'
,
'password'
,
'location'
,
'language'
,
'name'
]:
if
a
not
in
request
.
POST
:
if
a
not
in
post_vars
:
js
[
'value'
]
=
"Error (401 {field}). E-mail us."
.
format
(
field
=
a
)
js
[
'value'
]
=
"Error (401 {field}). E-mail us."
.
format
(
field
=
a
)
return
HttpResponse
(
json
.
dumps
(
js
))
return
HttpResponse
(
json
.
dumps
(
js
))
if
request
.
POST
[
'honor_code'
]
!=
u'true'
:
if
post_vars
[
'honor_code'
]
!=
u'true'
:
js
[
'value'
]
=
"To enroll, you must follow the honor code."
.
format
(
field
=
a
)
js
[
'value'
]
=
"To enroll, you must follow the honor code."
.
format
(
field
=
a
)
return
HttpResponse
(
json
.
dumps
(
js
))
return
HttpResponse
(
json
.
dumps
(
js
))
if
request
.
POST
[
'terms_of_service'
]
!=
u'true'
:
if
post_vars
[
'terms_of_service'
]
!=
u'true'
:
js
[
'value'
]
=
"You must accept the terms of service."
.
format
(
field
=
a
)
js
[
'value'
]
=
"You must accept the terms of service."
.
format
(
field
=
a
)
return
HttpResponse
(
json
.
dumps
(
js
))
return
HttpResponse
(
json
.
dumps
(
js
))
...
@@ -113,18 +117,18 @@ def create_account(request):
...
@@ -113,18 +117,18 @@ def create_account(request):
# this is a good idea
# this is a good idea
# TODO: Check password is sane
# TODO: Check password is sane
for
a
in
[
'username'
,
'email'
,
'password'
,
'terms_of_service'
,
'honor_code'
]:
for
a
in
[
'username'
,
'email'
,
'password'
,
'terms_of_service'
,
'honor_code'
]:
if
len
(
request
.
POST
[
a
])
<
2
:
if
len
(
post_vars
[
a
])
<
2
:
js
[
'value'
]
=
"{field} is required."
.
format
(
field
=
a
)
js
[
'value'
]
=
"{field} is required."
.
format
(
field
=
a
)
return
HttpResponse
(
json
.
dumps
(
js
))
return
HttpResponse
(
json
.
dumps
(
js
))
try
:
try
:
validate_email
(
request
.
POST
[
'email'
])
validate_email
(
post_vars
[
'email'
])
except
:
except
:
js
[
'value'
]
=
"Valid e-mail is required."
.
format
(
field
=
a
)
js
[
'value'
]
=
"Valid e-mail is required."
.
format
(
field
=
a
)
return
HttpResponse
(
json
.
dumps
(
js
))
return
HttpResponse
(
json
.
dumps
(
js
))
try
:
try
:
validate_slug
(
request
.
POST
[
'username'
])
validate_slug
(
post_vars
[
'username'
])
except
:
except
:
js
[
'value'
]
=
"Username should only consist of A-Z and 0-9."
.
format
(
field
=
a
)
js
[
'value'
]
=
"Username should only consist of A-Z and 0-9."
.
format
(
field
=
a
)
return
HttpResponse
(
json
.
dumps
(
js
))
return
HttpResponse
(
json
.
dumps
(
js
))
...
@@ -132,18 +136,18 @@ def create_account(request):
...
@@ -132,18 +136,18 @@ def create_account(request):
# Confirm username and e-mail are unique. TODO: This should be in a transaction
# Confirm username and e-mail are unique. TODO: This should be in a transaction
if
len
(
User
.
objects
.
filter
(
username
=
request
.
POST
[
'username'
]))
>
0
:
if
len
(
User
.
objects
.
filter
(
username
=
post_vars
[
'username'
]))
>
0
:
js
[
'value'
]
=
"An account with this username already exists."
js
[
'value'
]
=
"An account with this username already exists."
return
HttpResponse
(
json
.
dumps
(
js
))
return
HttpResponse
(
json
.
dumps
(
js
))
if
len
(
User
.
objects
.
filter
(
email
=
request
.
POST
[
'email'
]))
>
0
:
if
len
(
User
.
objects
.
filter
(
email
=
post_vars
[
'email'
]))
>
0
:
js
[
'value'
]
=
"An account with this e-mail already exists."
js
[
'value'
]
=
"An account with this e-mail already exists."
return
HttpResponse
(
json
.
dumps
(
js
))
return
HttpResponse
(
json
.
dumps
(
js
))
u
=
User
(
username
=
request
.
POST
[
'username'
],
u
=
User
(
username
=
post_vars
[
'username'
],
email
=
request
.
POST
[
'email'
],
email
=
post_vars
[
'email'
],
is_active
=
False
)
is_active
=
False
)
u
.
set_password
(
request
.
POST
[
'password'
])
u
.
set_password
(
post_vars
[
'password'
])
r
=
Registration
()
r
=
Registration
()
# TODO: Rearrange so that if part of the process fails, the whole process fails.
# 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
# Right now, we can have e.g. no registration e-mail sent out and a zombie account
...
@@ -151,12 +155,12 @@ def create_account(request):
...
@@ -151,12 +155,12 @@ def create_account(request):
r
.
register
(
u
)
r
.
register
(
u
)
up
=
UserProfile
(
user
=
u
)
up
=
UserProfile
(
user
=
u
)
up
.
name
=
request
.
POST
[
'name'
]
up
.
name
=
post_vars
[
'name'
]
up
.
language
=
request
.
POST
[
'language'
]
up
.
language
=
post_vars
[
'language'
]
up
.
location
=
request
.
POST
[
'location'
]
up
.
location
=
post_vars
[
'location'
]
up
.
save
()
up
.
save
()
d
=
{
'name'
:
request
.
POST
[
'name'
],
d
=
{
'name'
:
post_vars
[
'name'
],
'key'
:
r
.
activation_key
,
'key'
:
r
.
activation_key
,
'site'
:
settings
.
SITE_NAME
}
'site'
:
settings
.
SITE_NAME
}
...
@@ -172,9 +176,34 @@ def create_account(request):
...
@@ -172,9 +176,34 @@ def create_account(request):
return
HttpResponse
(
json
.
dumps
(
js
))
return
HttpResponse
(
json
.
dumps
(
js
))
js
=
{
'success'
:
True
,
js
=
{
'success'
:
True
,
'value'
:
render_to_string
(
'registration/reg_complete.html'
,
{
'email'
:
request
.
POST
[
'email'
],
'value'
:
render_to_string
(
'registration/reg_complete.html'
,
{
'email'
:
post_vars
[
'email'
],
'csrf'
:
csrf
(
request
)[
'csrf_token'
]})}
'csrf'
:
csrf
(
request
)[
'csrf_token'
]})}
return
HttpResponse
(
json
.
dumps
(
js
),
mimetype
=
"application/json"
)
return
HttpResponse
(
json
.
dumps
(
js
),
mimetype
=
"application/json"
)
def
create_random_account
(
create_account_function
):
def
id_generator
(
size
=
6
,
chars
=
string
.
ascii_uppercase
+
string
.
ascii_lowercase
+
string
.
digits
):
return
''
.
join
(
random
.
choice
(
chars
)
for
x
in
range
(
size
))
def
inner_create_random_account
(
request
):
post_override
=
{
'username'
:
"random_"
+
id_generator
(),
'email'
:
id_generator
(
size
=
10
,
chars
=
string
.
ascii_lowercase
)
+
"_lover@mitxtest.com"
,
'password'
:
id_generator
(),
'location'
:
id_generator
(
size
=
5
,
chars
=
string
.
ascii_uppercase
),
'language'
:
id_generator
(
size
=
5
,
chars
=
string
.
ascii_uppercase
)
+
"ish"
,
'name'
:
id_generator
(
size
=
5
,
chars
=
string
.
ascii_lowercase
)
+
" "
+
id_generator
(
size
=
7
,
chars
=
string
.
ascii_lowercase
),
'honor_code'
:
u'true'
,
'terms_of_service'
:
u'true'
,}
print
"Creating account: "
,
post_override
return
create_account_function
(
request
,
post_override
=
post_override
)
return
inner_create_random_account
if
settings
.
GENERATE_RANDOM_USER_CREDENTIALS
:
create_account
=
create_random_account
(
create_account
)
def
activate_account
(
request
,
key
):
def
activate_account
(
request
,
key
):
r
=
Registration
.
objects
.
filter
(
activation_key
=
key
)
r
=
Registration
.
objects
.
filter
(
activation_key
=
key
)
...
...
settings.py
View file @
3ddddbe5
PERFSTATS
=
False
COURSEWARE_ENABLED
=
True
COURSEWARE_ENABLED
=
True
ASKBOT_ENABLED
=
False
if
'ASKBOT_ENABLED'
not
in
locals
():
ASKBOT_ENABLED
=
True
if
not
COURSEWARE_ENABLED
:
if
not
COURSEWARE_ENABLED
:
ASKBOT_ENABLED
=
False
ASKBOT_ENABLED
=
False
...
@@ -13,6 +10,9 @@ SITE_NAME = "localhost:8000"
...
@@ -13,6 +10,9 @@ SITE_NAME = "localhost:8000"
DEFAULT_FROM_EMAIL
=
'registration@mitx.mit.edu'
DEFAULT_FROM_EMAIL
=
'registration@mitx.mit.edu'
DEFAULT_FEEDBACK_EMAIL
=
'feedback@mitx.mit.edu'
DEFAULT_FEEDBACK_EMAIL
=
'feedback@mitx.mit.edu'
# For testing the login system
GENERATE_RANDOM_USER_CREDENTIALS
=
False
WIKI_REQUIRE_LOGIN_EDIT
=
True
WIKI_REQUIRE_LOGIN_EDIT
=
True
WIKI_REQUIRE_LOGIN_VIEW
=
True
WIKI_REQUIRE_LOGIN_VIEW
=
True
...
...
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