Back to index

moin  1.9.0~rc2
Public Member Functions | Public Attributes | Private Member Functions | Private Attributes
MoinMoin.user.User Class Reference

List of all members.

Public Member Functions

def __init__
def __repr__
def make_id
def create_or_update
def exists
def load_from_id
def persistent_items
def save
def getTime
def getFormattedDate
def getFormattedDateTime
def setBookmark
def getBookmark
def delBookmark
def getSubscriptionList
def isSubscribedTo
def subscribe
def unsubscribe
def getQuickLinks
def isQuickLinkedTo
def addQuicklink
def removeQuicklink
def addTrail
def getTrail
def isCurrentUser
def isSuperUser
def host
def wikiHomeLink
def signature
def generate_recovery_token
def apply_recovery_token
def mailAccountData

Public Attributes

 valid
 id
 auth_username
 auth_method
 auth_attribs
 bookmarks
 name
 recoverpass_key
 enc_password
 tz_offset
 language
 real_language
 date_fmt
 datetime_fmt
 quicklinks
 subscribed_pages
 email_subscribed_events
 jabber_subscribed_events
 theme_name
 editor_default
 editor_ui
 last_saved
 may

Private Member Functions

def __filename
def _validatePassword
def _interWikiName
def _wantTrail

Private Attributes

 _cfg
 _stored
 _request

Detailed Description

A MoinMoin User 

Definition at line 268 of file user.py.


Constructor & Destructor Documentation

def MoinMoin.user.User.__init__ (   self,
  request,
  id = None,
  name = "",
  password = None,
  auth_username = "",
  kw 
)
Initialize User object

TODO: when this gets refactored, use "uid" not builtin "id"

@param request: the request object
@param id: (optional) user ID
@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)
@keyword auth_method: method that was used for authentication,
              default: 'internal'
@keyword auth_attribs: tuple of user object attribute names that are
               determined by auth method and should not be
               changeable by preferences, default: ().
               First tuple element was used for authentication.

Definition at line 271 of file user.py.

00271 
00272     def __init__(self, request, id=None, name="", password=None, auth_username="", **kw):
00273         """ Initialize User object
00274 
00275         TODO: when this gets refactored, use "uid" not builtin "id"
00276 
00277         @param request: the request object
00278         @param id: (optional) user ID
00279         @param name: (optional) user name
00280         @param password: (optional) user password (unicode)
00281         @param auth_username: (optional) already authenticated user name
00282                               (e.g. when using http basic auth) (unicode)
00283         @keyword auth_method: method that was used for authentication,
00284                               default: 'internal'
00285         @keyword auth_attribs: tuple of user object attribute names that are
00286                                determined by auth method and should not be
00287                                changeable by preferences, default: ().
00288                                First tuple element was used for authentication.
00289         """
00290         self._cfg = request.cfg
00291         self.valid = 0
00292         self.id = id
00293         self.auth_username = auth_username
00294         self.auth_method = kw.get('auth_method', 'internal')
00295         self.auth_attribs = kw.get('auth_attribs', ())
00296         self.bookmarks = {} # interwikiname: bookmark
00297 
00298         # create some vars automatically
00299         self.__dict__.update(self._cfg.user_form_defaults)
00300 
00301         if name:
00302             self.name = name
00303         elif auth_username: # this is needed for user autocreate
00304             self.name = auth_username
00305 
00306         # create checkbox fields (with default 0)
00307         for key, label in self._cfg.user_checkbox_fields:
00308             setattr(self, key, self._cfg.user_checkbox_defaults.get(key, 0))
00309 
00310         self.recoverpass_key = ""
00311 
00312         if password:
00313             self.enc_password = encodePassword(password)
00314 
00315         #self.edit_cols = 80
00316         self.tz_offset = int(float(self._cfg.tz_offset) * 3600)
00317         self.language = ""
00318         self.real_language = "" # In case user uses "Browser setting". For language-statistics
00319         self._stored = False
00320         self.date_fmt = ""
00321         self.datetime_fmt = ""
00322         self.quicklinks = self._cfg.quicklinks_default
00323         self.subscribed_pages = self._cfg.subscribed_pages_default
00324         self.email_subscribed_events = self._cfg.email_subscribed_events_default
00325         self.jabber_subscribed_events = self._cfg.jabber_subscribed_events_default
00326         self.theme_name = self._cfg.theme_default
00327         self.editor_default = self._cfg.editor_default
00328         self.editor_ui = self._cfg.editor_ui
00329         self.last_saved = str(time.time())
00330 
00331         # attrs not saved to profile
00332         self._request = request
00333 
00334         # we got an already authenticated username:
00335         check_password = None
00336         if not self.id and self.auth_username:
00337             self.id = getUserId(request, self.auth_username)
00338             if not password is None:
00339                 check_password = password
00340         if self.id:
00341             self.load_from_id(check_password)
00342         elif self.name:
00343             self.id = getUserId(self._request, self.name)
00344             if self.id:
00345                 # no password given should fail
00346                 self.load_from_id(password or u'')
00347         # Still no ID - make new user
00348         if not self.id:
00349             self.id = self.make_id()
00350             if password is not None:
00351                 self.enc_password = encodePassword(password)
00352 
00353         # "may" so we can say "if user.may.read(pagename):"
00354         if self._cfg.SecurityPolicy:
00355             self.may = self._cfg.SecurityPolicy(self)
00356         else:
00357             from MoinMoin.security import Default
00358             self.may = Default(self)
00359 
00360         if self.language and not self.language in i18n.wikiLanguages():
00361             self.language = 'en'


Member Function Documentation

def MoinMoin.user.User.__filename (   self) [private]
Get filename of the user's file on disk

@rtype: string
@return: full path and filename of user account file

Definition at line 383 of file user.py.

00383 
00384     def __filename(self):
00385         """ Get filename of the user's file on disk
00386 
00387         @rtype: string
00388         @return: full path and filename of user account file
00389         """
00390         return os.path.join(self._cfg.user_dir, self.id or "...NONE...")

Here is the caller graph for this function:

Definition at line 362 of file user.py.

00362 
00363     def __repr__(self):
00364         return "<%s.%s at 0x%x name:%r valid:%r>" % (
00365             self.__class__.__module__, self.__class__.__name__,
00366             id(self), self.name, self.valid)

def MoinMoin.user.User._interWikiName (   self,
  pagename 
) [private]
Return the inter wiki name of a page name

@param pagename: page name
@type pagename: unicode

Definition at line 859 of file user.py.

00859 
00860     def _interWikiName(self, pagename):
00861         """ Return the inter wiki name of a page name
00862 
00863         @param pagename: page name
00864         @type pagename: unicode
00865         """
00866         if not self._cfg.interwikiname:
00867             return None
00868 
00869         return "%s:%s" % (self._cfg.interwikiname, pagename)

Here is the caller graph for this function:

def MoinMoin.user.User._validatePassword (   self,
  data,
  password 
) [private]
Check user password.

This is a private method and should not be used by clients.

@param data: dict with user data (from storage)
@param password: password to verify [unicode]
@rtype: 2 tuple (bool, bool)
@return: password is valid, enc_password changed

Definition at line 488 of file user.py.

00488 
00489     def _validatePassword(self, data, password):
00490         """
00491         Check user password.
00492 
00493         This is a private method and should not be used by clients.
00494 
00495         @param data: dict with user data (from storage)
00496         @param password: password to verify [unicode]
00497         @rtype: 2 tuple (bool, bool)
00498         @return: password is valid, enc_password changed
00499         """
00500         epwd = data['enc_password']
00501 
00502         # If we have no password set, we don't accept login with username
00503         if not epwd:
00504             return False, False
00505 
00506         # require non empty password
00507         if not password:
00508             return False, False
00509 
00510         if epwd[:5] == '{SHA}':
00511             enc = '{SHA}' + base64.encodestring(hash_new('sha1', password.encode('utf-8')).digest()).rstrip()
00512             if epwd == enc:
00513                 data['enc_password'] = encodePassword(password) # upgrade to SSHA
00514                 return True, True
00515             return False, False
00516 
00517         if epwd[:6] == '{SSHA}':
00518             data = base64.decodestring(epwd[6:])
00519             salt = data[20:]
00520             hash = hash_new('sha1', password.encode('utf-8'))
00521             hash.update(salt)
00522             return hash.digest() == data[:20], False
00523 
00524         # No encoded password match, this must be wrong password
00525         return False, False

Here is the call graph for this function:

Here is the caller graph for this function:

def MoinMoin.user.User._wantTrail (   self) [private]

Definition at line 873 of file user.py.

00873 
00874     def _wantTrail(self):
00875         return (not self.valid and self._request.cfg.cookie_lifetime[0]  # anon sessions enabled
00876                 or self.valid and (self.show_page_trail or self.remember_last_visit))  # logged-in session

Here is the caller graph for this function:

def MoinMoin.user.User.addQuicklink (   self,
  pagename 
)
Adds a page to the user quicklinks

If the wiki has an interwiki name, all links are saved as
interwiki names. If not, as simple page name.

@param pagename: page name
@type pagename: unicode
@rtype: bool
@return: if pagename was added

Definition at line 807 of file user.py.

00807 
00808     def addQuicklink(self, pagename):
00809         """ Adds a page to the user quicklinks
00810 
00811         If the wiki has an interwiki name, all links are saved as
00812         interwiki names. If not, as simple page name.
00813 
00814         @param pagename: page name
00815         @type pagename: unicode
00816         @rtype: bool
00817         @return: if pagename was added
00818         """
00819         changed = False
00820         interWikiName = self._interWikiName(pagename)
00821         if interWikiName:
00822             if pagename in self.quicklinks:
00823                 self.quicklinks.remove(pagename)
00824                 changed = True
00825             if interWikiName not in self.quicklinks:
00826                 self.quicklinks.append(interWikiName)
00827                 changed = True
00828         else:
00829             if pagename not in self.quicklinks:
00830                 self.quicklinks.append(pagename)
00831                 changed = True
00832 
00833         if changed:
00834             self.save()
00835         return changed

Here is the call graph for this function:

def MoinMoin.user.User.addTrail (   self,
  page 
)
Add page to trail.

@param page: the page (object) to add to the trail

Definition at line 877 of file user.py.

00877 
00878     def addTrail(self, page):
00879         """ Add page to trail.
00880 
00881         @param page: the page (object) to add to the trail
00882         """
00883         if self._wantTrail():
00884             pagename = page.page_name
00885             # Add only existing pages that the user may read
00886             if not (page.exists() and self._request.user.may.read(pagename)):
00887                 return
00888 
00889             # Save interwiki links internally
00890             if self._cfg.interwikiname:
00891                 pagename = self._interWikiName(pagename)
00892 
00893             trail = self._request.session.get('trail', [])
00894 
00895             # Don't append tail to trail ;)
00896             if trail and trail[-1] == pagename:
00897                 return
00898 
00899             # Append new page, limiting the length
00900             trail = [p for p in trail if p != pagename]
00901             pagename_stripped = pagename.strip()
00902             if pagename_stripped:
00903                 trail.append(pagename_stripped)
00904             self._request.session['trail'] = trail[-(self._cfg.trail_size-1):]

Here is the call graph for this function:

def MoinMoin.user.User.apply_recovery_token (   self,
  tok,
  newpass 
)

Definition at line 979 of file user.py.

00979 
00980     def apply_recovery_token(self, tok, newpass):
00981         parts = tok.split('-')
00982         if len(parts) != 2:
00983             return False
00984         try:
00985             stamp = int(parts[0])
00986         except ValueError:
00987             return False
00988         # only allow it to be valid for twelve hours
00989         if stamp + 12*60*60 < time.time():
00990             return False
00991         # check hmac
00992         # key must be of type string
00993         h = hmac_new(str(self.recoverpass_key), str(stamp)).hexdigest()
00994         if h != parts[1]:
00995             return False
00996         self.recoverpass_key = ""
00997         self.enc_password = encodePassword(newpass)
00998         self.save()
00999         return True

Here is the call graph for this function:

def MoinMoin.user.User.create_or_update (   self,
  changed = False 
)
Create or update a user profile

@param changed: bool, set this to True if you updated the user profile values

Definition at line 375 of file user.py.

00375 
00376     def create_or_update(self, changed=False):
00377         """ Create or update a user profile
00378 
00379         @param changed: bool, set this to True if you updated the user profile values
00380         """
00381         if not self.valid and not self.disabled or changed: # do we need to save/update?
00382             self.save() # yes, create/update user profile

Here is the call graph for this function:

Removes bookmark timestamp.

@rtype: int
@return: 0 on success, 1 on failure

Definition at line 653 of file user.py.

00653 
00654     def delBookmark(self):
00655         """ Removes bookmark timestamp.
00656 
00657         @rtype: int
00658         @return: 0 on success, 1 on failure
00659         """
00660         interwikiname = self._cfg.interwikiname or u''
00661         if self.valid:
00662             try:
00663                 del self.bookmarks[interwikiname]
00664             except KeyError:
00665                 return 1
00666             self.save()
00667             return 0
00668         return 1

Here is the call graph for this function:

def MoinMoin.user.User.exists (   self)
Do we have a user account for this user?

@rtype: bool
@return: true, if we have a user account

Definition at line 391 of file user.py.

00391 
00392     def exists(self):
00393         """ Do we have a user account for this user?
00394 
00395         @rtype: bool
00396         @return: true, if we have a user account
00397         """
00398         return os.path.exists(self.__filename())

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 971 of file user.py.

