Commits

Jacek Bzdak  committed 06a5a62

Support for python3.3

  • Participants
  • Parent commits 8f242e3
  • Branches jbzdak-merge-python3.3

Comments (0)

Files changed (1)

File registration/models.py

 except ImportError:
     datetime_now = datetime.datetime.now
 
+try:
+    from django.utils.six import binary_type, text_type
+except ImportError:
+    try:
+        from six import binary_type, indexbytes
+    except ImportError:
+        # If we are using django < 1.5 we assume this is python 2.7,
+        # since earlier versions of django did not support 3.0
+        binary_type = str
+        text_type = unicode
+
 
 SHA1_RE = re.compile('^[a-f0-9]{40}$')
 
     keys), and for cleaning out expired inactive accounts.
     
     """
+
+    @staticmethod
+    def __id_generator(size=35, chars=string.ascii_uppercase + string.digits + string.ascii_lowercase):
+        return text_type(''.join(random.choice(chars) for x in range(size))).encode("utf-8")
+
+
     def activate_user(self, activation_key):
         """
         Validate an activation key and activate the corresponding
         username and a random salt.
         
         """
-        salt = hashlib.sha1(str(random.random())).hexdigest()[:5]
+        salt = hashlib.sha1(self.__id_generator()).digest()
         username = user.username
-        if isinstance(username, unicode):
+        if isinstance(username, text_type):
             username = username.encode('utf-8')
         activation_key = hashlib.sha1(salt+username).hexdigest()
         return self.create(user=user,