Permalink
Browse files

initial commit

  • Loading branch information...
0 parents commit a428d82f415cd26241d2f2181f0be8832970f3f7 ojii committed Apr 16, 2010
Showing with 106 additions and 0 deletions.
  1. +4 −0 .gitignore
  2. +24 −0 LICENSE
  3. +1 −0 MANIFEST.in
  4. +1 −0 login_as/__init__.py
  5. +5 −0 login_as/models.py
  6. +25 −0 login_as/templates/login_as/chooser.html
  7. +6 −0 login_as/urls.py
  8. +21 −0 login_as/views.py
  9. +19 −0 setup.py
@@ -0,0 +1,4 @@
+.*project
+*.pyc
+*.egg-info
+dist
24 LICENSE
@@ -0,0 +1,24 @@
+Copyright (c) 2010, Jonas Obrist
+All rights reserved.
+
+Redistribution and use in source and binary forms, with or without
+modification, are permitted provided that the following conditions are met:
+ * Redistributions of source code must retain the above copyright
+ notice, this list of conditions and the following disclaimer.
+ * Redistributions in binary form must reproduce the above copyright
+ notice, this list of conditions and the following disclaimer in the
+ documentation and/or other materials provided with the distribution.
+ * Neither the name of Jonas Obrist nor the
+ names of its contributors may be used to endorse or promote products
+ derived from this software without specific prior written permission.
+
+THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
+ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+DISCLAIMED. IN NO EVENT SHALL JONAS OBRIST BE LIABLE FOR ANY
+DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
+(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
+ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
+SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
@@ -0,0 +1 @@
+recursive-include login_as/templates *
@@ -0,0 +1 @@
+__version__ = '0.0.1'
@@ -0,0 +1,5 @@
+from django.conf import settings
+from django.core.exceptions import ImproperlyConfigured
+
+if not 'django.contrib.auth.backends.RemoteUserBackend' in settings.AUTHENTICATION_BACKENDS:
+ raise ImproperlyConfigured('django-login-as requires the RemoteUserBackend')
@@ -0,0 +1,25 @@
+{% extends "admin/base_site.html" %}
+{% load i18n %}
+
+{% block extrastyle %}{{ block.super }}<link rel="stylesheet" type="text/css" href="{% load adminmedia %}{% admin_media_prefix %}css/dashboard.css" />{% endblock %}
+
+{% block coltype %}colMS{% endblock %}
+
+{% block bodyclass %}dashboard{% endblock %}
+
+{% block breadcrumbs %}{% endblock %}
+
+{% block content %}
+<div id="content-main">
+ <div class="module">
+ <table width="100%">
+ <caption>{% trans "Choose a user to log in as:" %}</caption>
+ {% for user in users %}
+ <tr>
+ <th scope="row"><a href="{% url login-as-login user.pk %}">{{ user.username }}</a></th>
+ </tr>
+ {% endfor %}
+ </table>
+ </div>
+</div>
+{% endblock %}
@@ -0,0 +1,6 @@
+from django.conf.urls.defaults import *
+
+urlpatterns = patterns('login_as.views',
+ url('^$', 'chooser', name='login-as-chooser'),
+ url('^(\d+)/$', 'login', name='login-as-login'),
+)
@@ -0,0 +1,21 @@
+from django.shortcuts import render_to_response, get_object_or_404
+from django.contrib.auth import authenticate, login as auth_login
+from django.contrib.auth.models import User
+from django.http import HttpResponseRedirect, Http404
+
+def chooser(request):
+ if not request.user.is_superuser:
+ raise Http404
+ return render_to_response('login_as/chooser.html',
+ {'users': User.objects.all().order_by('username')})
+
+def login(request, userid):
+ if not request.user.is_superuser:
+ raise Http404
+ original = request.user.pk
+ user = get_object_or_404(User, pk=userid)
+ authed = authenticate(remote_user=user)
+ if not authed:
+ raise Http404
+ auth_login(request, authed)
+ return HttpResponseRedirect('/')
@@ -0,0 +1,19 @@
+from setuptools import setup, find_packages
+
+version = __import__('login_as').__version__
+
+setup(
+ name = 'django-login-as',
+ version = version,
+ description = 'Django Login As any user',
+ author = 'Jonas Obrist',
+ author_email = 'jonas.obrist@divio.ch',
+ url = 'http://github.com/ojii/django-login-as',
+ packages = find_packages(),
+ package_data={
+ 'login_as': [
+ 'templates/login_as/*.html',
+ ]
+ },
+ zip_safe=False,
+)

0 comments on commit a428d82

Please sign in to comment.