[damned-lies] Migrate openid library used
- From: Claude Paroz <claudep src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [damned-lies] Migrate openid library used
- Date: Tue, 19 Apr 2011 16:19:56 +0000 (UTC)
commit 06545fed99f1287fda70308f2bfe3c1f7f3687c1
Author: Claude Paroz <claude 2xlibre net>
Date: Tue Apr 19 18:17:16 2011 +0200
Migrate openid library used
django-openid is not actively maintained. Apparently, django-openid-auth
is a fork by Canonical, more polished.
Embedded django-openid is left in the tree for the migration duration.
README | 17 +++++++++-----
common/migrations/0001_openid_migration.py | 34 ++++++++++++++++++++++++++++
common/views.py | 7 +++--
settings.py | 11 ++++++++-
templates/login.html | 5 +++-
urls.py | 6 +---
6 files changed, 65 insertions(+), 15 deletions(-)
---
diff --git a/README b/README
index 41229b2..9e34426 100644
--- a/README
+++ b/README
@@ -37,7 +37,7 @@ Requirements
git clone git://github.com/dcramer/django-debug-toolbar.git
Define USE_DEBUG_TOOLBAR to True in local_settings.py to use it.
-8 - [Optional] python-openid and django-openid (see OpenID support
+8 - [Optional] python-openid and django-openid-auth (see OpenID support
below).
9 - [Optional] python-pyicu for correct sorting in various languages
@@ -83,17 +83,22 @@ It might be useful to add the command in a cron schedule.
OpenID support
==============
-If you want OpenID support, checkout Simon Willison's django-openid
-package:
+If you want OpenID support, install django-openid-auth package:
-git clone git://github.com/simonw/django-openid.git
+http://pypi.python.org/pypi/django-openid-auth/
-Put it somewhere in your Python path and set USE_DJANGO_OPENID to True in your
-local_settings.py.
+Set USE_DJANGO_OPENID to True in your local_settings.py.
This package is dependant on the python-openid package to be installed
on your system. Run 'python manage.py syncdb' and here we go!
+Note: if you are using MySQL, you should modify a table column in models.py
+of django-openid-auth:
+Change:
+ claimed_id = models.TextField(max_length=2047, unique=True)
+To:
+ claimed_id = models.CharField(max_length=255, unique=True)
+See bug http://code.djangoproject.com/ticket/2495
Databases
=========
diff --git a/common/migrations/0001_openid_migration.py b/common/migrations/0001_openid_migration.py
new file mode 100644
index 0000000..e7f6943
--- /dev/null
+++ b/common/migrations/0001_openid_migration.py
@@ -0,0 +1,34 @@
+# encoding: utf-8
+import datetime
+from south.db import db
+from south.v2 import DataMigration
+from django.db import models
+
+class Migration(DataMigration):
+
+ def forwards(self, orm):
+ "Write your forwards methods here."
+ try:
+ from django_openid import models
+ from django_openid_auth import models as new_models
+ except ImportError:
+ # skip migration
+ pass # return
+ import pdb; pdb.set_trace()
+ """for nonce in models.Nonce.objects.all():
+ new_nonce = new_models.Nonce.objects.create(server_url=nonce.server_url, timestamp=nonce.timestamp, salt=nonce.salt)
+ for assoc in models.Association.objects.all():
+ new_assoc = new_models.Association.objects.create(server_url=assoc.server_url, handle=assoc.handle, secret=assoc.secret, issued=assoc.issued, lifetime=assoc.lifetime, assoc_type=assoc.assoc_type)"""
+ for user_assoc in models.UserOpenidAssociation.objects.all():
+ new_uassoc = new_models.UserOpenID.objects.create(user=user_assoc.user, claimed_id=user_assoc.openid, display_id=user_assoc.openid)
+
+
+ def backwards(self, orm):
+ "Write your backwards methods here."
+
+
+ models = {
+
+ }
+
+ complete_apps = ['common']
diff --git a/common/migrations/__init__.py b/common/migrations/__init__.py
new file mode 100644
index 0000000..e69de29
diff --git a/common/views.py b/common/views.py
index 07cf464..d083f69 100644
--- a/common/views.py
+++ b/common/views.py
@@ -82,12 +82,13 @@ def site_login(request):
else:
referer = request.META.get('HTTP_REFERER', None)
- if 'django_openid' in settings.INSTALLED_APPS:
- openid_path = '/openid/'
+ if 'django_openid_auth' in settings.INSTALLED_APPS:
+ openid_path = '/openid/login/'
context = {
'pageSection': 'home',
'openid_path': openid_path,
'referer': referer,
+ 'next': referer,
}
return render_to_response('login.html', context, context_instance=RequestContext(request))
@@ -100,7 +101,7 @@ def site_register(request):
return HttpResponseRedirect(reverse('register_success'))
else:
form = RegistrationForm()
- if 'django_openid' in settings.INSTALLED_APPS:
+ if 'django_openid_auth' in settings.INSTALLED_APPS:
openid_path = '/openid/'
context = {
'pageSection': 'home',
diff --git a/settings.py b/settings.py
index fbfe6df..ccabeb0 100644
--- a/settings.py
+++ b/settings.py
@@ -138,6 +138,7 @@ INSTALLED_APPS = (
INTERNAL_IPS=('127.0.0.1',)
MESSAGE_STORAGE = 'django.contrib.messages.storage.fallback.FallbackStorage'
+LOGIN_REDIRECT_URL = '/'
try:
from local_settings import *
@@ -149,4 +150,12 @@ if USE_DEBUG_TOOLBAR:
INSTALLED_APPS += ('debug_toolbar',)
if USE_DJANGO_OPENID:
- INSTALLED_APPS += ('django_openid',)
+ INSTALLED_APPS += ('django_openid_auth',)
+ AUTHENTICATION_BACKENDS = (
+ 'django_openid_auth.auth.OpenIDBackend',
+ 'django.contrib.auth.backends.ModelBackend',
+ )
+ OPENID_CREATE_USERS = True
+ OPENID_UPDATE_DETAILS_FROM_SREG = True
+ OPENID_UPDATE_DETAILS_FROM_AX = True
+
diff --git a/templates/login.html b/templates/login.html
index c028c84..0a471df 100644
--- a/templates/login.html
+++ b/templates/login.html
@@ -34,11 +34,14 @@
<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" />
+ <label for="id_openid_identifier"><img src="{% url openid-logo %}" alt=""> {% trans 'OpenID:' %}</label> <input type="text" name="openid_identifier" id="id_openid_identifier" />
</div>
<div class="submit-row">
<label> </label><input type="submit" value="{% trans 'Log in with OpenID' %}" />
</div>
+ {% if next %}
+ <input type="hidden" name="next" value="{{ next }}" />
+ {% endif %}
</form>
{% endif %}
diff --git a/urls.py b/urls.py
index 4ba7c06..978f25b 100644
--- a/urls.py
+++ b/urls.py
@@ -84,11 +84,9 @@ urlpatterns += patterns('stats.views',
view = 'compare_by_releases'),
)
-if 'django_openid' in settings.INSTALLED_APPS:
- from django_openid.auth import AuthConsumer
-
+if 'django_openid_auth' in settings.INSTALLED_APPS:
urlpatterns += patterns('',
- (r'^openid/(.*)', AuthConsumer()),
+ (r'^openid/', include('django_openid_auth.urls')),
)
if settings.STATIC_SERVE:
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]