Commit 034456cb authored by Claude Paroz's avatar Claude Paroz Committed by Claude Paroz

Add note about OpenID optional support. site_login view handles the login

2008-11-22  Claude Paroz  <claude@2xlibre.net>

	* README: Add note about OpenID optional support.
	* common/views.py: site_login view handles the login process.
	* media/css/login.css: New css specific to login.html.
	* media/css/main.css: Add errornote style for showing messages.
	* settings_sample.py: Add LOGIN_URL variable (may be used by
	login_required decorator).
	* languages/views.py:
	* stats/views.py:
	* teams/views.py: Use more complete RequestContext to be able to access
	user variable in templates.
	* templates/base.html: Add support for showing user messages and for
	adding extra headers (css, js, etc.).
	* templates/login.html: New template for login.
	* urls.py: Add login view.

svn path=/trunk/; revision=1184
parent 2e2979f5
2008-11-22 Claude Paroz <claude@2xlibre.net>
* README: Add note about OpenID optional support.
* common/views.py: site_login view handles the login process.
* media/css/login.css: New css specific to login.html.
* media/css/main.css: Add errornote style for showing messages.
* settings_sample.py: Add LOGIN_URL variable (may be used by
login_required decorator).
* languages/views.py:
* stats/views.py:
* teams/views.py: Use more complete RequestContext to be able to access
user variable in templates.
* templates/base.html: Add support for showing user messages and for
adding extra headers (css, js, etc.).
* templates/login.html: New template for login.
* urls.py: Add login view.
2008-11-22 Claude Paroz <claude@2xlibre.net>
* common/views.py: Use RequestContext to be able to access user object in
......
......@@ -45,6 +45,15 @@ Installation
4 - Configure Sites in admin interface to define the 'View on site'
link.
OpenID support
==============
If you want OpenID support, checkout Simon Willison's django_openid
package (WIP, part of django-openid, not confuse!):
svn co http://django-openid.googlecode.com/svn/trunk/django_openid
Put it somewhere in your Python path and uncomment 'django_openid' in your
settings.py INSTALLED_APPS.
Run 'python manage.py syncdb' and here we go!
Databases
=========
......
......@@ -19,8 +19,13 @@
# 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
from django.shortcuts import render_to_response
from django.http import HttpResponseRedirect
from django.core.urlresolvers import reverse
from django.template import RequestContext
from django.utils.translation import ugettext_lazy as _
from django.utils.translation import ugettext as _
from django.contrib.auth import login, authenticate, logout
from django.conf import settings
def index(request):
translator_credits = _("translator-credits")
......@@ -35,3 +40,42 @@ def index(request):
'translator_credits': translator_credits
}
return render_to_response('index.html', context, context_instance=RequestContext(request))
def site_login(request):
""" Site-specific login page. Not named 'login' to not confuse with auth.login """
messages = []
referer = None
openid_path = ''
if request.method == 'POST':
if request.POST.has_key('logout') and request.POST['logout']:
logout(request)
messages.append(_("You have been logged out."))
elif request.POST.has_key('username'):
username = request.POST['username']
password = request.POST['password']
user = authenticate(username=username, password=password)
if user is not None:
if user.is_active:
login(request, user)
message = _("You have been successfully logged in.")
user.message_set.create(message=message)
if request.POST['referer']:
return HttpResponseRedirect(request.POST['referer'])
else:
return HttpResponseRedirect(reverse("home"))
else:
messages.append(_("We're sorry, but your account has been disabled."))
else:
messages.append(_("Login unsuccessful. Please verify your username and password."))
else:
referer = request.META.get('HTTP_REFERER', None)
if 'django_openid' in settings.INSTALLED_APPS:
openid_path = '/openid/'
context = {
'pageSection': 'home',
'openid_path': openid_path,
'messages': messages,
'referer': referer,
}
return render_to_response('login.html', context, context_instance=RequestContext(request))
......@@ -23,6 +23,7 @@ import os
import tarfile
from datetime import date, datetime
from django.shortcuts import render_to_response, get_object_or_404
from django.template import RequestContext
from django.http import HttpResponse, HttpResponseRedirect
from stats.conf import settings
from common import utils
......@@ -35,7 +36,7 @@ def languages(request):
'pageSection': "languages",
'languages': utils.trans_sort_object_list(languages, 'name')
}
return render_to_response('languages/language_list.html', context)
return render_to_response('languages/language_list.html', context, context_instance=RequestContext(request))
def language_release(request, locale, release_name):
language = get_object_or_404(Language, locale=Language.unslug_locale(locale))
......@@ -47,7 +48,7 @@ def language_release(request, locale, release_name):
'release': release,
'stats': stats
}
return render_to_response('languages/language_release.html', context)
return render_to_response('languages/language_release.html', context, context_instance=RequestContext(request))
def language_release_tar(request, locale, release_name, dtype):
release = get_object_or_404(Release, name=release_name)
......
/* LOGIN FORM */
.login #container { background:white; border:1px solid #ccc; width:28em; min-width:300px; margin-left:auto; margin-right:auto; margin-top:100px; }
.login #content-main { width:100%; }
.login form { margin-top:1em; }
.login .form-row { padding:4px 0; float:left; width:100%; }
.login .form-row label { float:left; width:11em; padding-right:0.5em; line-height:1.1em; text-align:right; font-size:1em; color:#333; }
.login .form-row #id_username, .login .form-row #id_password { width:14em; }
.login .submit-row { clear:both; padding:1em 0 0 11.4em; }
......@@ -123,6 +123,7 @@ div.mainpage {
div#authenticated {
text-align: right;
margin-right: 4px;
font-size: small;
font-style: italic;
color: #aaaaaa;
......@@ -148,6 +149,12 @@ p#show, p#hide {
color: #666666;
}
.errornote {
border: 1px solid;
padding: 5px;
background: #FAE28E;
}
.footnote {
text-align: center;
font-size: small;
......
......@@ -69,6 +69,8 @@ MEDIA_URL = 'media'
# Examples: "http://foo.com/media/", "/media/".
ADMIN_MEDIA_PREFIX = '/media/admin/'
LOGIN_URL = '/login/'
# Make this unique, and don't share it with anybody.
SECRET_KEY = 'zk!^92901p458c8lo0(fox-&k7jj(aple76_k%eva7b1)xjo8-'
......@@ -98,6 +100,7 @@ INSTALLED_APPS = (
'django.contrib.sessions',
'django.contrib.sites',
'django.contrib.admin',
# 'django_openid',
'languages',
'people',
'stats',
......
......@@ -21,9 +21,10 @@
from django.shortcuts import render_to_response, get_object_or_404
from stats.models import Statistics, Module, Release
from stats.conf import settings
from djamnedlies.stats import utils
from stats import utils
from django.core import serializers
from django.http import HttpResponse
from django.template import RequestContext
from django.utils.translation import ugettext_lazy as _
MIME_TYPES = {'json': 'application/json',
......@@ -35,7 +36,7 @@ def modules(request):
'pageSection': "module",
'modules': utils.sortObjectList(all_modules, 'get_description')
}
return render_to_response('module_list.html', context)
return render_to_response('module_list.html', context, context_instance=RequestContext(request))
def module(request, module_name):
mod = get_object_or_404(Module, name=module_name)
......@@ -44,7 +45,7 @@ def module(request, module_name):
'module': mod,
'prof': utils.Profiler()
}
return render_to_response('module.html', context)
return render_to_response('module.html', context, context_instance=RequestContext(request))
def docimages(request, module_name, potbase, branch_name, langcode):
mod = get_object_or_404(Module, name=module_name)
......@@ -58,7 +59,7 @@ def docimages(request, module_name, potbase, branch_name, langcode):
'module': mod,
'stat': stat
}
return render_to_response('module_images.html', context)
return render_to_response('module_images.html', context, context_instance=RequestContext(request))
def releases(request, format='html'):
all_releases = Release.objects.order_by('status', '-name')
......@@ -70,7 +71,7 @@ def releases(request, format='html'):
'pageSection': "releases",
'releases': all_releases
}
return render_to_response('release_list.html', context)
return render_to_response('release_list.html', context, context_instance=RequestContext(request))
def release(request, release_name):
rel = get_object_or_404(Release, name=release_name)
......@@ -78,5 +79,5 @@ def release(request, release_name):
'pageSection': "releases",
'release': rel
}
return render_to_response('release.html', context)
return render_to_response('release.html', context, context_instance=RequestContext(request))
......@@ -20,6 +20,7 @@
# 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
from django.shortcuts import render_to_response, get_object_or_404
from django.template import RequestContext
from common import utils
from teams.models import Team, FakeTeam
from languages.models import Language
......@@ -31,7 +32,7 @@ def teams(request):
'pageSection': 'teams',
'teams': utils.trans_sort_object_list(teams, 'description')
}
return render_to_response('teams/team_list.html', context)
return render_to_response('teams/team_list.html', context, context_instance=RequestContext(request))
def team(request, team_slug):
try:
......@@ -44,5 +45,5 @@ def team(request, team_slug):
'pageSection': 'teams',
'team': team
}
return render_to_response('teams/team_detail.html', context)
return render_to_response('teams/team_detail.html', context, context_instance=RequestContext(request))
......@@ -15,6 +15,8 @@
<link rel="stylesheet" href="/media/css/rtl.css"/>
{% endif %}
<script src="/media/js/main.js" type="text/javascript"></script>
{% block extrahead %}
{% endblock %}
</head>
<body>
......@@ -80,11 +82,19 @@
<div id="authenticated">
{% if user.is_authenticated %}
{% blocktrans with user.username as username %} Logged in as: {{ username }}{% endblocktrans %}
{% else %}
<!-- Not useful right now <a href="{% url login %}">{% trans "Login" %}</a> -->
{% endif %}
</div>
<div class="body">
<div id="content">
{% if messages %}
{% for message in messages %}
<p class="errornote">{{ message }}</p>
{% endfor %}
{% endif %}
{% block content %}
{% endblock %}
</div>
......
{% extends "base.html" %}
{% load i18n %}
{% block title %} {% trans "Damned Lies about GNOME" %} {% endblock %}
{% block extrahead %} <link rel="stylesheet" href="/media/css/login.css"/> {% endblock %}
{% block content %}
<div class="mainpage">
{% if user.is_authenticated %}
<p>{% blocktrans with user.username as username %}You are already logged in as {{ username }}.{% endblocktrans %}</p>
<form action="" method="post">
<input type="hidden" name="logout" value="1" />
<div class="submit-row">
<label>&nbsp;</label><input type="submit" value="{% trans 'Log out' %}" />
</div>
</form>
{% else %}
<p>{% trans 'Log in with your username and password:' %}</p>
<form action="{{ app_path }}" method="post" id="login-form" class="login">
<div class="form-row">
<label for="id_username">{% trans 'Username:' %}</label> <input type="text" name="username" id="id_username" />
</div>
<div class="form-row">
<label for="id_password">{% trans 'Password:' %}</label> <input type="password" name="password" id="id_password" />
<input type="hidden" name="this_is_the_login_form" value="1" />
<input type="hidden" name="post_data" value="{{ post_data }}" />
<input type="hidden" name="referer" value="{{ referer|default:"" }}" />
</div>
<div class="submit-row">
<label>&nbsp;</label><input type="submit" value="{% trans 'Log in' %}" />
</div>
</form>
{% if openid_path %}
<p>{% trans 'Or use your OpenID:' %}</p>
<form action="{{ openid_path }}" method="post" id="openid-login-form" class="login">
<div class="form-row">
<label for="id_openid"><img src="{{ openid_path }}logo/" alt=""> {% trans 'OpenID:' %}</label> <input type="text" name="openid_url" id="id_openid" />
</div>
<div class="submit-row">
<label>&nbsp;</label><input type="submit" value="{% trans 'Log in with OpenID' %}" />
</div>
</form>
{% endif %}
<script type="text/javascript">
document.getElementById('id_username').focus()
</script>
{% endif %}
</div>
{% endblock %}
......@@ -7,6 +7,7 @@ admin.autodiscover()
urlpatterns = patterns('',
url(r'^$', 'common.views.index', name='home'),
url(r'^login/$', 'common.views.site_login', name='login'),
(r'^teams/', include('teams.urls')),
(r'^people/', include('people.urls')),
(r'^languages/', include('languages.urls')),
......
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