Пример #1
0
def getUser(userid):
    sql = "SELECT username,email,about FROM users WHERE userid = '{}'".format(
        userid)
    try:
        conn.connect()
        cursor = conn.cursor()
        cursor.execute(sql)
        data = cursor.fetchall()[0]
        cursor.close()
        conn.close()
        return data
    except:
        return False
Пример #2
0
def getProduct(productid):
    print(productid)
    sql = "SELECT * FROM products WHERE productid = '{}'".format(productid)
    try:
        conn.connect()
        cursor = conn.cursor()
        cursor.execute(sql)
        data = cursor.fetchall()[0]
        cursor.close()
        conn.close()
        return data
    except:
        return False
Пример #3
0
def updateProduct(info):
    sql = "UPDATE products SET name = '{1}', price = {2}, description = '{3}', category = '{4}' where productid = {0}".format(
        info[0], info[1], info[2], info[3], info[4])
    try:
        conn.connect()
        cursor = conn.cursor()
        cursor.execute(sql)
        conn.commit()
        data = cursor.rowcount
        cursor.close()
        conn.close()
        return data
    except:
        return False
Пример #4
0
def editProfile(username, about, userid):
    print(username, about, userid)
    query = ''' UPDATE users SET username = %s, about =%s WHERE userid =%s '''
    data = (username, about, userid)
    try:
        conn.connect()
        cursor = conn.cursor()
        cursor.execute(query, data)
        conn.commit()
        data = cursor.lastrowid
        cursor.close()
        conn.close()
        return [True, data]
    except:
        return [False, 0]
Пример #5
0
def registerUser(username, password, email):
    hash = generate_password_hash(password)
    sql = "INSERT INTO users (username,hash,email) VALUES ('{0}','{1}','{2}')".format(
        username, hash, email)
    try:
        conn.connect()
        cursor = conn.cursor()
        cursor.execute(sql)
        conn.commit()
        data = cursor.lastrowid
        cursor.close()
        conn.close()
        return [True, data]
    except:
        return [False, 0]
Пример #6
0
def loginUser(username, password):
    sql = "SELECT * FROM users WHERE username = '******'".format(username)
    try:
        conn.connect()
        cursor = conn.cursor()
        cursor.execute(sql)
        data = cursor.fetchall()[0]
        cursor.close()
        conn.close()
        if username == data[1] and check_password_hash(data[2], password):
            return [True, data[0]]
        else:
            return [False, 0]
    except:
        return [False, 0]
Пример #7
0
def updateAdmin(info):
    sql = "UPDATE admin SET username='******' where adminid='{0}'".format(
        info[0], info[1])
    try:
        conn.connect()
        cursor = conn.cursor()
        cursor.execute(sql)
        conn.commit()
        data = cursor.rowcount
        cursor.close()
        conn.close()
        print(data)
        return data
    except:
        return False
Пример #8
0
def updateUser(info):
    sql = "UPDATE users SET username='******', email='{2}', about='{3}' where userid='{0}'".format(
        info[0], info[1], info[2], info[3])
    try:
        conn.connect()
        cursor = conn.cursor()
        cursor.execute(sql)
        conn.commit()
        data = cursor.rowcount
        cursor.close()
        conn.close()
        print(data)
        return data
    except:
        return False
Пример #9
0
def addProduct(info):
    sql = "INSERT INTO products (name,price,description,category) VALUES ('{0}',{1},'{2}','{3}')".format(
        info[0], info[1], info[2], info[3])
    try:
        conn.connect()
        cursor = conn.cursor()
        cursor.execute(sql)
        conn.commit()
        data = cursor.rowcount
        cursor.close()
        conn.close()
        print(data)
        return data
    except:
        return False
Пример #10
0
def getProfile(userid):
    sql = "SELECT username, email, about FROM users WHERE userid = '{}'".format(
        userid)
    conn.connect()
    cursor = conn.cursor()
    cursor.execute(sql)
    data = cursor.fetchall()
    for row in data:
        username = row[0]
        email = row[1]
        about = row[2]
    cursor.close()
    conn.close()
    print(username, email, about)
    return username, email, about
Пример #11
0
def registerAdmin(username, password):
    hash = generate_password_hash(password)
    sql = "INSERT INTO admin (username,hash) VALUES ('{0}','{1}')".format(
        username, hash)
    try:
        conn.connect()
        cursor = conn.cursor()
        cursor.execute(sql)
        conn.commit()
        data = cursor.lastrowid
        cursor.close()
        conn.close()
        print(data)
        return [True, data]
    except:
        return [False, 0]
from app import conn

conn.close()