Initial authentication work

This commit is contained in:
Correl Roush 2010-12-08 08:28:57 -05:00
parent 8183b0c928
commit 44bab4989a
5 changed files with 39 additions and 0 deletions

View file

@ -1,6 +1,7 @@
import os import os
from django.http import Http404 from django.http import Http404
from django.shortcuts import render_to_response from django.shortcuts import render_to_response
from django.contrib.auth.decorators import permission_required
from codereview.dashboard.models import Repository from codereview.dashboard.models import Repository
from codereview.browser import vcs from codereview.browser import vcs
@ -37,12 +38,14 @@ def _log_data(request, repo, ref, path=None):
'newer': newer, 'newer': newer,
'older': older, 'older': older,
} }
@permission_required('dashboard.browse')
def log(request, repository, path=None): def log(request, repository, path=None):
repo, ref = _repo(request, repository) repo, ref = _repo(request, repository)
data = {'repository': repository} data = {'repository': repository}
data.update(_log_data(request, repo, ref, path)) data.update(_log_data(request, repo, ref, path))
data.update(_nav_data(request, repo, ref, path)) data.update(_nav_data(request, repo, ref, path))
return render_to_response('browser/log.html', data) return render_to_response('browser/log.html', data)
@permission_required('dashboard.browse')
def commit(request, repository, ref): def commit(request, repository, ref):
try: try:
repository = Repository.objects.get(name=repository) repository = Repository.objects.get(name=repository)
@ -60,6 +63,7 @@ def commit(request, repository, ref):
'commit': commit, 'commit': commit,
'diffs': diffs, 'diffs': diffs,
}) })
@permission_required('dashboard.browse')
def blob(request, repository, path): def blob(request, repository, path):
repo, ref = _repo(request, repository) repo, ref = _repo(request, repository)
data = { data = {

View file

@ -5,5 +5,10 @@ class Repository(models.Model):
path = models.CharField(max_length=255) path = models.CharField(max_length=255)
type = models.IntegerField(default=0) type = models.IntegerField(default=0)
class Meta:
permissions = (
("browse", "Browse repositories"),
)
def __unicode__(self): def __unicode__(self):
return self.name return self.name

5
dashboard/urls.py Normal file
View file

@ -0,0 +1,5 @@
from django.conf.urls.defaults import *
urlpatterns = patterns('',
(r'^login/$', 'django.contrib.auth.views.login'),
)

View file

@ -0,0 +1,23 @@
{% extends "layouts/default.html" %}
{% block content %}
{% if form.errors %}
<p>Username or password is incorrect</p>
{% endif %}
<form method="post" action="{% url django.contrib.auth.views.login %}">
{% csrf_token %}
<fieldset>
<dl>
<dt>{{ form.username.label_tag }}</dt>
<dd>{{ form.username }}</dd>
<dt>{{ form.password.label_tag }}</dt>
<dd>{{ form.password }}</dd>
</dl>
<input type="submit" value="Login" />
<input type="hidden" name="next" value="{{ next }}" />
</fieldset>
</form>
{% endblock %}

View file

@ -10,6 +10,8 @@ urlpatterns = patterns('',
(r'^$', 'codereview.dashboard.views.index'), (r'^$', 'codereview.dashboard.views.index'),
(r'^browser/', include('codereview.browser.urls')), (r'^browser/', include('codereview.browser.urls')),
(r'^dashboard/', include('codereview.dashboard.urls')),
# Uncomment the admin/doc line below and add 'django.contrib.admindocs' # Uncomment the admin/doc line below and add 'django.contrib.admindocs'
# to INSTALLED_APPS to enable admin documentation: # to INSTALLED_APPS to enable admin documentation:
# (r'^admin/doc/', include('django.contrib.admindocs.urls')), # (r'^admin/doc/', include('django.contrib.admindocs.urls')),