Working django-auth login and logout views. Password import from htpasswd file still needed.
- Legacy-Id: 7536
This commit is contained in:
parent
1d246b8b1f
commit
475bcbbd30
|
@ -1,11 +1,15 @@
|
|||
# Copyright The IETF Trust 2007, 2009, All Rights Reserved
|
||||
|
||||
from django.conf.urls import patterns, url
|
||||
from django.contrib.auth.views import login
|
||||
|
||||
urlpatterns = patterns('ietf.ietfauth.views',
|
||||
url(r'^$', 'index', name='account_index'),
|
||||
url(r'^login/$', 'ietf_login'),
|
||||
# url(r'^login/$', 'ietf_login'),
|
||||
url(r'^login/$', login),
|
||||
url(r'^logout/$', 'logout_view'),
|
||||
url(r'^loggedin/$', 'ietf_loggedin'),
|
||||
url(r'^loggedout/$', 'logged_out'),
|
||||
url(r'^profile/$', 'profile'),
|
||||
# (r'^login/(?P<user>[a-z0-9.@]+)/(?P<passwd>.+)$', 'url_login'),
|
||||
url(r'^testemail/$', 'test_email'),
|
||||
|
|
|
@ -43,6 +43,7 @@ from django.shortcuts import render_to_response
|
|||
from django.contrib.auth import REDIRECT_FIELD_NAME, authenticate, login
|
||||
from django.contrib.auth.decorators import login_required
|
||||
from django.contrib.auth.models import User
|
||||
from django.contrib.auth.views import login, logout
|
||||
from django.utils.http import urlquote
|
||||
from django.utils.translation import ugettext as _
|
||||
from django.core.exceptions import ValidationError
|
||||
|
@ -63,6 +64,7 @@ def url_login(request, user, passwd):
|
|||
return HttpResponseRedirect('/accounts/loggedin/?%s=%s' % (REDIRECT_FIELD_NAME, urlquote(redirect_to)))
|
||||
return HttpResponse("Not authenticated?", status=500)
|
||||
|
||||
@login_required
|
||||
def ietf_login(request):
|
||||
if not request.user.is_authenticated():
|
||||
return HttpResponse("Not authenticated?", status=500)
|
||||
|
@ -259,3 +261,14 @@ def test_email(request):
|
|||
|
||||
return r
|
||||
|
||||
def logout_view(request):
|
||||
try:
|
||||
logout(request)
|
||||
return HttpResponseRedirect('/accounts/loggedout/')
|
||||
except Warning as w:
|
||||
from ietf.utils.log import log
|
||||
log(w)
|
||||
return HttpResponseRedirect('/accounts/loggedout/')
|
||||
|
||||
def logged_out(request):
|
||||
return render_to_response('registration/loggedout.html', {'next':'/'}, context_instance=RequestContext(request))
|
||||
|
|
|
@ -96,7 +96,7 @@ WSGI_APPLICATION = "ietf.wsgi.application"
|
|||
|
||||
DAJAXICE_MEDIA_PREFIX = "dajaxice"
|
||||
|
||||
AUTHENTICATION_BACKENDS = ( 'django.contrib.auth.backends.RemoteUserBackend', )
|
||||
AUTHENTICATION_BACKENDS = ( 'django.contrib.auth.backends.ModelBackend', )
|
||||
|
||||
#DATABASE_ROUTERS = ["ietf.legacy_router.LegacyRouter"]
|
||||
|
||||
|
|
|
@ -58,11 +58,17 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|||
</div>
|
||||
|
||||
{% if user %}
|
||||
<div id="ietf-login" class="noprint">{% if user.is_authenticated %}
|
||||
{{ user }}
|
||||
{% else %}
|
||||
<a href="https://{{ request.get_host }}/accounts/login/?next={{request.get_full_path|urlencode}}" rel="nofollow">Sign In</a>
|
||||
{% endif %}</div>
|
||||
<div id="ietf-login" class="noprint">
|
||||
{% if request.get_full_path == "/accounts/loggedout/" %}
|
||||
<a href="https://{{ request.get_host }}/accounts/login/" rel="nofollow">Sign In</a>
|
||||
{% else %}
|
||||
{% if user.is_authenticated %}
|
||||
{{ user }} | <a href="/accounts/logout/">Sign Out</a>
|
||||
{% else %}
|
||||
<a href="https://{{ request.get_host }}/accounts/login/?next={{request.get_full_path|urlencode}}" rel="nofollow">Sign In</a>
|
||||
{% endif %}
|
||||
{% endif %}
|
||||
</div>
|
||||
{% endif %}
|
||||
|
||||
{% block start_content_table %}
|
||||
|
|
11
ietf/templates/registration/loggedout.html
Normal file
11
ietf/templates/registration/loggedout.html
Normal file
|
@ -0,0 +1,11 @@
|
|||
{% extends "registration/base.html" %}
|
||||
|
||||
{% block title %}Logged Out{% endblock %}
|
||||
|
||||
{% block content %}
|
||||
<div id="login-pane">
|
||||
<div id="login-form">
|
||||
<h1>You have been logged out</h1>
|
||||
</div>
|
||||
</div>
|
||||
{% endblock %}
|
19
ietf/templates/registration/login.html
Normal file
19
ietf/templates/registration/login.html
Normal file
|
@ -0,0 +1,19 @@
|
|||
{% extends "registration/base.html" %}
|
||||
|
||||
{% block title %}Sign in{% endblock %}
|
||||
|
||||
{% block content %}
|
||||
<div id="login-pane">
|
||||
<div id="login-form">
|
||||
<h1>Sign In</h1>
|
||||
<form action="" method="post">{% csrf_token %}
|
||||
<table class="login-form">
|
||||
{{ form }}
|
||||
</table>
|
||||
<div class="submit_row">
|
||||
<input type="submit" value="Sign in" />
|
||||
</div>
|
||||
</form>
|
||||
</div>
|
||||
</div>
|
||||
{% endblock %}
|
|
@ -404,3 +404,19 @@ span.fieldRequired {
|
|||
margin: 1em 0;
|
||||
}
|
||||
|
||||
|
||||
#login-pane {
|
||||
width: 100%;
|
||||
height: 100%;
|
||||
// background: rgba(196,196,196,.5);
|
||||
}
|
||||
|
||||
|
||||
#login-form {
|
||||
width: 24em;
|
||||
padding: 2em;
|
||||
margin-right: auto;
|
||||
margin-left: auto;
|
||||
margin-top: 10em;
|
||||
background: white;
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue