Commit a729f686 by Jason Bau

initial, dead simple way to allow superuser to log in as anyone

Conflicts:
	lms/envs/common.py
	lms/urls.py
parent b753641d
......@@ -77,6 +77,19 @@ def csrf_token(context):
' name="csrfmiddlewaretoken" value="%s" /></div>' % (csrf_token))
def superuser_login_as(request, username):
if not request.user.is_superuser:
return HttpResponse('Permission denied')
try:
u1 = User.objects.get(username=username)
u1.backend = 'django.contrib.auth.backends.ModelBackend'
except User.DoesNotExist:
return HttpResponse('User not found')
logout(request)
login(request, u1)
return HttpResponse('You are now logged in as ' + username)
# NOTE: This view is not linked to directly--it is called from
# branding/views.py:index(), which is cached for anonymous users.
# This means that it should always return the same thing for anon
......
......@@ -179,6 +179,9 @@ MITX_FEATURES = {
# Sends the user's deanonymized email address to xqueue with code responses
# DO NOT SET if you don't want the anonymous user id to be linked with user.email in xqueue (Stanford does)
'SEND_USERS_EMAILADDR_WITH_CODERESPONSE': False,
# OP Superusers can log in as anyone
'ENABLE_SUPERUSER_LOGIN_AS': False,
}
# Used for A/B testing
......
......@@ -420,6 +420,10 @@ urlpatterns += (
url(r'^shoppingcart/', include('shoppingcart.urls')),
)
if settings.MITX_FEATURES.get('ENABLE_SUPERUSER_LOGIN_AS'):
urlpatterns += (
url(r'^su_login_as/(?P<username>[\w.@+-]+)/?$', 'student.views.superuser_login_as', name='impersonate'),
)
if settings.MITX_FEATURES.get('AUTH_USE_OPENID_PROVIDER'):
urlpatterns += (
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment