Back to index

moin  1.9.0~rc2
Classes | Functions
MoinMoin.user Namespace Reference

Classes

class  User

Functions

def getUserList
def get_by_filter
def get_by_email_address
def get_by_jabber_id
def _getUserIdByKey
def getUserId
def getUserIdByOpenId
def getUserIdentification
def encodePassword
def normalizeName
def isValidName
def encodeList
def decodeList
def encodeDict
def decodeDict

Function Documentation

def MoinMoin.user._getUserIdByKey (   request,
  key,
  search 
) [private]
Get the user ID for a specified key/value pair.

This method must only be called for keys that are
guaranteed to be unique.

@param key: the key to look in
@param search: the value to look for
@return the corresponding user ID or None

Definition at line 61 of file user.py.

00061 
00062 def _getUserIdByKey(request, key, search):
00063     """ Get the user ID for a specified key/value pair.
00064 
00065     This method must only be called for keys that are
00066     guaranteed to be unique.
00067 
00068     @param key: the key to look in
00069     @param search: the value to look for
00070     @return the corresponding user ID or None
00071     """
00072     if not search or not key:
00073         return None
00074     cfg = request.cfg
00075     cachekey = '%s2id' % key
00076     try:
00077         _key2id = getattr(cfg.cache, cachekey)
00078     except AttributeError:
00079         arena = 'user'
00080         cache = caching.CacheEntry(request, arena, cachekey, scope='wiki', use_pickle=True)
00081         try:
00082             _key2id = cache.content()
00083         except caching.CacheError:
00084             _key2id = {}
00085         setattr(cfg.cache, cachekey, _key2id)
00086     uid = _key2id.get(search, None)
00087     if uid is None:
00088         for userid in getUserList(request):
00089             u = User(request, id=userid)
00090             if hasattr(u, key):
00091                 value = getattr(u, key)
00092                 if isinstance(value, list):
00093                     for val in value:
00094                         _key2id[val] = userid
00095                 else:
00096                     _key2id[value] = userid
00097         arena = 'user'
00098         cache = caching.CacheEntry(request, arena, cachekey, scope='wiki', use_pickle=True)
00099         try:
00100             cache.update(_key2id)
00101         except caching.CacheError:
00102             pass
00103         uid = _key2id.get(search, None)
00104     return uid
00105 

Here is the call graph for this function:

Here is the caller graph for this function:

def MoinMoin.user.decodeDict (   line)
Decode dict of key:value pairs from user data file

@param line: line containing a dict, encoded with encodeDict
@rtype: dict
@return: dict  unicode:unicode items

Definition at line 251 of file user.py.

00251 
00252 def decodeDict(line):
00253     """ Decode dict of key:value pairs from user data file
00254 
00255     @param line: line containing a dict, encoded with encodeDict
00256     @rtype: dict
00257     @return: dict  unicode:unicode items
00258     """
00259     items = {}
00260     for item in line.split('\t'):
00261         item = item.strip()
00262         if not item:
00263             continue
00264         key, value = item.split(':', 1)
00265         items[key] = value
00266     return items
00267 

Here is the caller graph for this function:

def MoinMoin.user.decodeList (   line)
Decode list of items from user data file

@param line: line containing list of items, encoded with encodeList
@rtype: list of unicode strings
@return: list of items in encoded in line

Definition at line 219 of file user.py.

00219 
00220 def decodeList(line):
00221     """ Decode list of items from user data file
00222 
00223     @param line: line containing list of items, encoded with encodeList
00224     @rtype: list of unicode strings
00225     @return: list of items in encoded in line
00226     """
00227     items = []
00228     for item in line.split('\t'):
00229         item = item.strip()
00230         if not item:
00231             continue
00232         items.append(item)
00233     return items

Here is the caller graph for this function:

def MoinMoin.user.encodeDict (   items)
Encode dict of items in user data file

Items are separated by '\t' characters.
Each item is key:value.

@param items: dict of unicode:unicode
@rtype: unicode
@return: dict encoded as unicode

Definition at line 234 of file user.py.

00234 
00235 def encodeDict(items):
00236     """ Encode dict of items in user data file
00237 
00238     Items are separated by '\t' characters.
00239     Each item is key:value.
00240 
00241     @param items: dict of unicode:unicode
00242     @rtype: unicode
00243     @return: dict encoded as unicode
00244     """
00245     line = []
00246     for key, value in items.items():
00247         item = u'%s:%s' % (key, value)
00248         line.append(item)
00249     line = '\t'.join(line)
00250     return line

Here is the caller graph for this function:

def MoinMoin.user.encodeList (   items)
Encode list of items in user data file

Items are separated by '\t' characters.

@param items: list unicode strings
@rtype: unicode
@return: list encoded as unicode

Definition at line 200 of file user.py.

00200 
00201 def encodeList(items):
00202     """ Encode list of items in user data file
00203 
00204     Items are separated by '\t' characters.
00205 
00206     @param items: list unicode strings
00207     @rtype: unicode
00208     @return: list encoded as unicode
00209     """
00210     line = []
00211     for item in items:
00212         item = item.strip()
00213         if not item:
00214             continue
00215         line.append(item)
00216 
00217     line = '\t'.join(line)
00218     return line

Here is the caller graph for this function:

def MoinMoin.user.encodePassword (   pwd,
  salt = None 
)
Encode a cleartext password

@param pwd: the cleartext password, (unicode)
@param salt: the salt for the password (string)
@rtype: string
@return: the password in apache htpasswd compatible SHA-encoding,
    or None

Definition at line 142 of file user.py.

00142 
00143 def encodePassword(pwd, salt=None):
00144     """ Encode a cleartext password
00145 
00146     @param pwd: the cleartext password, (unicode)
00147     @param salt: the salt for the password (string)
00148     @rtype: string
00149     @return: the password in apache htpasswd compatible SHA-encoding,
00150         or None
00151     """
00152     pwd = pwd.encode('utf-8')
00153 
00154     if salt is None:
00155         salt = random_string(20)
00156     assert isinstance(salt, str)
00157     hash = hash_new('sha1', pwd)
00158     hash.update(salt)
00159 
00160     return '{SSHA}' + base64.encodestring(hash.digest() + salt).rstrip()
00161 

Here is the caller graph for this function:

def MoinMoin.user.get_by_email_address (   request,
  email_address 
)
Searches for an user with a particular e-mail address and returns it. 

Definition at line 51 of file user.py.

00051 
00052 def get_by_email_address(request, email_address):
00053     """ Searches for an user with a particular e-mail address and returns it. """
00054     filter_func = lambda user: user.valid and user.email.lower() == email_address.lower()
00055     return get_by_filter(request, filter_func)

Here is the call graph for this function:

def MoinMoin.user.get_by_filter (   request,
  filter_func 
)
Searches for an user with a given filter function 

Definition at line 44 of file user.py.

00044 
00045 def get_by_filter(request, filter_func):
00046     """ Searches for an user with a given filter function """
00047     for uid in getUserList(request):
00048         theuser = User(request, uid)
00049         if filter_func(theuser):
00050             return theuser

Here is the call graph for this function:

Here is the caller graph for this function:

def MoinMoin.user.get_by_jabber_id (   request,
  jabber_id 
)
Searches for an user with a perticular jabber id and returns it. 

Definition at line 56 of file user.py.

00056 
00057 def get_by_jabber_id(request, jabber_id):
00058     """ Searches for an user with a perticular jabber id and returns it. """
00059     filter_func = lambda user: user.valid and user.jid.lower() == jabber_id.lower()
00060     return get_by_filter(request, filter_func)

Here is the call graph for this function:

def MoinMoin.user.getUserId (   request,
  searchName 
)
Get the user ID for a specific user NAME.

@param searchName: the user name to look up
@rtype: string
@return: the corresponding user ID or None

Definition at line 106 of file user.py.

00106 
00107 def getUserId(request, searchName):
00108     """ Get the user ID for a specific user NAME.
00109 
00110     @param searchName: the user name to look up
00111     @rtype: string
00112     @return: the corresponding user ID or None
00113     """
00114     return _getUserIdByKey(request, 'name', searchName)
00115 

Here is the call graph for this function:

def MoinMoin.user.getUserIdByOpenId (   request,
  openid 
)
Get the user ID for a specific OpenID.

@param openid: the openid to look up
@rtype: string
@return: the corresponding user ID or None

Definition at line 116 of file user.py.

00116 
00117 def getUserIdByOpenId(request, openid):
00118     """ Get the user ID for a specific OpenID.
00119 
00120     @param openid: the openid to look up
00121     @rtype: string
00122     @return: the corresponding user ID or None
00123     """
00124     return _getUserIdByKey(request, 'openids', openid)
00125 

Here is the call graph for this function:

def MoinMoin.user.getUserIdentification (   request,
  username = None 
)
Return user name or IP or '<unknown>' indicator.

@param request: the request object
@param username: (optional) user name
@rtype: string
@return: user name or IP or unknown indicator

Definition at line 126 of file user.py.

00126 
00127 def getUserIdentification(request, username=None):
00128     """ Return user name or IP or '<unknown>' indicator.
00129 
00130     @param request: the request object
00131     @param username: (optional) user name
00132     @rtype: string
00133     @return: user name or IP or unknown indicator
00134     """
00135     _ = request.getText
00136 
00137     if username is None:
00138         username = request.user.name
00139 
00140     return username or (request.cfg.show_hosts and request.remote_addr) or _("<unknown>")
00141 

def MoinMoin.user.getUserList (   request)
Get a list of all (numerical) user IDs.

@param request: current request
@rtype: list
@return: all user IDs

Definition at line 31 of file user.py.

00031 
00032 def getUserList(request):
00033     """ Get a list of all (numerical) user IDs.
00034 
00035     @param request: current request
00036     @rtype: list
00037     @return: all user IDs
00038     """
00039     import re
00040     user_re = re.compile(r'^\d+\.\d+(\.\d+)?$')
00041     files = filesys.dclistdir(request.cfg.user_dir)
00042     userlist = [f for f in files if user_re.match(f)]
00043     return userlist

Here is the caller graph for this function:

def MoinMoin.user.isValidName (   request,
  name 
)
Validate user name

@param name: user name, unicode

Definition at line 191 of file user.py.

00191 
00192 def isValidName(request, name):
00193     """ Validate user name
00194 
00195     @param name: user name, unicode
00196     """
00197     normalized = normalizeName(name)
00198     return (name == normalized) and not wikiutil.isGroupPage(name, request.cfg)
00199 

Here is the call graph for this function:

Make normalized user name

Prevent impersonating another user with names containing leading,
trailing or multiple whitespace, or using invisible unicode
characters.

Prevent creating user page as sub page, because '/' is not allowed
in user names.

Prevent using ':' and ',' which are reserved by acl.

@param name: user name, unicode
@rtype: unicode
@return: user name that can be used in acl lines

Definition at line 162 of file user.py.

00162 
00163 def normalizeName(name):
00164     """ Make normalized user name
00165 
00166     Prevent impersonating another user with names containing leading,
00167     trailing or multiple whitespace, or using invisible unicode
00168     characters.
00169 
00170     Prevent creating user page as sub page, because '/' is not allowed
00171     in user names.
00172 
00173     Prevent using ':' and ',' which are reserved by acl.
00174 
00175     @param name: user name, unicode
00176     @rtype: unicode
00177     @return: user name that can be used in acl lines
00178     """
00179     username_allowedchars = "'@.-_" # ' for names like O'Brian or email addresses.
00180                                     # "," and ":" must not be allowed (ACL delimiters).
00181                                     # We also allow _ in usernames for nicer URLs.
00182     # Strip non alpha numeric characters (except username_allowedchars), keep white space
00183     name = ''.join([c for c in name if c.isalnum() or c.isspace() or c in username_allowedchars])
00184 
00185     # Normalize white space. Each name can contain multiple
00186     # words separated with only one space.
00187     name = ' '.join(name.split())
00188 
00189     return name
00190 

Here is the caller graph for this function: