Commits

Anonymous committed eb0cb16

Added support for Django admin management, using now HTTP 303 redirect to avoid form data warning in Firefox, some session information is optional

Comments (0)

Files changed (2)

openid2rp/django/auth.py

 	db = OpenIDSession()
 	db.assoc_handle=session['assoc_handle']
 	db.mac_key=session['mac_key']
-	db.session_type=session['session_type']
-	db.assoc_type=session['assoc_type']
-	db.ns=session['ns']
 	db.claimedId=claim
 	# Expire session in provider-given amount of seconds, consider possible shift
 	db.expiration_date = datetime.datetime.utcnow() + datetime.timedelta(seconds=long(session['expires_in'])) - maxTimeShift
+	if 'assoc_type' in session:
+		db.assoc_type=session['assoc_type']
+	if 'ns' in session:
+		db.ns=session['ns']
+	if 'session_type' in session:
+		db.session_type=session['session_type']
 	db.save()
 
 def getSessionByHandle(handle):
 		redirect_url=openid2rp.request_authentication( services, url, session['assoc_handle'], answer_url, claimedId, op_local, sreg=sreg, ax=ax )
 		response=HttpResponse()
 		response['Location']=redirect_url
-		response.status_code=307
+		response.status_code=303
 		return response, claimedId
 	else:
 		raise IncorrectClaimError()

openid2rp/django/models.py

 from django.db import models
 from django.contrib.auth.models import User
+from django.utils.encoding import smart_unicode
 
 class UserOpenID(models.Model):
 	user = models.ForeignKey(User, related_name='openids')
 	uri = models.CharField(max_length=255, blank=False, null=False)
 	insert_date = models.DateTimeField(null=False, blank=False, auto_now_add=True, editable=False)
 	last_modified = models.DateTimeField(null=False, blank=False, auto_now=True, editable=False)
-
+	def __unicode__(self):
+		return smart_unicode("OpenID claim for user '"+str(self.user)+"': "+str(self.uri))
+		
 class OpenIDSession(models.Model):
 	claimedId = models.CharField(max_length=255, blank=False, null=False)
 	assoc_handle = models.CharField(max_length=255, blank=False, null=False)
 	mac_key = models.CharField(max_length=255, blank=False, null=False)
-	session_type = models.CharField(max_length=255, blank=False, null=False)
 	expiration_date = models.DateTimeField(null=False, blank=False, editable=False)
-	assoc_type = models.CharField(max_length=255, blank=False, null=False)
-	ns = models.CharField(max_length=255, blank=False, null=False)
+	session_type = models.CharField(max_length=255, blank=True, null=True)
+	assoc_type = models.CharField(max_length=255, blank=True, null=True)
+	ns = models.CharField(max_length=255, blank=True, null=True)
+	def __unicode__(self):
+		return smart_unicode("OpenID session for '"+str(self.claimedId)+"', expires at "+str(self.expiration_date))
 	
 class OpenIDNonce(models.Model):
 	nonce = models.CharField(max_length=255, blank=False, null=False)
 	expiration_date = models.DateTimeField(null=False, blank=False, editable=False)
+	def __unicode__(self):
+		return smart_unicode("OpenID nonce '"+str(self.nonce)+"', expires at "+str(self.expiration_date))