示例#1
0
def getBalance(username
               ):  #used to display the users balance at the top of each screen
    username = encrypt.encrypt(username)
    _SQL = """SELECT balance FROM users WHERE username = %s;"""
    with DBcm.UseDatabase(config) as database:
        database.execute(_SQL, (username, ))
        balance = database.fetchall()
    decBalance = encrypt.decrypt(balance[0][0])
    numBal = '{:.2f}'.format(float(decBalance))
    return numBal
示例#2
0
def getPrice(name):
    decPrice = []
    name = encrypt.encrypt(name)
    _SQL = """SELECT price FROM cardtypes WHERE name = %s;"""

    with DBcm.UseDatabase(config) as database:
        database.execute(_SQL, (name, ))
        price = database.fetchall()
    decPrice.append(encrypt.decrypt(price[0][0]))
    return decPrice
示例#3
0
def getCard(id):
    decCard = []
    _SQL = """SELECT type, prize FROM scratchcards WHERE id = %s AND redeemed = 0"""

    with DBcm.UseDatabase(config) as database:
        database.execute(_SQL, (id, ))
        card = database.fetchone()
    if not card:
        return card
    for i in card:
        decCard.append(encrypt.decrypt(i))
    return decCard
示例#4
0
def getCardTypes():
    decCards = []
    temp = []
    _SQL = """SELECT name, price FROM cardtypes"""

    with DBcm.UseDatabase(config) as database:
        database.execute(_SQL)
        cards = database.fetchall()
    for i in cards:
        temp = []
        for d in i:
            temp.append(encrypt.decrypt(d))
        decCards.append(temp)

    return decCards
示例#5
0
def getCardPrizes(name):
    temp = []
    decPrizes = []
    name = encrypt.encrypt(name)

    _SQL = """SELECT prize1, prize2, prize3, prize4 FROM cardtypes WHERE name = %s"""

    with DBcm.UseDatabase(config) as database:
        database.execute(_SQL, (name, ))
        prizes = database.fetchall()
    for i in prizes:
        temp = []
        for d in i:
            temp.append(encrypt.decrypt(d))
        decPrizes.append(temp)
    return decPrizes
示例#6
0
def getPrizes(name):
    name = encrypt.encrypt(name)
    decPrizes = []
    temp = []
    _SQL = """SELECT * FROM cardtypes WHERE name = %s;"""

    with DBcm.UseDatabase(config) as database:
        database.execute(_SQL, (name, ))
        prizes = database.fetchall()
    for i in prizes:
        temp = []
        for d in i[1:]:
            temp.append(encrypt.decrypt(d))
        decPrizes.append(temp)

    return decPrizes
示例#7
0
def getPaymentCard(id):
    decCard = []
    temp = []
    _SQL = """SELECT id, cardNumber, expiryMonth, expiryYear, holderFirstName, cardType, holderSurname from paymentcards WHERE id = %s""".format(
        id=id)

    with DBcm.UseDatabase(config) as database:
        database.execute(_SQL, (id, ))
        paymentCard = database.fetchall()

    for i in paymentCard:
        temp.append(i[0])
        for d in i[1:]:
            temp.append(encrypt.decrypt(d))
        decCard.append(temp)
        temp = []
    return decCard
示例#8
0
def login(username, password):
    username = encrypt.encrypt(username)

    _SQL = """SELECT username,password FROM users WHERE username = %s;"""
    with DBcm.UseDatabase(config) as database:
        database.execute(_SQL, (username, ))
        user = database.fetchall()

    if not len(user):
        return False

    decUser = []
    decUser.append(user[0][0])
    decUser.append(encrypt.decrypt(user[0][1]))
    if decUser[1] != password:
        return False

    return True
示例#9
0
def adminLogin(admin):
    decUser = []
    admin['user'] = encrypt.encrypt(admin['user'])

    _SQL = """SELECT adminUsername, adminPassword FROM admin WHERE adminUsername = %s"""

    with DBcm.UseDatabase(config) as database:
        database.execute(_SQL, (admin['user'], ))
        user = database.fetchone()
    if not len(user):
        return False

    for i in range(0, 2):
        decUser.append(encrypt.decrypt(user[i]))

    if admin['password'] != decUser[1]:
        return False
    return True
示例#10
0
def getPaymentCards(user):
    decCards = []
    temp = []
    user = encrypt.encrypt(user)
    _SQL = """SELECT id, cardNumber, cardType FROM paymentcards WHERE user = %s"""

    with DBcm.UseDatabase(config) as database:
        database.execute(_SQL, (user, ))
        paymentCards = database.fetchall()

    for i in paymentCards:
        temp.append(i[0])
        for d in i[1:]:
            temp.append(encrypt.decrypt(d))
        decCards.append(temp)
        temp = []

    return decCards
示例#11
0
def getCards(user):
    cards = []
    temp = []
    user = encrypt.encrypt(user)

    _SQL = """SELECT id, boughtOn, type, boughtBy FROM scratchcards WHERE user = %s
     AND redeemed = 0"""

    with DBcm.UseDatabase(config) as database:
        database.execute(_SQL, (user, ))
        userCards = database.fetchall()

    for i in userCards:
        temp.append(i[0])
        for d in i[1:]:
            temp.append(encrypt.decrypt(d))
        cards.append(temp)
        temp = []
    return cards