How to use the klein.interfaces.ISimpleAccount function in klein

To help you get started, we’ve selected a few klein examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github twisted / klein / loginspike.py View on Github external
def authorizeChirper(session_store, transaction, session):
    # type: (ISessionStore, Transaction, ISession) -> Deferred
    account = (yield session.authorize([ISimpleAccount]))[ISimpleAccount]
    if account is not None:
        returnValue(Chirper(transaction, account, chirpTable))
github twisted / klein / loginspike.py View on Github external
    style.renderMethod, account=Authorization(ISimpleAccount, required=False)
)
def ifLoggedIn(tag, account):
    # type: (Tag, ISimpleAccount) -> Any
    """
    Render the given tag if the user is logged in, otherwise don't.
    """
    if account is None:
        return u""
    else:
        return tag
github twisted / klein / loginspike.py View on Github external
defaults={
        "homeActive": "",
        "loginActive": "",
        "signupActive": "",
        "sessionsActive": "",
    }
)

from sqlalchemy import Column, String, ForeignKey

import attr

@attr.s
class Chirper(object):
    transaction = attr.ib(type=Transaction)
    account = attr.ib(type=ISimpleAccount)
    chirpTable = attr.ib(type=Table)

    def chirp(self, value):
        # type: (str) -> Deferred
        chirpTable = self.chirpTable
        return self.transaction.execute(chirpTable.insert().values(
                account_id=self.account.accountID,
                chirp=value
            ))

appMetadata = MetaData()
sessionSchema = SessionSchema.withMetadata(appMetadata)
chirpTable = Table(
    'chirp', appMetadata,
    Column("account_id", String(),
           ForeignKey(sessionSchema.account.c.account_id)),