コード例 #1
0
 def register(self, ctx, username, email,
              password, screename, homepage):
     properties = dict(screename=screename or username,
                       login=username,
                       password=password,
                       group_id=3,
                       email=email,
                       homepage=homepage
                       ) 
         
     def success(result, ctx, username):
         d = IUsersDatabase(IS(ctx)).findUser(username)
         d.addCallback(login, ctx)
         return d
     def login(avatar, ctx):
         # if using new guard
         # s = inevow.ISession(ctx)
         # creds = credentials.UsernamePassword(avatar['ulogin'], avatar['upassword'])
         # s.setComponent(creds, ignoreClass=True)
         s = inevow.ISession(ctx)
         res = index.Main()
         res.remember(avatar, IA)
         s.setResourceForPortal(res, s.guard.resource.portal, res.logout)
         #
     uri = iw.ILastURL(inevow.ISession(ctx), None)
     if uri:
         inevow.ISession(ctx).unsetComponent(iw.ILastURL)
     inevow.IRequest(ctx).setComponent(iformless.IRedirectAfterPost,uri or '')
     d = IUsersDatabase(IS(ctx)).addUser(properties)
     d.addCallback(success, ctx, username)        
     return d
コード例 #2
0
ファイル: auth.py プロジェクト: BackupTheBerlios/weever-svn
class SimpleChecker:
    """
    A simple checker implementation. Delegates storage/retrieval to userdb object
    """
    __implements__ = checkers.ICredentialsChecker
    credentialInterfaces = (credentials.IUsernamePassword,)

    def __init__(self, store):
        self.userdb = IUsersDatabase(store)

    #implements ICredentialChecker
    def requestAvatarId(self, creds):
        """Return the avatar id of the avatar which can be accessed using
        the given credentials.

        credentials will be an object with username and password attributes
        we need to raise an error to indicate failure or return a username
        to indicate success. requestAvatar will then be called with the avatar
        id we returned.
        """
        d = self.userdb.findUser(creds.username)
        return d.addCallback(self.verify, creds)
    
    def verify(self, user, creds):
        if user is not None:
            return defer.maybeDeferred(
                creds.checkPassword, user['upassword']).addCallback(
                self._cbPasswordMatch, user)
        else:
            print "No user named: ",creds.username
            raise error.UnauthorizedLogin()

    def _cbPasswordMatch(self, matched, user):
        if matched:
            return user
        else:
            print "password didn't match: ",user['ulogin']
            return failure.Failure(error.UnauthorizedLogin())
コード例 #3
0
ファイル: auth.py プロジェクト: BackupTheBerlios/weever-svn
 def __init__(self, store):
     self.userdb = IUsersDatabase(store)
コード例 #4
0
 def success(result, ctx, username):
     d = IUsersDatabase(IS(ctx)).findUser(username)
     d.addCallback(login, ctx)
     return d