Changeset 4087


Ignore:
Timestamp:
26 Apr 2009, 01:58:47 (16 years ago)
Author:
uli
Message:

Make Account objects more usable.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • waeup/branches/ulif-rewrite/src/waeup/authentication.py

    r4075 r4087  
    7777
    7878class Account(grok.Model):
    79     def __init__(self, name, password):
     79    def __init__(self, name, password, title=None, description=None):
    8080        self.name = name
     81        if title is None:
     82            title = name
     83        if description is None:
     84            description = title
     85        self.title = title
     86        self.description = description
    8187        self.setPassword(password)
    8288
     
    121127        if login == 'grok':
    122128            return Account('grok', 'grok')
    123         return
    124         #... look up the account object and return it ...
     129
     130        # ... look up the account object and return it ...
     131        usercontainer = self.getUserContainer()
     132        if usercontainer is None:
     133            return
     134        return usercontainer.get(login, None)
     135
     136    def addAccount(self, account):
     137        usercontainer = self.getUserContainer()
     138        if usercontainer is None:
     139            return
     140        # XXX: complain if name already exists...
     141        usercontainer.addAccount(account)
     142
     143    def getUserContainer(self):
     144        site = grok.getSite()
     145        return getAttribute(site, 'users', None)
Note: See TracChangeset for help on using the changeset viewer.