Beispiel #1
0
def login():
    if request.method == 'POST':
        pprint(request.json)
        username = request.json['username']
        password = request.json['password']

        records= dbcon.query_db("select * from LDAP where EMAIL = ? AND PWD_HASH = ?",  [username, password] , one=True)

        if records is None :
            print("+++++++++++ INVALID CREDENTIALS +++++++++++\n")
            return "INVALID_CREDENTIALS" 

        else:

            #if IS_ACTIVE = 1 then auth token is already set, hence return that auth token
            if records["is_active"] == 1:
                return records["current_token"]
            else:

                print("Generating New Token For User")

                #generate new token
                auth_token = secrets.token_hex(32)
                update_query = "UPDATE LDAP SET CURRENT_TOKEN = ?, IS_ACTIVE = 1  WHERE EMAIL = ? "
            
                dbcon.query_db(update_query, [auth_token, username], one=True)
                return auth_token
    else:
        return "INVALID_REQUEST_METHOD"
Beispiel #2
0
def check_balance():
    pprint(request.json)
    auth_token = request.json['auth_token']
    query = "select * from LDAP where CURRENT_TOKEN = ?"
    records = dbcon.query_db(query, [auth_token], one=True)
    print("Current Balance: {}".format(records["balance"]))
    return str(records["balance"])
Beispiel #3
0
def p2p():
    pprint(request.json)
    auth_token = request.json["auth_token"]
    query = 'select * from LDAP where CURRENT_TOKEN = ?'
    payer_records = dbcon.query_db(query, [auth_token], one=True)
    payer = payer_records["email"]
    payee = request.json["payee"]
    tx_amount = int(request.json["amount"])

    #check validity of payee
    payee_records = dbcon.query_db("select * from LDAP where EMAIL = ?", [payee], one=True)
    if payee_records is None:
        print("+++++++++++ PAYEE DOES NOT EXIST +++++++++++\n")
        return "PAYEE_DOES_NOT_EXIST"
    
    #checking if payer has enough balance

    if payer_records["balance"] >= tx_amount :
        #update payee and payer records
        dbcon.query_db("update LDAP set BALANCE = ? where EMAIL = ? ", [payee_records["balance"] + tx_amount, payee], one=True)
        dbcon.query_db("update LDAP set BALANCE = ? where EMAIL = ?", [payer_records["balance"] - tx_amount, payer], one=True)
            
        print("SUCCESS\n")
        return "TX_SUCCESS"

    else:
        print("+++++++++++ BALANCE UNDERFLOW +++++++++++\n")
        return "BALANCE_UNDERFLOW" 
Beispiel #4
0
    def wrapper():
        if request.method == 'POST':
            print("Decorator Check\n")
            pprint(request.json)
            auth_token = request.json['auth_token']

            records = dbcon.query_db(
                "select * from LDAP where CURRENT_TOKEN = ? AND IS_ACTIVE = 1",
                [auth_token],
                one=True)

            if records is None:
                return "+++++++++++ AUTH FAiLURE +++++++++++"
            else:
                return func()
Beispiel #5
0
def get_qr():
    #receive the json object containing values for generating the qr code
    #json keys are - {vendorid, amount, tokenid(for auth)<ignore for now>}
    '''pprint(request.json)
    vendorid = request.json['vendorid']
    amount = request.json['amount']
    tokenid = request.json['tokenid']
    url = qr.gen_qr("VID"+vendorid+"AMNT"+amount+"TID"+tokenid)
    url.svg('test.svg', scale = 1 )
    print(url.terminal())
    return qr.qrencode64(url)'''
    pprint(request.json)
    auth_token = request.json["auth_token"]
    query = 'select * from LDAP where CURRENT_TOKEN = ?'
    payer_records = dbcon.query_db(query, [auth_token], one=True)
    payer = payer_records["email"]
    payee = request.json["payee"]
    tx_amount = int(request.json["amount"])

    #check validity of payee
    payee_records = dbcon.query_db("select * from LDAP where EMAIL = ?", [payee], one=True)
    if payee_records is None:
        print("+++++++++++ PAYEE DOES NOT EXIST +++++++++++\n")
        return "PAYEE_DOES_NOT_EXIST"
    
    #checking if payer has enough balance

    if payer_records["balance"] >= tx_amount :
        #update payee and payer records
        dbcon.query_db("update LDAP set BALANCE = ? where EMAIL = ? ", [payee_records["balance"] + tx_amount, payee], one=True)
        dbcon.query_db("update LDAP set BALANCE = ? where EMAIL = ?", [payer_records["balance"] - tx_amount, payer], one=True)
        
        print("CREATING QR CODE\n")
        qr_string = "VID" + payee + "," + "AMOUNT" + request.json["amount"]
        url = qr.gen_qr(qr_string)
        url.svg('test.svg', scale=1)
        print(url.terminal())
        print("SUCCESS\n")
        #return "Yes"
        return jsonify({"STATUS":"TX_SUCCESS", "QR":str(qr.qrencode64(url))})

    else:
        print("+++++++++++ BALANCE UNDERFLOW +++++++++++\n")
        return "BALANCE_UNDERFLOW"