Commits

Thomas Waldmann committed 7c19f8b

user module: misc. cleanup

removed unneeded imports, move some imports to global scope

improved docstrings / comments

included .trusted state in repr of User item

renamed some methods (PEP-8)

Comments (0)

Files changed (1)

 
 from __future__ import absolute_import, division
 
-import time
+import re
 import copy
 import hashlib
 import werkzeug
 
 from whoosh.query import Term, And, Or
 
-from MoinMoin import config, wikiutil
+from MoinMoin import wikiutil
 from MoinMoin.config import CONTENTTYPE_USER
 from MoinMoin.constants.keys import *
 from MoinMoin.i18n import _, L_, N_
+from MoinMoin.mail import sendmail
 from MoinMoin.util.interwiki import getInterwikiHome, getInterwikiName, is_local_wiki
 from MoinMoin.util.crypto import crypt_password, upgrade_password, valid_password, \
                                  generate_token, valid_token, make_uuid
     def __init__(self, uid=None, name="", password=None, auth_username="", trusted=False, **kw):
         """ Initialize User object
 
-        :param uid: (optional) user ID
+        :param uid: (optional) user ID (user itemid)
         :param name: (optional) user name
         :param password: (optional) user password (unicode)
         :param auth_username: (optional) already authenticated user name
                               (e.g. when using http basic auth) (unicode)
+        :param trusted: (optional) whether user instance is created by a
+                        trusted auth method / session
         :keyword auth_method: method that was used for authentication,
                               default: 'internal'
         :keyword auth_attribs: tuple of user object attribute names that are
         self.profile = UserProfile()
         self._cfg = app.cfg
         self.valid = False
-        self.trusted = trusted # trusted auth methods can set this to True
+        self.trusted = trusted
         self.auth_method = kw.get('auth_method', 'internal')
         self.auth_attribs = kw.get('auth_attribs', ())
 
             self.may = Default(self)
 
     def __repr__(self):
-        return "<{0}.{1} at {2:#x} name:{3!r} itemid:{4!r} valid:{5!r}>".format(
+        return "<{0}.{1} at {2:#x} name:{3!r} itemid:{4!r} valid:{5!r} trusted:{6!r}>".format(
             self.__class__.__module__, self.__class__.__name__, id(self),
-            self.name, self.itemid, self.valid)
+            self.name, self.itemid, self.valid, self.trusted)
 
     def __getattr__(self, name):
         """
                                            True)
 
         param['size'] = str(size)
-        #TODO: use same protocol of Moin site (might be https instead of http)]
+        # TODO: use same protocol of Moin site (might be https instead of http)]
         gravatar_url = "http://www.gravatar.com/avatar.php?"
         gravatar_url += werkzeug.url_encode(param)
 
 
         if password is not None:
             # Check for a valid password, possibly changing storage
-            valid, changed = self._validatePassword(self.profile, password)
+            valid, changed = self._validate_password(self.profile, password)
             if not valid:
                 return
 
         if changed:
             self.profile.save()
 
-    def _validatePassword(self, data, password):
+    def _validate_password(self, data, password):
         """
         Check user password.
 
         return text # FIXME, was: self._request.getText(text, lang=self.language)
 
 
-    # -----------------------------------------------------------------
-    # Bookmark
+    # Bookmarks --------------------------------------------------------------
 
     def setBookmark(self, tm):
         """ Set bookmark timestamp.
             return 0
         return 1
 
-    # -----------------------------------------------------------------
-    # Subscribe
+    # Subscribed Items -------------------------------------------------------
 
     def isSubscribedTo(self, pagelist):
         """ Check if user subscription matches any page in pagelist.
         if not self.valid:
             return False
 
-        import re
         # Create a new list with interwiki names.
         pages = [getInterwikiName(pagename) for pagename in pagelist]
         # Create text for regular expression search
             self.save(force=True)
         return not self.isSubscribedTo([pagename])
 
-    # -----------------------------------------------------------------
-    # Quicklinks
+    # Quicklinks -------------------------------------------------------------
 
     def isQuickLinkedTo(self, pagelist):
         """ Check if user quicklink matches any page in pagelist.
             return True
         return False
 
-    # -----------------------------------------------------------------
-    # Trail
+    # Trail ------------------------------------------------------------------
 
     def addTrail(self, item_name):
         """ Add item name to trail.
         """
         return session.get('trail', [])
 
-    # -----------------------------------------------------------------
-    # Other
+    # Other ------------------------------------------------------------------
 
     def isCurrentUser(self):
         """ Check if this user object is the user doing the current request """
         return flaskg.user.name == self.name
 
+    # Account verification / Password recovery -------------------------------
+
     def generate_recovery_token(self):
         key, token = generate_token()
         self.profile[RECOVERPASS_KEY] = key
         """ Mail a user who forgot his password a message enabling
             him to login again.
         """
-        from MoinMoin.mail import sendmail
         token = self.generate_recovery_token()
 
         text = _("""\
 
     def mailVerificationLink(self):
         """ Mail a user a link to verify his email address. """
-        from MoinMoin.mail import sendmail
         token = self.generate_recovery_token()
 
         text = _("""\