From 44bab4989a812ae0d32199debb8b3d436947ae7b Mon Sep 17 00:00:00 2001 From: Correl Roush Date: Wed, 8 Dec 2010 08:28:57 -0500 Subject: [PATCH] Initial authentication work --- browser/views.py | 4 ++++ dashboard/models.py | 5 +++++ dashboard/urls.py | 5 +++++ templates/registration/login.html | 23 +++++++++++++++++++++++ urls.py | 2 ++ 5 files changed, 39 insertions(+) create mode 100644 dashboard/urls.py create mode 100644 templates/registration/login.html diff --git a/browser/views.py b/browser/views.py index 7c1d55a..307dbfe 100755 --- a/browser/views.py +++ b/browser/views.py @@ -1,6 +1,7 @@ import os from django.http import Http404 from django.shortcuts import render_to_response +from django.contrib.auth.decorators import permission_required from codereview.dashboard.models import Repository from codereview.browser import vcs @@ -37,12 +38,14 @@ def _log_data(request, repo, ref, path=None): 'newer': newer, 'older': older, } +@permission_required('dashboard.browse') def log(request, repository, path=None): repo, ref = _repo(request, repository) data = {'repository': repository} data.update(_log_data(request, repo, ref, path)) data.update(_nav_data(request, repo, ref, path)) return render_to_response('browser/log.html', data) +@permission_required('dashboard.browse') def commit(request, repository, ref): try: repository = Repository.objects.get(name=repository) @@ -60,6 +63,7 @@ def commit(request, repository, ref): 'commit': commit, 'diffs': diffs, }) +@permission_required('dashboard.browse') def blob(request, repository, path): repo, ref = _repo(request, repository) data = { diff --git a/dashboard/models.py b/dashboard/models.py index 0826503..077b366 100755 --- a/dashboard/models.py +++ b/dashboard/models.py @@ -5,5 +5,10 @@ class Repository(models.Model): path = models.CharField(max_length=255) type = models.IntegerField(default=0) + class Meta: + permissions = ( + ("browse", "Browse repositories"), + ) + def __unicode__(self): return self.name diff --git a/dashboard/urls.py b/dashboard/urls.py new file mode 100644 index 0000000..ed2bbb1 --- /dev/null +++ b/dashboard/urls.py @@ -0,0 +1,5 @@ +from django.conf.urls.defaults import * + +urlpatterns = patterns('', + (r'^login/$', 'django.contrib.auth.views.login'), +) diff --git a/templates/registration/login.html b/templates/registration/login.html new file mode 100644 index 0000000..1d107a2 --- /dev/null +++ b/templates/registration/login.html @@ -0,0 +1,23 @@ +{% extends "layouts/default.html" %} + +{% block content %} + +{% if form.errors %} +

Username or password is incorrect

+{% endif %} + +
+ {% csrf_token %} +
+
+
{{ form.username.label_tag }}
+
{{ form.username }}
+
{{ form.password.label_tag }}
+
{{ form.password }}
+
+ + +
+
+ +{% endblock %} diff --git a/urls.py b/urls.py index 5411d6f..666995f 100755 --- a/urls.py +++ b/urls.py @@ -10,6 +10,8 @@ urlpatterns = patterns('', (r'^$', 'codereview.dashboard.views.index'), (r'^browser/', include('codereview.browser.urls')), + (r'^dashboard/', include('codereview.dashboard.urls')), + # Uncomment the admin/doc line below and add 'django.contrib.admindocs' # to INSTALLED_APPS to enable admin documentation: # (r'^admin/doc/', include('django.contrib.admindocs.urls')),