00971 
00972     def generate_recovery_token(self):
00973         key = random_string(64, "abcdefghijklmnopqrstuvwxyz0123456789")
00974         msg = str(int(time.time()))
00975         h = hmac_new(key, msg).hexdigest()
00976         self.recoverpass_key = key
00977         self.save()
00978         return msg + '-' + h

Here is the call graph for this function:

Here is the caller graph for this function:

Get bookmark timestamp.

@rtype: int
@return: bookmark timestamp or None

Definition at line 638 of file user.py.

00638 
00639     def getBookmark(self):
00640         """ Get bookmark timestamp.
00641 
00642         @rtype: int
00643         @return: bookmark timestamp or None
00644         """
00645         bm = None
00646         interwikiname = self._cfg.interwikiname or u''
00647         if self.valid:
00648             try:
00649                 bm = int(self.bookmarks[interwikiname])
00650             except (ValueError, KeyError):
00651                 pass
00652         return bm

def MoinMoin.user.User.getFormattedDate (   self,
  tm 
)
Get formatted date adjusted for user's timezone.

@param tm: time (UTC UNIX timestamp)
@rtype: string
@return: formatted date, see cfg.date_fmt

Definition at line 603 of file user.py.

00603 
00604     def getFormattedDate(self, tm):
00605         """ Get formatted date adjusted for user's timezone.
00606 
00607         @param tm: time (UTC UNIX timestamp)
00608         @rtype: string
00609         @return: formatted date, see cfg.date_fmt
00610         """
00611         date_fmt = self.date_fmt or self._cfg.date_fmt
00612         return time.strftime(date_fmt, self.getTime(tm))
00613 

Here is the call graph for this function:

def MoinMoin.user.User.getFormattedDateTime (   self,
  tm 
)
Get formatted date and time adjusted for user's timezone.

@param tm: time (UTC UNIX timestamp)
@rtype: string
@return: formatted date and time, see cfg.datetime_fmt

Definition at line 614 of file user.py.

00614 
00615     def getFormattedDateTime(self, tm):
00616         """ Get formatted date and time adjusted for user's timezone.
00617 
00618         @param tm: time (UTC UNIX timestamp)
00619         @rtype: string
00620         @return: formatted date and time, see cfg.datetime_fmt
00621         """
00622         datetime_fmt = self.datetime_fmt or self._cfg.datetime_fmt
00623         return time.strftime(datetime_fmt, self.getTime(tm))

Here is the call graph for this function:

Get list of pages this user wants in the navibar

@rtype: list
@return: quicklinks from user account

Definition at line 780 of file user.py.

00780 
00781     def getQuickLinks(self):
00782         """ Get list of pages this user wants in the navibar
00783 
00784         @rtype: list
00785         @return: quicklinks from user account
00786         """
00787         return self.quicklinks

Get list of pages this user has subscribed to

@rtype: list
@return: pages this user has subscribed to

Definition at line 672 of file user.py.

00672 
00673     def getSubscriptionList(self):
00674         """ Get list of pages this user has subscribed to
00675 
00676         @rtype: list
00677         @return: pages this user has subscribed to
00678         """
00679         return self.subscribed_pages

Here is the caller graph for this function:

def MoinMoin.user.User.getTime (   self,
  tm 
)
Get time in user's timezone.

@param tm: time (UTC UNIX timestamp)
@rtype: int
@return: tm tuple adjusted for user's timezone

Definition at line 593 of file user.py.

00593 
00594     def getTime(self, tm):
00595         """ Get time in user's timezone.
00596 
00597         @param tm: time (UTC UNIX timestamp)
00598         @rtype: int
00599         @return: tm tuple adjusted for user's timezone
00600         """
00601         return timefuncs.tmtuple(tm + self.tz_offset)
00602 

Here is the caller graph for this function:

Return list of recently visited pages.

@rtype: list
@return: pages in trail

Definition at line 905 of file user.py.

00905 
00906     def getTrail(self):
00907         """ Return list of recently visited pages.
00908 
00909         @rtype: list
00910         @return: pages in trail
00911         """
00912         if self._wantTrail():
00913             trail = self._request.session.get('trail', [])
00914         else:
00915             trail = []
00916         return trail

Here is the call graph for this function:

def MoinMoin.user.User.host (   self)
Return user host 

Definition at line 936 of file user.py.

00936 
00937     def host(self):
00938         """ Return user host """
00939         _ = self._request.getText
00940         host = self.isCurrentUser() and self._cfg.show_hosts and self._request.remote_addr
00941         return host or _("<unknown>")

Here is the call graph for this function:

Here is the caller graph for this function:

Check if this user object is the user doing the current request 

Definition at line 920 of file user.py.

00920 
00921     def isCurrentUser(self):
00922         """ Check if this user object is the user doing the current request """
00923         return self._request.user.name == self.name

Here is the caller graph for this function:

def MoinMoin.user.User.isQuickLinkedTo (   self,
  pagelist 
)
Check if user quicklink matches any page in pagelist.

@param pagelist: list of pages to check for quicklinks
@rtype: bool
@return: if user has quicklinked any page in pagelist

Definition at line 788 of file user.py.

00788 
00789     def isQuickLinkedTo(self, pagelist):
00790         """ Check if user quicklink matches any page in pagelist.
00791 
00792         @param pagelist: list of pages to check for quicklinks
00793         @rtype: bool
00794         @return: if user has quicklinked any page in pagelist
00795         """
00796         if not self.valid:
00797             return False
00798 
00799         for pagename in pagelist:
00800             if pagename in self.quicklinks:
00801                 return True
00802             interWikiName = self._interWikiName(pagename)
00803             if interWikiName and interWikiName in self.quicklinks:
00804                 return True
00805 
00806         return False

Here is the call graph for this function:

def MoinMoin.user.User.isSubscribedTo (   self,
  pagelist 
)
Check if user subscription matches any page in pagelist.

The subscription list may contain page names or interwiki page
names. e.g 'Page Name' or 'WikiName:Page_Name'

TODO: check if it's fast enough when getting called for many
      users from page.getSubscribersList()

@param pagelist: list of pages to check for subscription
@rtype: bool
@return: if user is subscribed any page in pagelist

Definition at line 680 of file user.py.

00680 
00681     def isSubscribedTo(self, pagelist):
00682         """ Check if user subscription matches any page in pagelist.
00683 
00684         The subscription list may contain page names or interwiki page
00685         names. e.g 'Page Name' or 'WikiName:Page_Name'
00686 
00687         TODO: check if it's fast enough when getting called for many
00688               users from page.getSubscribersList()
00689 
00690         @param pagelist: list of pages to check for subscription
00691         @rtype: bool
00692         @return: if user is subscribed any page in pagelist
00693         """
00694         if not self.valid:
00695             return False
00696 
00697         import re
00698         # Create a new list with both names and interwiki names.
00699         pages = pagelist[:]
00700         if self._cfg.interwikiname:
00701             pages += [self._interWikiName(pagename) for pagename in pagelist]
00702         # Create text for regular expression search
00703         text = '\n'.join(pages)
00704 
00705         for pattern in self.getSubscriptionList():
00706             # Try simple match first
00707             if pattern in pages:
00708                 return True
00709             # Try regular expression search, skipping bad patterns
00710             try:
00711                 pattern = re.compile(r'^%s$' % pattern, re.M)
00712             except re.error:
00713                 continue
00714             if pattern.search(text):
00715                 return True
00716 
00717         return False

Here is the call graph for this function:

Here is the caller graph for this function:

Check if this user is superuser 

Definition at line 924 of file user.py.

00924 
00925     def isSuperUser(self):
00926         """ Check if this user is superuser """
00927         if not self.valid:
00928             return False
00929         request = self._request
00930         if request.cfg.DesktopEdition and request.remote_addr == '127.0.0.1':
00931             # the DesktopEdition gives any local user superuser powers
00932             return True
00933         superusers = request.cfg.superuser
00934         assert isinstance(superusers, (list, tuple))
00935         return self.name and self.name in superusers

def MoinMoin.user.User.load_from_id (   self,
  password = None 
)
Load user account data from disk.

Can only load user data if the id number is already known.

This loads all member variables, except "id" and "valid" and
those starting with an underscore.

@param password: If not None, then the given password must match the
         password in the user account file.

Definition at line 399 of file user.py.

00399 
00400     def load_from_id(self, password=None):
00401         """ Load user account data from disk.
00402 
00403         Can only load user data if the id number is already known.
00404 
00405         This loads all member variables, except "id" and "valid" and
00406         those starting with an underscore.
00407 
00408         @param password: If not None, then the given password must match the
00409                          password in the user account file.
00410         """
00411         if not self.exists():
00412             return
00413 
00414         data = codecs.open(self.__filename(), "r", config.charset).readlines()
00415         user_data = {'enc_password': ''}
00416         for line in data:
00417             if line[0] == '#':
00418                 continue
00419 
00420             try:
00421                 key, val = line.strip().split('=', 1)
00422                 if key not in self._cfg.user_transient_fields and key[0] != '_':
00423                     # Decode list values
00424                     if key.endswith('[]'):
00425                         key = key[:-2]
00426                         val = decodeList(val)
00427                     # Decode dict values
00428                     elif key.endswith('{}'):
00429                         key = key[:-2]
00430                         val = decodeDict(val)
00431                     # for compatibility reading old files, keep these explicit
00432                     # we will store them with [] appended
00433                     elif key in ['quicklinks', 'subscribed_pages', 'subscribed_events']:
00434                         val = decodeList(val)
00435                     user_data[key] = val
00436             except ValueError:
00437                 pass
00438 
00439         # Validate data from user file. In case we need to change some
00440         # values, we set 'changed' flag, and later save the user data.
00441         changed = 0
00442 
00443         if password is not None:
00444             # Check for a valid password, possibly changing storage
00445             valid, changed = self._validatePassword(user_data, password)
00446             if not valid:
00447                 return
00448 
00449         # Remove ignored checkbox values from user data
00450         for key, label in self._cfg.user_checkbox_fields:
00451             if key in user_data and key in self._cfg.user_checkbox_disable:
00452                 del user_data[key]
00453 
00454         # Copy user data into user object
00455         for key, val in user_data.items():
00456             vars(self)[key] = val
00457 
00458         self.tz_offset = int(self.tz_offset)
00459 
00460         # Remove old unsupported attributes from user data file.
00461         remove_attributes = ['passwd', 'show_emoticons']
00462         for attr in remove_attributes:
00463             if hasattr(self, attr):
00464                 delattr(self, attr)
00465                 changed = 1
00466 
00467         # make sure checkboxes are boolean
00468         for key, label in self._cfg.user_checkbox_fields:
00469             try:
00470                 setattr(self, key, int(getattr(self, key)))
00471             except ValueError:
00472                 setattr(self, key, 0)
00473 
00474         # convert (old) hourly format to seconds
00475         if -24 <= self.tz_offset and self.tz_offset <= 24:
00476             self.tz_offset = self.tz_offset * 3600
00477 
00478         if not self.disabled:
00479             self.valid = 1
00480 
00481         # Mark this user as stored so saves don't send
00482         # the "user created" event
00483         self._stored = True
00484 
00485         # If user data has been changed, save fixed user data.
00486         if changed:
00487             self.save()

Here is the call graph for this function:

def MoinMoin.user.User.mailAccountData (   self,
  cleartext_passwd = None 
)
Mail a user who forgot his password a message enabling
    him to login again.

Definition at line 1000 of file user.py.

01000 
01001     def mailAccountData(self, cleartext_passwd=None):
01002         """ Mail a user who forgot his password a message enabling
01003             him to login again.
01004         """
01005         from MoinMoin.mail import sendmail
01006         from MoinMoin.wikiutil import getLocalizedPage
01007         _ = self._request.getText
01008 
01009         tok = self.generate_recovery_token()
01010 
01011         text = '\n' + _("""\
01012 Login Name: %s
01013 
01014 Password recovery token: %s
01015 
01016 Password reset URL: %s/?action=recoverpass&name=%s&token=%s
01017 """) % (
01018                         self.name,
01019                         tok,
01020                         self._request.script_root,
01021                         url_quote_plus(self.name),
01022                         tok, )
01023 
01024         text = _("""\
01025 Somebody has requested to email you a password recovery token.
01026 
01027 If you lost your password, please go to the password reset URL below or
01028 go to the password recovery page again and enter your username and the
01029 recovery token.
01030 """) + text
01031 
01032 
01033         subject = _('[%(sitename)s] Your wiki account data',
01034                 ) % {'sitename': self._cfg.sitename or "Wiki"}
01035         mailok, msg = sendmail.sendmail(self._request, [self.email], subject,
01036                                     text, mail_from=self._cfg.mail_from)
01037         return mailok, msg
01038 

Here is the call graph for this function:

make a new unique user id 

Definition at line 367 of file user.py.

00367 
00368     def make_id(self):
00369         """ make a new unique user id """
00370         #!!! this should probably be a hash of REMOTE_ADDR, HTTP_USER_AGENT
00371         # and some other things identifying remote users, then we could also
00372         # use it reliably in edit locking
00373         from random import randint
00374         return "%s.%d" % (str(time.time()), randint(0, 65535))

items we want to store into the user profile 

Definition at line 526 of file user.py.

00526 
00527     def persistent_items(self):
00528         """ items we want to store into the user profile """
00529         return [(key, value) for key, value in vars(self).items()
00530                     if key not in self._cfg.user_transient_fields and key[0] != '_']

Here is the caller graph for this function:

def MoinMoin.user.User.removeQuicklink (   self,
  pagename 
)
Remove a page from user quicklinks

Remove both interwiki and simple name from quicklinks.

@param pagename: page name
@type pagename: unicode
@rtype: bool
@return: if pagename was removed

Definition at line 836 of file user.py.

00836 
00837     def removeQuicklink(self, pagename):
00838         """ Remove a page from user quicklinks
00839 
00840         Remove both interwiki and simple name from quicklinks.
00841 
00842         @param pagename: page name
00843         @type pagename: unicode
00844         @rtype: bool
00845         @return: if pagename was removed
00846         """
00847         changed = False
00848         interWikiName = self._interWikiName(pagename)
00849         if interWikiName and interWikiName in self.quicklinks:
00850             self.quicklinks.remove(interWikiName)
00851             changed = True
00852         if pagename in self.quicklinks:
00853             self.quicklinks.remove(pagename)
00854             changed = True
00855 
00856         if changed:
00857             self.save()
00858         return changed

Here is the call graph for this function:

def MoinMoin.user.User.save (   self)
Save user account data to user account file on disk.

This saves all member variables, except "id" and "valid" and
those starting with an underscore.

Definition at line 531 of file user.py.

00531 
00532     def save(self):
00533         """ Save user account data to user account file on disk.
00534 
00535         This saves all member variables, except "id" and "valid" and
00536         those starting with an underscore.
00537         """
00538         if not self.id:
00539             return
00540 
00541         user_dir = self._cfg.user_dir
00542         if not os.path.exists(user_dir):
00543             os.makedirs(user_dir)
00544 
00545         self.last_saved = str(time.time())
00546 
00547         # !!! should write to a temp file here to avoid race conditions,
00548         # or even better, use locking
00549 
00550         data = codecs.open(self.__filename(), "w", config.charset)
00551         data.write("# Data saved '%s' for id '%s'\n" % (
00552             time.strftime(self._cfg.datetime_fmt, time.localtime(time.time())),
00553             self.id))
00554         attrs = self.persistent_items()
00555         attrs.sort()
00556         for key, value in attrs:
00557             # Encode list values
00558             if isinstance(value, list):
00559                 key += '[]'
00560                 value = encodeList(value)
00561             # Encode dict values
00562             elif isinstance(value, dict):
00563                 key += '{}'
00564                 value = encodeDict(value)
00565             line = u"%s=%s\n" % (key, unicode(value))
00566             data.write(line)
00567         data.close()
00568 
00569         arena = 'user'
00570         key = 'name2id'
00571         caching.CacheEntry(self._request, arena, key, scope='wiki').remove()
00572         try:
00573             del self._request.cfg.cache.name2id
00574         except:
00575             pass
00576         key = 'openid2id'
00577         caching.CacheEntry(self._request, arena, key, scope='wiki').remove()
00578         try:
00579             del self._request.cfg.cache.openid2id
00580         except:
00581             pass
00582 
00583         if not self.disabled:
00584             self.valid = 1
00585 
00586         if not self._stored:
00587             self._stored = True
00588             event = events.UserCreatedEvent(self._request, self)
00589             events.send_event(event)

Here is the call graph for this function:

Here is the caller graph for this function:

def MoinMoin.user.User.setBookmark (   self,
  tm 
)
Set bookmark timestamp.

@param tm: timestamp

Definition at line 627 of file user.py.

00627 
00628     def setBookmark(self, tm):
00629         """ Set bookmark timestamp.
00630 
00631         @param tm: timestamp
00632         """
00633         if self.valid:
00634             interwikiname = self._cfg.interwikiname or u''
00635             bookmark = unicode(tm)
00636             self.bookmarks[interwikiname] = bookmark
00637             self.save()

Here is the call graph for this function:

Return user signature using wiki markup

Users sign with a link to their homepage.
Visitors return their host address.

TODO: The signature use wiki format only, for example, it will
not create a link when using rst format. It will also break if
we change wiki syntax.

Definition at line 956 of file user.py.

00956 
00957     def signature(self):
00958         """ Return user signature using wiki markup
00959 
00960         Users sign with a link to their homepage.
00961         Visitors return their host address.
00962 
00963         TODO: The signature use wiki format only, for example, it will
00964         not create a link when using rst format. It will also break if
00965         we change wiki syntax.
00966         """
00967         if self.name:
00968             return self.wikiHomeLink()
00969         else:
00970             return self.host()

Here is the call graph for this function:

def MoinMoin.user.User.subscribe (   self,
  pagename 
)
Subscribe to a wiki page.

To enable shared farm users, if the wiki has an interwiki name,
page names are saved as interwiki names.

@param pagename: name of the page to subscribe
@type pagename: unicode
@rtype: bool
@return: if page was subscribed

Definition at line 718 of file user.py.

00718 
00719     def subscribe(self, pagename):
00720         """ Subscribe to a wiki page.
00721 
00722         To enable shared farm users, if the wiki has an interwiki name,
00723         page names are saved as interwiki names.
00724 
00725         @param pagename: name of the page to subscribe
00726         @type pagename: unicode
00727         @rtype: bool
00728         @return: if page was subscribed
00729         """
00730         if self._cfg.interwikiname:
00731             pagename = self._interWikiName(pagename)
00732 
00733         if pagename not in self.subscribed_pages:
00734             self.subscribed_pages.append(pagename)
00735             self.save()
00736 
00737             # Send a notification
00738             from MoinMoin.events import SubscribedToPageEvent, send_event
00739             e = SubscribedToPageEvent(self._request, pagename, self.name)
00740             send_event(e)
00741             return True
00742 
00743         return False

Here is the call graph for this function:

def MoinMoin.user.User.unsubscribe (   self,
  pagename 
)
Unsubscribe a wiki page.

Try to unsubscribe by removing non-interwiki name (leftover
from old use files) and interwiki name from the subscription
list.

Its possible that the user will be subscribed to a page by more
then one pattern. It can be both pagename and interwiki name,
or few patterns that all of them match the page. Therefore, we
must check if the user is still subscribed to the page after we
try to remove names from the list.

@param pagename: name of the page to subscribe
@type pagename: unicode
@rtype: bool
@return: if unsubscrieb was successful. If the user has a
    regular expression that match, it will always fail.

Definition at line 744 of file user.py.

00744 
00745     def unsubscribe(self, pagename):
00746         """ Unsubscribe a wiki page.
00747 
00748         Try to unsubscribe by removing non-interwiki name (leftover
00749         from old use files) and interwiki name from the subscription
00750         list.
00751 
00752         Its possible that the user will be subscribed to a page by more
00753         then one pattern. It can be both pagename and interwiki name,
00754         or few patterns that all of them match the page. Therefore, we
00755         must check if the user is still subscribed to the page after we
00756         try to remove names from the list.
00757 
00758         @param pagename: name of the page to subscribe
00759         @type pagename: unicode
00760         @rtype: bool
00761         @return: if unsubscrieb was successful. If the user has a
00762             regular expression that match, it will always fail.
00763         """
00764         changed = False
00765         if pagename in self.subscribed_pages:
00766             self.subscribed_pages.remove(pagename)
00767             changed = True
00768 
00769         interWikiName = self._interWikiName(pagename)
00770         if interWikiName and interWikiName in self.subscribed_pages:
00771             self.subscribed_pages.remove(interWikiName)
00772             changed = True
00773 
00774         if changed:
00775             self.save()
00776         return not self.isSubscribedTo([pagename])

Here is the call graph for this function:

Return wiki markup usable as a link to the user homepage,
    it doesn't matter whether it already exists or not.

Definition at line 942 of file user.py.

00942 
00943     def wikiHomeLink(self):
00944         """ Return wiki markup usable as a link to the user homepage,
00945             it doesn't matter whether it already exists or not.
00946         """
00947         wikiname, pagename = wikiutil.getInterwikiHomePage(self._request, self.name)
00948         if wikiname == 'Self':
00949             if wikiutil.isStrictWikiname(self.name):
00950                 markup = pagename
00951             else:
00952                 markup = '[[%s]]' % pagename
00953         else:
00954             markup = '[[%s:%s]]' % (wikiname, pagename)
00955         return markup

Here is the caller graph for this function:


Member Data Documentation

Definition at line 289 of file user.py.

Definition at line 331 of file user.py.

Definition at line 318 of file user.py.

Definition at line 294 of file user.py.

Definition at line 293 of file user.py.

Definition at line 292 of file user.py.

Definition at line 295 of file user.py.

Definition at line 319 of file user.py.

Definition at line 320 of file user.py.

Definition at line 326 of file user.py.

Definition at line 327 of file user.py.

Definition at line 323 of file user.py.

Definition at line 312 of file user.py.

Definition at line 291 of file user.py.

Definition at line 324 of file user.py.

Definition at line 316 of file user.py.

Definition at line 328 of file user.py.

Definition at line 354 of file user.py.

Definition at line 301 of file user.py.

Definition at line 321 of file user.py.

Definition at line 317 of file user.py.

Definition at line 309 of file user.py.

Definition at line 322 of file user.py.

Definition at line 325 of file user.py.

Definition at line 315 of file user.py.

Definition at line 290 of file user.py.


The documentation for this class was generated from the following file: