示例#1
0
    def login(self, request, session, creds, segments):
        """Called to check the credentials of a user.

        Here we extend guard's implementation to preauthenticate users
        if they have a valid persistant session.
        """
        print "Login"
        if isinstance(creds, credentials.Anonymous):
            preauth = self.authenticatedUserForKey(session.uid)
            if preauth is not None:
                self.savorSessionCookie(request)
                creds = userbase.Preauthenticated(preauth)

        def cbLoginSuccess(input):
            """User authenticated successfully.

            Create the persistent session, and associate it with the
            username. (XXX it doesn't work like this now)
            """

            user = request.args.get('username')
            if user is not None:
                # create a database session and associate it with this user
                cookieValue = session.uid
                if request.args.get('rememberMe'):
                    self.createSessionForKey(cookieValue, creds.username)
                    self.savorSessionCookie(request)
            return input

        return guard.SessionWrapper.login(self, request, session, creds,
                                          segments).addCallback(cbLoginSuccess)
示例#2
0
 def test_repr(self):
     """
     L{userbase.Preauthenticated} has a repr which identifies its type and
     its user.
     """
     self.assertEqual(repr(userbase.Preauthenticated(u'foo@bar')),
                      '<Preauthenticated: foo@bar>')
示例#3
0
 def test_usernamehashedpassword(self):
     """
     L{Preauthenticated} implements L{IUsernameHashedPassword} and succeeds
     all authentication checks.
     """
     creds = userbase.Preauthenticated('foo@bar')
     self.assertTrue(
         verifyObject(IUsernameHashedPassword, creds),
         "Preauthenticated does not implement IUsernameHashedPassword")
     self.assertTrue(
         creds.checkPassword('arbitrary bytes'),
         "Preauthenticated did not accept an arbitrary password.")
示例#4
0
 def test_preauthenticated(self):
     """
     L{LoginSystem.requestAvatarId} returns the store identifier of the
     L{LoginAccount} associated with a L{Preauthenticated} credentials
     object.
     """
     account = self.realm.addAccount(
         self.localpart, self.domain, self.password)
     username = '******' % (self.localpart, self.domain)
     d = self._requestAvatarId(userbase.Preauthenticated(username))
     d.addCallback(self.assertEqual, account.storeID)
     return d
示例#5
0
    def validateTo(self, user):
        addr = '@'.join((user.dest.local, user.dest.domain))
        d = self.portal.login(userbase.Preauthenticated(addr), None,
                              iquotient.IMIMEDelivery)

        def loggedIn((iface, avatar, logout)):
            logout()  # XXX???

            def receiverCreator():
                return avatar.createMIMEReceiver(
                    u"smtp://%s@%s" % (user.dest.local, user.dest.domain))

            return receiverCreator

        def notLoggedIn(err):
            err.trap(userbase.NoSuchUser)
            return defer.fail(smtp.SMTPBadRcpt(user))

        d.addCallbacks(loggedIn, notLoggedIn)
        return d