Skip to content

Commit 475bcbb

Browse files
committed
Working django-auth login and logout views. Password import from htpasswd file still needed.
- Legacy-Id: 7536
1 parent 1d246b8 commit 475bcbb

7 files changed

Lines changed: 76 additions & 7 deletions

File tree

ietf/ietfauth/urls.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,15 @@
11
# Copyright The IETF Trust 2007, 2009, All Rights Reserved
22

33
from django.conf.urls import patterns, url
4+
from django.contrib.auth.views import login
45

56
urlpatterns = patterns('ietf.ietfauth.views',
67
url(r'^$', 'index', name='account_index'),
7-
url(r'^login/$', 'ietf_login'),
8+
# url(r'^login/$', 'ietf_login'),
9+
url(r'^login/$', login),
10+
url(r'^logout/$', 'logout_view'),
811
url(r'^loggedin/$', 'ietf_loggedin'),
12+
url(r'^loggedout/$', 'logged_out'),
913
url(r'^profile/$', 'profile'),
1014
# (r'^login/(?P<user>[a-z0-9.@]+)/(?P<passwd>.+)$', 'url_login'),
1115
url(r'^testemail/$', 'test_email'),

ietf/ietfauth/views.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@
4343
from django.contrib.auth import REDIRECT_FIELD_NAME, authenticate, login
4444
from django.contrib.auth.decorators import login_required
4545
from django.contrib.auth.models import User
46+
from django.contrib.auth.views import login, logout
4647
from django.utils.http import urlquote
4748
from django.utils.translation import ugettext as _
4849
from django.core.exceptions import ValidationError
@@ -63,6 +64,7 @@ def url_login(request, user, passwd):
6364
return HttpResponseRedirect('/accounts/loggedin/?%s=%s' % (REDIRECT_FIELD_NAME, urlquote(redirect_to)))
6465
return HttpResponse("Not authenticated?", status=500)
6566

67+
@login_required
6668
def ietf_login(request):
6769
if not request.user.is_authenticated():
6870
return HttpResponse("Not authenticated?", status=500)
@@ -259,3 +261,14 @@ def test_email(request):
259261

260262
return r
261263

264+
def logout_view(request):
265+
try:
266+
logout(request)
267+
return HttpResponseRedirect('/accounts/loggedout/')
268+
except Warning as w:
269+
from ietf.utils.log import log
270+
log(w)
271+
return HttpResponseRedirect('/accounts/loggedout/')
272+
273+
def logged_out(request):
274+
return render_to_response('registration/loggedout.html', {'next':'/'}, context_instance=RequestContext(request))

ietf/settings.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@
9696

9797
DAJAXICE_MEDIA_PREFIX = "dajaxice"
9898

99-
AUTHENTICATION_BACKENDS = ( 'django.contrib.auth.backends.RemoteUserBackend', )
99+
AUTHENTICATION_BACKENDS = ( 'django.contrib.auth.backends.ModelBackend', )
100100

101101
#DATABASE_ROUTERS = ["ietf.legacy_router.LegacyRouter"]
102102

ietf/templates/base.html

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -58,11 +58,17 @@
5858
</div>
5959

6060
{% if user %}
61-
<div id="ietf-login" class="noprint">{% if user.is_authenticated %}
62-
{{ user }}
63-
{% else %}
64-
<a href="https://{{ request.get_host }}/accounts/login/?next={{request.get_full_path|urlencode}}" rel="nofollow">Sign In</a>
65-
{% endif %}</div>
61+
<div id="ietf-login" class="noprint">
62+
{% if request.get_full_path == "/accounts/loggedout/" %}
63+
<a href="https://{{ request.get_host }}/accounts/login/" rel="nofollow">Sign In</a>
64+
{% else %}
65+
{% if user.is_authenticated %}
66+
{{ user }} | <a href="/accounts/logout/">Sign Out</a>
67+
{% else %}
68+
<a href="https://{{ request.get_host }}/accounts/login/?next={{request.get_full_path|urlencode}}" rel="nofollow">Sign In</a>
69+
{% endif %}
70+
{% endif %}
71+
</div>
6672
{% endif %}
6773

6874
{% block start_content_table %}
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
{% extends "registration/base.html" %}
2+
3+
{% block title %}Logged Out{% endblock %}
4+
5+
{% block content %}
6+
<div id="login-pane">
7+
<div id="login-form">
8+
<h1>You have been logged out</h1>
9+
</div>
10+
</div>
11+
{% endblock %}
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
{% extends "registration/base.html" %}
2+
3+
{% block title %}Sign in{% endblock %}
4+
5+
{% block content %}
6+
<div id="login-pane">
7+
<div id="login-form">
8+
<h1>Sign In</h1>
9+
<form action="" method="post">{% csrf_token %}
10+
<table class="login-form">
11+
{{ form }}
12+
</table>
13+
<div class="submit_row">
14+
<input type="submit" value="Sign in" />
15+
</div>
16+
</form>
17+
</div>
18+
</div>
19+
{% endblock %}

static/css/base2.css

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -404,3 +404,19 @@ span.fieldRequired {
404404
margin: 1em 0;
405405
}
406406

407+
408+
#login-pane {
409+
width: 100%;
410+
height: 100%;
411+
// background: rgba(196,196,196,.5);
412+
}
413+
414+
415+
#login-form {
416+
width: 24em;
417+
padding: 2em;
418+
margin-right: auto;
419+
margin-left: auto;
420+
margin-top: 10em;
421+
background: white;
422+
}

0 commit comments

Comments
 (0)