[snowy: 2/26] Make OpenID the default way of authenticating



commit db35fedac9a1bb0ccb5a159289b62b4e8cb1d88b
Author: Leon Handreke <leon handreke gmail com>
Date:   Sun Mar 21 22:26:03 2010 +0100

    Make OpenID the default way of authenticating
    
    Add a nice template for OpenID login

 accounts/templates/openid/login.html       |   48 ++++++++++++++++++++++++++++
 accounts/templates/registration/login.html |    2 +
 accounts/urls.py                           |   15 ++++++--
 settings.py                                |    2 +-
 templates/base.html                        |    4 +-
 5 files changed, 64 insertions(+), 7 deletions(-)
---
diff --git a/accounts/templates/openid/login.html b/accounts/templates/openid/login.html
new file mode 100644
index 0000000..1819771
--- /dev/null
+++ b/accounts/templates/openid/login.html
@@ -0,0 +1,48 @@
+{% extends "site_base.html" %}
+
+{% load i18n %}
+
+{% block content %}
+
+<h3>{% trans "Log in with your OpenID" %}</h3>
+
+{% if form.errors %}
+<p class="errors">{% trans "Please correct errors below:" %}<br />
+    {% if form.openid_identifier.errors %} 
+    <span class="error">{{ form.openid_identifier.errors|join:", " }}</span>
+    {% endif %}
+    {% if form.next.errors %} 
+    <span class="error">{{ form.next.errors|join:", " }}</span>
+    {% endif %}
+</p>
+{% endif %}
+
+<form name="fopenid" action="{{ action }}" method="post">
+    <table>
+        <tr>
+            <td style="width: 100px;"><b>{% trans "OpenID:"%}</b></td>
+            <td>{{ form.openid_identifier }}</td>
+        </tr>
+    </table>
+    <input name="bsignin" type="submit" value="{% trans "Log in with your OpenID" %}"></div>
+
+    {% if next %}
+    <input type="hidden" name="next" value="{{ next }}" />
+    {% endif %}
+</form>	
+<br />
+<div>{% trans "Don't have an OpenID yet? Get one " %}<a href="http://openid.net/get-an-openid/"; alt="Get an OpenID">{% trans "here!" %}</a></div>
+
+<small>{% trans "Or " %} <a href="{% url auth_login %}">{% trans "log in the old way" %}</a>{% trans "." %}</small>
+{% endblock %}
+
+
+
+
+<!--<style type="text/css">
+input.openid {
+  background: url({% url openid-logo %}) no-repeat; 
+  background-position: 0 50%;
+  padding-left: 16px;
+}
+</style>-->
diff --git a/accounts/templates/registration/login.html b/accounts/templates/registration/login.html
index 3b6d02c..33a5fbc 100644
--- a/accounts/templates/registration/login.html
+++ b/accounts/templates/registration/login.html
@@ -25,5 +25,7 @@
 <input type="hidden" name="next" value="{{ next }}" />
 {% endif %}
 </form>
+
+<p><small>{% trans "not a member yet?" %} <a href="{% url registration.views.register %}">{% trans "Sign up." %}</a></small></p>
 {% endblock %}
 
diff --git a/accounts/urls.py b/accounts/urls.py
index e9828ec..26c6321 100644
--- a/accounts/urls.py
+++ b/accounts/urls.py
@@ -24,16 +24,21 @@ from django.conf.urls.defaults import *
 from registration.views import activate
 from registration.views import register
 
+import django_openid_auth.views
+
 urlpatterns = patterns('',
     url(r'^preferences/$', 'snowy.accounts.views.accounts_preferences',
         name='preferences'),
 
-    # Registration URLs
-    url(r'^activate/(?P<activation_key>\w+)/$', activate, name='registration_activate'),
-    url(r'^login/$', auth_views.login, {'template_name': 'registration/login.html'},
-        name='auth_login'),
     url(r'^logout/$', auth_views.logout, {'template_name': 'registration/logout.html'},
         name='auth_logout'),
+
+    # OpenID URLs
+    url(r'^openid/login/$', django_openid_auth.views.login_begin,
+        {'template_name': 'openid/login.html'}, name='openid_login'),
+    
+    # Registration URLs
+    url(r'^activate/(?P<activation_key>\w+)/$', activate, name='registration_activate'),
     url(r'^password/change/$', auth_views.password_change, name='auth_password_change'),
     url(r'^password/change/done/$', auth_views.password_change_done,
         name='auth_password_change_done'),
@@ -44,6 +49,8 @@ urlpatterns = patterns('',
         name='auth_password_reset_complete'),
     url(r'^password/reset/done/$', auth_views.password_reset_done,
         name='auth_password_reset_done'),
+    url(r'^register/login/$', auth_views.login, {'template_name': 'registration/login.html'},
+        name='auth_login'),
     url(r'^register/$', register, {'form_class': RegistrationFormUniqueUser},
         name='registration_register'),
     url(r'^register/complete/$', direct_to_template,
diff --git a/settings.py b/settings.py
index e3cfc84..b937fd5 100644
--- a/settings.py
+++ b/settings.py
@@ -148,7 +148,7 @@ OPENID_CREATE_USERS = True
 OPENID_UPDATE_DETAILS_FROM_SREG = True
 
 LOGIN_REDIRECT_URL = '/'
-LOGIN_URL = '/openid/login/'
+LOGIN_URL = '/accounts/openid/login/'
 
 # local_settings.py can be used to override environment-specific settings
 # like database and email that differ between development and production.
diff --git a/templates/base.html b/templates/base.html
index a961ff3..0e48f95 100644
--- a/templates/base.html
+++ b/templates/base.html
@@ -33,8 +33,8 @@
                     <h3>{{ user }}</h3>
                     <p><a href="{% url preferences %}">{% trans "preferences" %}</a> / <a href="{% url django.contrib.auth.views.logout %}">{% trans "log out" %}</a></p>
 {% else %}
-                    <p>{% trans "hello stranger! care to " %}<a href="{% url django.contrib.auth.views.login %}">{% trans "log in" %}</a>{% trans "?" %}</p>
-                    <p><small>{% trans "not a member yet?" %} <a href="{% url registration.views.register %}">{% trans "Sign up." %}</a></small></p>
+                    <p>{% trans "hello stranger! care to " %}<a href="{% url openid_login %}">{% trans "log in" %}</a>{% trans "?" %}</p>
+                    <!--<p><small>{% trans "not a member yet?" %} <a href="{% url registration.views.register %}">{% trans "Sign up." %}</a></small></p>-->
 {% endif %}
                 </td>
                 <td id="header-avatar">



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]