From 51c0cb6e20174df2652643a916b96e9fa89b509e Mon Sep 17 00:00:00 2001 From: Antony Chazapis Date: Mon, 8 Aug 2011 03:04:46 +0300 Subject: [PATCH] Bug fix. --- pithos/aai/functions.py | 5 +++-- pithos/aai/models.py | 4 ++-- pithos/aai/shibboleth.py | 8 ++++---- pithos/aai/util.py | 7 +++---- 4 files changed, 12 insertions(+), 12 deletions(-) diff --git a/pithos/aai/functions.py b/pithos/aai/functions.py index 260ca70..52b0c33 100644 --- a/pithos/aai/functions.py +++ b/pithos/aai/functions.py @@ -34,7 +34,7 @@ from time import time, mktime from django.conf import settings -from django.http import HttpResponse, HttpResponseRedirect +from django.http import HttpResponse, HttpResponseBadRequest from django.utils.http import urlencode from django.utils.cache import patch_vary_headers @@ -81,7 +81,8 @@ def login(request): if not next: response['X-Auth-User'] = user.uniq response['X-Auth-Token'] = user.auth_token - response.status_code = 204 + response.content = user.uniq + '\n' + user.auth_token + '\n' + response.status_code = 200 else: response['Location'] = next response.status_code = 302 diff --git a/pithos/aai/models.py b/pithos/aai/models.py index fb778ca..dfcd745 100644 --- a/pithos/aai/models.py +++ b/pithos/aai/models.py @@ -46,9 +46,9 @@ class PithosUser(models.Model): auth_token_expires = models.DateTimeField('Time of auth token expiration', auto_now_add=True) created = models.DateTimeField('Time of creation', auto_now_add=True) updated = models.DateTimeField('Time of last update', auto_now=True) - + class Meta: verbose_name = u'Pithos User' - + def __unicode__(self): return self.uniq diff --git a/pithos/aai/shibboleth.py b/pithos/aai/shibboleth.py index 1075086..e9ff835 100644 --- a/pithos/aai/shibboleth.py +++ b/pithos/aai/shibboleth.py @@ -57,12 +57,12 @@ class NoRealName(BaseException): def register_shibboleth_user(tokens): """Registers a Shibboleth user using the input hash as a source for data.""" - + try: eppn = tokens[Tokens.SHIB_EPPN] except KeyError: raise NoUniqueToken("Authentication does not return a unique token") - + if Tokens.SHIB_DISPLAYNAME in tokens: realname = tokens[Tokens.SHIB_DISPLAYNAME] elif Tokens.SHIB_CN in tokens: @@ -71,7 +71,7 @@ def register_shibboleth_user(tokens): realname = tokens[Tokens.SHIB_NAME] + ' ' + tokens[Tokens.SHIB_SURNAME] else: raise NoRealName("Authentication does not return the user's name") - + affiliation = tokens.get(Tokens.SHIB_EP_AFFILIATION, '') - + return register_user(eppn, realname, affiliation) diff --git a/pithos/aai/util.py b/pithos/aai/util.py index 8d31bc7..7ce1699 100644 --- a/pithos/aai/util.py +++ b/pithos/aai/util.py @@ -31,9 +31,8 @@ # interpreted as representing official policies, either expressed # or implied, of GRNET S.A. -# Business Logic for working with users +import hashlib -from hashlib import md5 from time import asctime from datetime import datetime, timedelta @@ -60,11 +59,11 @@ def delete_user(user): @transaction.commit_on_success def create_auth_token(user): - md5 = md5() + md5 = hashlib.md5() md5.update(user.uniq) md5.update(user.realname.encode('ascii', 'ignore')) md5.update(asctime()) - + user.auth_token = md5.hexdigest() user.auth_token_created = datetime.now() user.auth_token_expires = user.auth_token_created + \ -- 1.7.10.4