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
ceacc3b4
Commit
ceacc3b4
authored
Jul 16, 2013
by
ihoover
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
moved auto_auth view to students.view and fixed flag conflicts
parent
e5f44165
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
76 additions
and
75 deletions
+76
-75
common/djangoapps/student/views.py
+74
-37
lms/djangoapps/branding/views.py
+0
-36
lms/envs/common.py
+1
-1
lms/urls.py
+1
-1
No files found.
common/djangoapps/student/views.py
View file @
ceacc3b4
...
...
@@ -19,6 +19,7 @@ from django.core.context_processors import csrf
from
django.core.mail
import
send_mail
from
django.core.urlresolvers
import
reverse
from
django.core.validators
import
validate_email
,
validate_slug
,
ValidationError
from
django.core.exceptions
import
ObjectDoesNotExist
from
django.db
import
IntegrityError
,
transaction
from
django.http
import
HttpResponse
,
HttpResponseBadRequest
,
HttpResponseForbidden
,
HttpResponseNotAllowed
,
Http404
from
django.shortcuts
import
redirect
...
...
@@ -674,18 +675,20 @@ def create_account(request, post_override=None):
subject
=
''
.
join
(
subject
.
splitlines
())
message
=
render_to_string
(
'emails/activation_email.txt'
,
d
)
try
:
if
settings
.
MITX_FEATURES
.
get
(
'REROUTE_ACTIVATION_EMAIL'
):
dest_addr
=
settings
.
MITX_FEATURES
[
'REROUTE_ACTIVATION_EMAIL'
]
message
=
(
"Activation for
%
s (
%
s):
%
s
\n
"
%
(
user
,
user
.
email
,
profile
.
name
)
+
'-'
*
80
+
'
\n\n
'
+
message
)
send_mail
(
subject
,
message
,
settings
.
DEFAULT_FROM_EMAIL
,
[
dest_addr
],
fail_silently
=
False
)
elif
not
settings
.
GENERATE_RANDOM_USER_CREDENTIALS
:
res
=
user
.
email_user
(
subject
,
message
,
settings
.
DEFAULT_FROM_EMAIL
)
except
:
log
.
warning
(
'Unable to send activation email to user'
,
exc_info
=
True
)
js
[
'value'
]
=
_
(
'Could not send activation e-mail.'
)
return
HttpResponse
(
json
.
dumps
(
js
))
# dont send email if we are doing load testing or random user generation for some reason
if
not
(
settings
.
GENERATE_RANDOM_USER_CREDENTIALS
or
settings
.
MITX_FEATURES
.
get
(
'AUTOMATIC_AUTH_FOR_LOAD_TESTING'
)):
try
:
if
settings
.
MITX_FEATURES
.
get
(
'REROUTE_ACTIVATION_EMAIL'
):
dest_addr
=
settings
.
MITX_FEATURES
[
'REROUTE_ACTIVATION_EMAIL'
]
message
=
(
"Activation for
%
s (
%
s):
%
s
\n
"
%
(
user
,
user
.
email
,
profile
.
name
)
+
'-'
*
80
+
'
\n\n
'
+
message
)
send_mail
(
subject
,
message
,
settings
.
DEFAULT_FROM_EMAIL
,
[
dest_addr
],
fail_silently
=
False
)
else
:
res
=
user
.
email_user
(
subject
,
message
,
settings
.
DEFAULT_FROM_EMAIL
)
except
:
log
.
warning
(
'Unable to send activation email to user'
,
exc_info
=
True
)
js
[
'value'
]
=
_
(
'Could not send activation e-mail.'
)
return
HttpResponse
(
json
.
dumps
(
js
))
# Immediately after a user creates an account, we log them in. They are only
# logged in until they close the browser. They can't log in again until they click
...
...
@@ -918,25 +921,19 @@ def get_random_post_override():
'honor_code'
:
u'true'
,
'terms_of_service'
:
u'true'
,
}
def
get_planned_post_override
(
username
,
password
):
"""
Return a dictionary suitable for passing to post_vars of _do_create_account or post_override
of create_account, with specified username and password.
"""
def
id_generator
(
size
=
6
,
chars
=
string
.
ascii_uppercase
+
string
.
ascii_lowercase
+
string
.
digits
):
return
''
.
join
(
random
.
choice
(
chars
)
for
x
in
range
(
size
))
return
{
'username'
:
username
,
'email'
:
id_generator
(
size
=
10
,
chars
=
string
.
ascii_lowercase
)
+
"_dummy_test@mitx.mit.edu"
,
'password'
:
password
,
'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'
,
}
def
create_random_account
(
create_account_function
):
def
inner_create_random_account
(
request
):
return
create_account_function
(
request
,
post_override
=
get_random_post_override
())
def
inner_create_random_account
(
request
,
post_override
=
None
):
# This logic ensures that even if we have both
# GENERATE_RANDOM_USER_CREDENTIALS and
# settings.MITX_FEATURES['AUTOMATIC_AUTH_FOR_LOAD_TESTING']
# set to true, then create_account will behave they way
# each feature for automated account generation expects
if
post_override
is
None
:
post_override
=
get_random_post_override
()
return
create_account_function
(
request
,
post_override
)
return
inner_create_random_account
...
...
@@ -944,16 +941,56 @@ def create_random_account(create_account_function):
if
settings
.
GENERATE_RANDOM_USER_CREDENTIALS
:
create_account
=
create_random_account
(
create_account
)
def
create_random_account_with_name_and_password
(
create_account_function
):
def
inner_create_random_account
(
request
,
username
,
password
):
return
create_account_function
(
request
,
post_override
=
get_planned_post_override
(
username
,
password
))
return
inner_create_random_account
def
auto_auth
(
request
):
"""
Automatically logs the user in with a generated random credentials
This view is only accessible when
settings.MITX_SETTINGS['AUTOMATIC_AUTH_FOR_LOAD_TESTING'] is true.
"""
def
get_dummy_post_data
(
username
,
password
):
"""
Return a dictionary suitable for passing to post_vars of _do_create_account or post_override
of create_account, with specified username and password.
"""
return
{
'username'
:
username
,
'email'
:
username
+
"_dummy_test@mitx.mit.edu"
,
'password'
:
password
,
'name'
:
username
+
" "
+
username
,
'honor_code'
:
u'true'
,
'terms_of_service'
:
u'true'
,
}
# generate random user ceredentials from a small name space (determined by settings)
name_base
=
'USER_'
pass_base
=
'PASS_'
max_users
=
200
if
hasattr
(
settings
,
'MAX_AUTO_AUTH_USERS'
):
max_users
=
settings
.
MAX_AUTO_AUTH_USERS
number
=
random
.
randint
(
1
,
max_users
)
username
=
name_base
+
str
(
number
)
password
=
pass_base
+
str
(
number
)
# if they already are a user, log in
try
:
user
=
User
.
objects
.
get
(
username
=
username
)
user
=
authenticate
(
username
=
username
,
password
=
password
)
login
(
request
,
user
)
# else create and activate account info
except
ObjectDoesNotExist
:
post_override
=
get_dummy_post_data
(
username
,
password
)
create_account
(
request
,
post_override
=
post_override
)
request
.
user
.
is_active
=
True
request
.
user
.
save
()
# return empty success
return
HttpResponse
(
''
)
# for load testing we want to create lots of accounts
# with controlled username and password
if
settings
.
MITX_FEATURES
.
get
(
'AUTOMATIC_AUTH_FOR_LOAD_TESTING'
):
create_account
=
create_random_account_with_name_and_password
(
create_account
)
@ensure_csrf_cookie
def
activate_account
(
request
,
key
):
...
...
lms/djangoapps/branding/views.py
View file @
ceacc3b4
...
...
@@ -49,39 +49,3 @@ def courses(request):
return
courseware
.
views
.
courses
(
request
)
return
courseware
.
views
.
university_profile
(
request
,
university
)
def
auto_auth
(
request
):
"""
Automatically logs the user in with a generated random credentials
This view is only accessible when settings.AUTOMATIC_AUTH_FOR_LOAD_TESTING is
true.
"""
from
django.contrib.auth.models
import
User
from
django.contrib.auth
import
login
,
authenticate
from
random
import
randint
# generate random user ceredentials from a small name space (determined by settings)
name_base
=
'USER_'
pass_base
=
'PASS_'
number
=
randint
(
1
,
settings
.
MAX_AUTO_AUTH_USERS
)
username
=
name_base
+
str
(
number
)
password
=
pass_base
+
str
(
number
)
# if they already are a user, log in
try
:
user
=
User
.
objects
.
get
(
username
=
username
)
user
=
authenticate
(
username
=
username
,
password
=
password
)
login
(
request
,
user
)
# else create and activate account info
except
:
student
.
views
.
create_account
(
request
,
username
,
password
)
request
.
user
.
is_active
=
True
request
.
user
.
save
()
# redirect to home-page
return
redirect
(
'root'
)
lms/envs/common.py
View file @
ceacc3b4
...
...
@@ -38,7 +38,7 @@ COURSEWARE_ENABLED = True
ENABLE_JASMINE
=
False
# only relevant if MITX_FEATURES['AUTOMATIC_AUTH_FOR_LOAD_TESTING'] = True
MAX_AUTO_AUTH_USERS
=
20
MAX_AUTO_AUTH_USERS
=
20
0
GENERATE_RANDOM_USER_CREDENTIALS
=
False
PERFSTATS
=
False
...
...
lms/urls.py
View file @
ceacc3b4
...
...
@@ -442,7 +442,7 @@ if settings.DEBUG:
# enable automatic login
if
settings
.
MITX_FEATURES
.
get
(
'AUTOMATIC_AUTH_FOR_LOAD_TESTING'
):
urlpatterns
+=
(
url
(
r'^auto_auth$'
,
'
branding
.views.auto_auth'
),
url
(
r'^auto_auth$'
,
'
student
.views.auto_auth'
),
)
#Custom error pages
...
...
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