diff options
author | Mike Chen <chagel@gmail.com> | 2009-07-05 10:23:06 +0800 |
---|---|---|
committer | Mike Chen <chagel@gmail.com> | 2009-07-05 10:23:06 +0800 |
commit | 2acb62174ab2cac9c7a88faafcb5f0a22a54db6f (patch) | |
tree | 93e9d22d6fb8a6c882e3915a8511a3ac542a1e67 /django_authopenid/models.py | |
download | askbot-2acb62174ab2cac9c7a88faafcb5f0a22a54db6f.tar.gz askbot-2acb62174ab2cac9c7a88faafcb5f0a22a54db6f.tar.bz2 askbot-2acb62174ab2cac9c7a88faafcb5f0a22a54db6f.zip |
initiliaze git rep
Diffstat (limited to 'django_authopenid/models.py')
-rw-r--r-- | django_authopenid/models.py | 71 |
1 files changed, 71 insertions, 0 deletions
diff --git a/django_authopenid/models.py b/django_authopenid/models.py new file mode 100644 index 00000000..9826c452 --- /dev/null +++ b/django_authopenid/models.py @@ -0,0 +1,71 @@ +# -*- coding: utf-8 -*- +from django.conf import settings +from django.contrib.auth.models import User +from django.db import models + +import md5, random, sys, os, time + +__all__ = ['Nonce', 'Association', 'UserAssociation', + 'UserPasswordQueueManager', 'UserPasswordQueue'] + +class Nonce(models.Model): + """ openid nonce """ + server_url = models.CharField(max_length=255) + timestamp = models.IntegerField() + salt = models.CharField(max_length=40) + + def __unicode__(self): + return u"Nonce: %s" % self.id + + +class Association(models.Model): + """ association openid url and lifetime """ + server_url = models.TextField(max_length=2047) + handle = models.CharField(max_length=255) + secret = models.TextField(max_length=255) # Stored base64 encoded + issued = models.IntegerField() + lifetime = models.IntegerField() + assoc_type = models.TextField(max_length=64) + + def __unicode__(self): + return u"Association: %s, %s" % (self.server_url, self.handle) + +class UserAssociation(models.Model): + """ + model to manage association between openid and user + """ + openid_url = models.CharField(blank=False, max_length=255) + user = models.ForeignKey(User, unique=True) + + def __unicode__(self): + return "Openid %s with user %s" % (self.openid_url, self.user) + +class UserPasswordQueueManager(models.Manager): + """ manager for UserPasswordQueue object """ + def get_new_confirm_key(self): + "Returns key that isn't being used." + # The random module is seeded when this Apache child is created. + # Use SECRET_KEY as added salt. + while 1: + confirm_key = md5.new("%s%s%s%s" % ( + random.randint(0, sys.maxint - 1), os.getpid(), + time.time(), settings.SECRET_KEY)).hexdigest() + try: + self.get(confirm_key=confirm_key) + except self.model.DoesNotExist: + break + return confirm_key + + +class UserPasswordQueue(models.Model): + """ + model for new password queue. + """ + user = models.ForeignKey(User, unique=True) + new_password = models.CharField(max_length=30) + confirm_key = models.CharField(max_length=40) + + objects = UserPasswordQueueManager() + + def __unicode__(self): + return self.user.username |