Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Get admin login working

  • Loading branch information...
commit f4909d6bd490bb758200eda634cef1f7bf903e59 1 parent e6708ad
@davedash davedash authored
View
20 apps/myadmin/urls.py
@@ -1,5 +1,10 @@
+from django import http
from django.conf.urls.defaults import patterns, url, include
-from django.contrib import admin
+from django.contrib import admin, auth
+from django.shortcuts import redirect
+
+from funfactory.urlresolvers import reverse
+from session_csrf import anonymous_csrf
from myadmin import views
@@ -8,8 +13,19 @@
url('^recluster/?$', views.recluster, name='myadmin.recluster'),
url('^export_tsv/?$', views.export_tsv, name='myadmin.export_tsv'),
url('^settings/?$', views.settings, name='myadmin.settings'),
-
+ url('^login$', anonymous_csrf(auth.views.login), name='login'),
# The Django admin.
url('^', include(admin.site.urls)),
)
+
+# Hijack the admin's login to use our pages.
+def login(request):
+ # If someone is already auth'd then they're getting directed to login()
+ # because they don't have sufficient permissions.
+ if request.user.is_authenticated():
+ return http.HttpResponseForbidden()
+ else:
+ return redirect('%s?next=%s' % (reverse('login'), request.path))
+
+admin.site.login = login
View
3  settings/base.py
@@ -145,6 +145,9 @@
'django.contrib.messages',
]
+# Removed because this breaks the one user we have for admin.
+INSTALLED_APPS.remove('django_sha2')
+
# Where to store product details
PROD_DETAILS_DIR = path('lib/product_details_json')
View
26 templates/registration/login.html
@@ -0,0 +1,26 @@
+{% extends "base.html" %}
+
+{% block content %}
+
+{% if form.errors %}
+<p>Your username and password didn't match. Please try again.</p>
+{% endif %}
+
+<form method="post" action="{{ url('login') }}">
+{{ csrf() }}
+<table>
+<tr>
+ <td>{{ form.username.label_tag() }}</td>
+ <td>{{ form.username }}</td>
+</tr>
+<tr>
+ <td>{{ form.password.label_tag() }}</td>
+ <td>{{ form.password }}</td>
+</tr>
+</table>
+
+<input type="submit" value="login" />
+<input type="hidden" name="next" value="{{ next }}" />
+</form>
+
+{% endblock %}
Please sign in to comment.
Something went wrong with that request. Please try again.