Пример #1
0
def transfer(sender, recipient, token, zoobars):
    try:
        if auth_client.check_token(sender, token) is False:
            raise AssertionError()
        else: 
            db = bank_setup()
            senderp = db.query(Bank).get(sender)
            recipientp = db.query(Bank).get(recipient)

            sender_balance = senderp.zoobars - zoobars
            recipient_balance = recipientp.zoobars + zoobars

            if sender_balance < 0 or recipient_balance < 0:
                raise ValueError()

            senderp.zoobars = sender_balance
            recipientp.zoobars = recipient_balance
            db.commit()

            transfer = Transfer()
            transfer.sender = sender
            transfer.recipient = recipient
            transfer.amount = zoobars
            transfer.time = time.asctime()

            transferdb = transfer_setup()
            transferdb.add(transfer)
            transferdb.commit()
            return True

    except (KeyError, ValueError, AttributeError, AssertionError) as e:
        return False 
Пример #2
0
def transfer(sender, recipient, zoobars, token):
    if not auth_client.check_token(sender, token):
        raise RuntimeError()
    bankdb = bank_setup()
    senderp = bankdb.query(Bank).get(sender)
    recipientp = bankdb.query(Bank).get(recipient)

    sender_balance = senderp.zoobars - zoobars
    recipient_balance = recipientp.zoobars + zoobars

    if sender_balance < 0 or recipient_balance < 0:
        raise ValueError()

    senderp.zoobars = sender_balance
    recipientp.zoobars = recipient_balance
    bankdb.commit()

    transfer = Transfer()
    transfer.sender = sender
    transfer.recipient = recipient
    transfer.amount = zoobars
    transfer.time = time.asctime()

    transferdb = transfer_setup()
    transferdb.add(transfer)
    transferdb.commit()
Пример #3
0
 def checkCookie(self, cookie):
     if not cookie:
         return
     (username, token) = cookie.rsplit("#", 1)
     if auth_client.check_token(username, token):
         self.setPerson(username, token)