From c764ae5f13f07300b360359f4ce0f13cbc5a0a66 Mon Sep 17 00:00:00 2001 From: Andrew Williams Date: Thu, 20 Jan 2011 16:39:00 +0000 Subject: [PATCH] Use the django inbuilt simplejson, also fix for current v1 API --- auth.py | 14 +++----------- 1 file changed, 3 insertions(+), 11 deletions(-) diff --git a/auth.py b/auth.py index 7495f5e..4647eda 100644 --- a/auth.py +++ b/auth.py @@ -1,11 +1,11 @@ import hashlib from string import lower -import simplejson as json +import django.utils.simplejson as json import urllib import urllib2 from hashlib import sha1 from django.contrib.auth.models import User, check_password -from settings import * +import settings class DredditAuthBackend: """ @@ -18,14 +18,6 @@ class DredditAuthBackend: if username and password: # Call the webservice api_url = 'https://auth.dredd.it/api/login/' - auth_handler = urllib2.HTTPBasicAuthHandler() - auth_handler.add_password(realm='dredditauth', - uri=api_url, - user=DREDDIT_API_USERNAME, - passwd=DREDDIT_API_PASSWORD) - opener = urllib2.build_opener(auth_handler) - urllib2.install_opener(opener) - params = { 'user': username, 'pass': sha1(password).hexdigest() } try: raw = urllib2.urlopen('%s?%s' % (api_url, urllib.urlencode(params))) @@ -49,7 +41,7 @@ class DredditAuthBackend: if hasattr(settings, 'DREDDIT_AUTH_CREATE_GROUPS') and settings.DREDDIT_AUTH_CREATE_GROUPS: for g in groups: - group, created = Group.objects.get_or_create(name=g['name']): + group, created = Group.objects.get_or_create(name=g['name']) user.groups.add(group) return user