Commits

Thomas Waldmann committed 8fcaf02

use main part of the namespace for user items, use uuid4 for user item uuids

we use the normal wiki namespace for now to store user profile items, using
the user name as item name. for now, this is simpler. if we feel the need,
we can go back to storing them into UserProfile/* part of the namespace.

If we do that, there might be the issue that itemname != username then.

  • Participants
  • Parent commits a997882

Comments (0)

Files changed (1)

 import time
 import copy
 
+from uuid import uuid4
+make_uuid = lambda: unicode(uuid4().hex)
+
 from babel import parse_locale
 
 from flask import current_app as app
     """ create a user """
     # Create user profile
     theuser = User(auth_method="new-user")
-
-    theuser.name = username
+    theuser.name = unicode(username)
 
     # Don't allow creating users with invalid names
     if not isValidName(theuser.name):
 
 
 def get_user_backend():
-    """
-    Just a shorthand that makes the rest of the code easier
-    by returning the proper user backend.
-    """
-    ns_user_profile = app.cfg.ns_user_profile
-    return flaskg.unprotected_storage.get_backend(ns_user_profile)
+    return flaskg.unprotected_storage
 
 
 def getUserList():
                 self.load_from_id(password or u'')
         # Still no ID - make new user
         if not self.uuid:
-            self.uuid = self.make_id()
+            self.uuid = make_uuid()
             if password is not None:
                 self.enc_password = crypt_password(password)
 
                 pass
         return l
 
-    def make_id(self):
-        """ make a new unique user id """
-        #!!! this should probably be a hash of REMOTE_ADDR, HTTP_USER_AGENT
-        # and some other things identifying remote users, then we could also
-        # use it reliably in edit locking
-        from random import randint
-        return u"%s.%d" % (str(time.time()), randint(0, 65535))
-
     def create_or_update(self, changed=False):
         """ Create or update a user profile
 
         :param password: If not None, then the given password must match the
                          password in the user account file.
         """
-        name = getName(self.uuid) # XXX we need the name because backend API is still based on names
         try:
+            name = getName(self.uuid) # XXX we need the name because backend API is still based on names
+            if name is None:
+                raise NoSuchItemError("No user name for that uuid.")
             item = self._user_backend.get_item(name)
             self._user = item.get_revision(-1)
         except (NoSuchItemError, NoSuchRevisionError):
         """
         Save user account data to user account file on disk.
         """
+        backend_name = self.name # XXX maybe UserProfile/<name> later
         try:
-            item = self._user_backend.get_item(self.name)
+            item = self._user_backend.get_item(backend_name)
         except NoSuchItemError:
-            item = self._user_backend.create_item(self.name)
+            item = self._user_backend.create_item(backend_name)
         try:
             currentrev = item.get_revision(-1)
             rev_no = currentrev.revno