Exemplo n.º 1
0
    def pypy_xfer(self, rcptname, zoobars, selfname, token):
        balance_db = zoodb.balance_setup()
        sender = balance_db.query(zoodb.Balance).get(selfname)
        recipient = balance_db.query(zoodb.Balance).get(rcptname)

        if not sender:
            raise Exception('sender ' + selfname + ' not found')
        if not recipient:
            raise Exception('recipient ' + rcptname + ' not found')

        sender_balance = sender.zoobars - zoobars
        recipient_balance = recipient.zoobars + zoobars

        if sender_balance < 0 or recipient_balance < 0:
            raise ValueError()
        
        msg = 'modify@#' \
            + selfname + "@#" \
            + str(sender_balance) + "@#" \
            + token
        resp = call("blnssvc/sock", msg).strip()
        if not resp:
            raise ValueError()

        msg = 'modify@#' \
            + rcptname + "@#" \
            + str(recipient_balance) + "@#" \
            + token
        resp = call("blnssvc/sock", msg).strip()
            
        msg = selfname + "@#" \
            + rcptname + "@#" \
            + str(zoobars)

        resp = call("logsvc/sock", msg).strip()
Exemplo n.º 2
0
    def loginCookie(self, person):
        self.person = person
        msg = 'logincookie@#'\
            + person.username
        resp = call('authsvc/sock', msg).strip()
        log("---auth----- msg: %s Response = %s" % (msg, resp))

        balancedb = balance_setup()
        person.zoobars = balancedb.query(Balance).get(person.username).zoobars
        return "%s#%s" % (person.username, resp)
Exemplo n.º 3
0
    def loginCookie(self, person):
        self.person = person
        msg = 'logincookie@#'\
            + person.username
        resp = call('authsvc/sock', msg).strip()
        log("---auth----- msg: %s Response = %s" % (msg, resp))

        balancedb = balance_setup()
        person.zoobars = balancedb.query(Balance).get(person.username).zoobars
        return "%s#%s" % (person.username, resp)
Exemplo n.º 4
0
    def addRegistration(self, username, password):
        person = g.persondb.query(Person).get(username)
        if person:
            return None
        newperson = Person()
        newperson.username = username
        g.persondb.add(newperson)
        msg = 'register@#'\
            + username + '@#'\
            + password
        cookie = call('authsvc/sock', msg).strip()
        log("---auth----- msg: %s Response = %s" % (msg, cookie))

        msg = 'new@#' + username
        resp = call('blnssvc/sock', msg).strip()
        log("---auth----- msg: %s Response = %s" % (msg,resp))

        self.person = newperson
        balancedb = balance_setup()
        newperson.zoobars = balancedb.query(Balance).get(newperson.username).zoobars

        return cookie
Exemplo n.º 5
0
    def addRegistration(self, username, password):
        person = g.persondb.query(Person).get(username)
        if person:
            return None
        newperson = Person()
        newperson.username = username
        g.persondb.add(newperson)
        msg = 'register@#'\
            + username + '@#'\
            + password
        cookie = call('authsvc/sock', msg).strip()
        log("---auth----- msg: %s Response = %s" % (msg, cookie))

        msg = 'new@#' + username
        resp = call('blnssvc/sock', msg).strip()
        log("---auth----- msg: %s Response = %s" % (msg, resp))

        self.person = newperson
        balancedb = balance_setup()
        newperson.zoobars = balancedb.query(Balance).get(
            newperson.username).zoobars

        return cookie
Exemplo n.º 6
0
    def checkLogin(self, username, password):
        person = g.persondb.query(Person).get(username)
        if not person:
            return None

        msg = 'checklogin@#'\
            + username + "@#"\
            + password
        resp = call("authsvc/sock", msg).strip()
        log("---auth----- Response = %s" % resp)

        if resp == "true":
            return self.loginCookie(person)
        else:
            return None
Exemplo n.º 7
0
    def checkLogin(self, username, password):
        person = g.persondb.query(Person).get(username)
        if not person:
            return None

        msg = 'checklogin@#'\
            + username + "@#"\
            + password
        resp = call("authsvc/sock", msg).strip()
        log("---auth----- Response = %s" % resp)

        if resp == "true":
            return self.loginCookie(person)
        else:
            return None
Exemplo n.º 8
0
    def checkCookie(self, cookie):
        if not cookie:
            return

        (username, token) = cookie.rsplit("#", 1)
        person = g.persondb.query(Person).get(username)
        balancedb = balance_setup()
        person.zoobars = balancedb.query(Balance).get(username).zoobars

        msg = 'checkcookie@#'\
            + username + "@#"\
            + token + "@#"
        resp = call('authsvc/sock', msg).strip()

        if resp:
            self.person = person
Exemplo n.º 9
0
    def checkCookie(self, cookie):
        if not cookie:
            return

        (username, token) = cookie.rsplit("#", 1)
        person = g.persondb.query(Person).get(username)
        balancedb = balance_setup()
        person.zoobars = balancedb.query(Balance).get(username).zoobars

        msg = 'checkcookie@#'\
            + username + "@#"\
            + token + "@#"
        resp = call('authsvc/sock', msg).strip()

        if resp:
            self.person = person
Exemplo n.º 10
0
msgs = req.split("@#")
action = msgs[0]

if action == 'new':
    balance = Balance()
    balance.username = msgs[1]
    balance.zoobars = 10
    db = balance_setup()
    db.add(balance)
    db.commit()
elif action == 'modify':
    #check token
    #msgs[3] token
    
    msg = 'checkcookie@#' \
        + msgs[1] + "@#" \
        + msgs[3]
    resp = call("authsvc/sock", msg).strip() 
    if not resp:
        print None
    else:
        db = balance_setup()
        balance = db.query(Balance).get(msgs[1])
        balance.zoobars = int(msgs[2])
        db.update(balance)
        db.commit()      
        db = balance_setup()
        print db.query(Balance).get(msgs[1]).zoobars
else:
    raise Exception("unknown action %s" % msgs[0])
Exemplo n.º 11
0
msgs = req.split("@#")
action = msgs[0]

if action == 'new':
    balance = Balance()
    balance.username = msgs[1]
    balance.zoobars = 10
    db = balance_setup()
    db.add(balance)
    db.commit()
elif action == 'modify':
    #check token
    #msgs[3] token

    msg = 'checkcookie@#' \
        + msgs[1] + "@#" \
        + msgs[3]
    resp = call("authsvc/sock", msg).strip()
    if not resp:
        print None
    else:
        db = balance_setup()
        balance = db.query(Balance).get(msgs[1])
        balance.zoobars = int(msgs[2])
        db.update(balance)
        db.commit()
        db = balance_setup()
        print db.query(Balance).get(msgs[1]).zoobars
else:
    raise Exception("unknown action %s" % msgs[0])
Exemplo n.º 12
0
#!/usr/bin/python

from unixclient import call



msg = 'modify@#' \
    + "test1" + "@#" \
    + str(2)
resp = call("/jail/blnssvc/sock", msg)
print "Response = ", resp

Exemplo n.º 13
0
def transfer():
    warning = None
    try:
        if 'recipient' in request.form:
            recipient = g.persondb.query(Person)\
                .get(request.form['recipient'])
            if cmp(recipient.username, g.user.person.username) == 0:
                raise ValueError()
            #zoobars > 0 and be digit
            if not request.form['zoobars'].isdigit():
                raise ValueError()
            zoobars = int(request.form['zoobars'])

            balancedb = g.balancedb.query(Balance)
            recipient_blns_obj = balancedb.get(recipient.username)
            sender_blns_obj = balancedb.get(g.user.person.username)

            sender_balance = sender_blns_obj.zoobars - zoobars
            recipient_balance = recipient_blns_obj.zoobars + zoobars
            
            #recipient_balance 
            if sender_balance < 0 or recipient_balance < 0:
                raise ValueError()
           
            #sender_balance_obj.zoobars = sender_balance
            #recipient_balance_obj.zoobars = recipient_balance
           
            token = request.cookies.get("PyZoobarLogin").split("#")[1]
            #log("token is:%s"%token)            
            msg = 'modify@#' \
                + g.user.person.username + "@#" \
                + str(sender_balance) + "@#" \
                + token
            resp = call("blnssvc/sock", msg).strip()
            log("-------- msg: %s Response = %s" % (msg,resp))
            if not resp:
               raise ValueError()
            
            msg = 'modify@#' \
                + recipient.username + "@#" \
                + str(recipient_balance) + "@#" \
                + token
            resp = call("blnssvc/sock", msg).strip()
            log("-------- Response = %s" % resp )
           
            balancedb = balance_setup()
            log("test %d"% balancedb.query(Balance)\
                .get(g.user.person.username).zoobars)
            log("test %d"% balancedb.query(Balance)\
                .get(recipient.username).zoobars)
            #transfer = Transfer()
            #transfer.sender = g.user.person.username
            #transfer.recipient = recipient.username
            #transfer.amount = zoobars
            #transfer.time = time.asctime()
            #g.transferdb.add(transfer)
            
            msg = g.user.person.username + "@#" \
                + recipient.username + "@#" \
                + str(zoobars)

            resp = call("logsvc/sock", msg).strip()
            log("-------- Response = %s" % resp )
           
            warning = "Sent %d zoobars" % zoobars
    except (KeyError, ValueError, AttributeError) as e:
        log("Transfer exception: %s" % str(e))
        warning = "Transfer to %s failed" % request.form['recipient']

    return render_template('transfer.html', warning=warning)