Beispiel #1
0
 def checkCookie(self, cookie):
     if not cookie:
         return
     (username, token) = cookie.rsplit("#", 1)
     # if auth.check_token(username, token):
     if auth_client.check_token(username, token):
         self.setPerson(username, token)
Beispiel #2
0
def transfer(sender, recipient, zoobars, token):
    if not auth_client.check_token(sender, token):
        return
    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()
Beispiel #3
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 
Beispiel #4
0
def transfer(sender, recipient, zoobars, token):
    if not auth.check_token(sender, token):
        print("Sender '%s' token didn't match " % sender)
        return
    if sender == recipient:
        print("Sender and recipient are same")
        return
    bankdb = bank_setup()
    senderp = bankdb.query(Bank).get(sender)
    recipientp = bankdb.query(Bank).get(recipient)

    if recipientp is None:
        print("No such recipient exist: %s" % recipient)
        return

    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()
Beispiel #5
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()
Beispiel #6
0
def transfer(sender, recipient, zoobars,token):
    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()
    except(KeyError, ValueError, AttributeError, AssertionError) as e:
        return False
Beispiel #7
0
def update_pcode(username, token, pcode):
    if not auth_client.check_token(username, token):
        raise ValueError()       
    pcode_db = pcode_setup()
    pcode_item = pcode_db.query(Pcode).get(username)
    if not pcode_item:
        pcode_item = Pcode()
        pcode_item.username = username
        pcode_item.profile = pcode
        pcode_db.add(pcode_item)
    else:    
        pcode_item.profile = pcode
    pcode_db.commit()
Beispiel #8
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)
Beispiel #9
0
 def rpc_transfer(self, sender, recipient, zoobars, token):
     if not auth_client.check_token(sender,
                                    token) and self.caller != "profile":
         raise PermissionError()
     return bank.transfer(sender, recipient, zoobars)
Beispiel #10
0
 def rpc_transfer(self, sender, recipient, zoobars, token):
     if not auth_client.check_token(sender, token):
         raise ValueError("Invalid token")
     return bank.transfer(sender, recipient, zoobars)