Exemple #1
0
def get_latest_users():
    conn, db = connection()

    query = db.execute('SELECT * FROM users ORDER BY id DESC LIMIT 3')

    data = db.fetchall()

    return query, data
Exemple #2
0
def show_users():
    conn, db = connection()

    query = db.execute('SELECT * FROM users ')

    data = db.fetchall()

    return query, data
Exemple #3
0
def show_unapproved_articale():
    conn, db = connection()

    query = db.execute(
        'SELECT * FROM articale WHERE approve=0 ORDER BY id DESC')

    data = db.fetchall()

    return query, data
Exemple #4
0
def approve(id):
    c_id = clean(id)
    conn, db = connection()

    query = db.execute('UPDATE articale SET approve=1 WHERE id = %s', [c_id])

    conn.commit()

    db.close
Exemple #5
0
def admin_delete(id):
    c_id = clean(id)
    conn, db = connection()

    query = db.execute('DELETE FROM articale WHERE id = %s ', [c_id])

    conn.commit()

    db.close
Exemple #6
0
def delete_user(id):
    c_id = clean(id)
    conn, db = connection()

    query = db.execute('DELETE FROM users WHERE id = %s', (c_id))

    conn.commit()

    db.close
Exemple #7
0
def get_by_id(id):
    c_id = clean(id)
    conn, db = connection()

    query = db.execute('SELECT * FROM articale WHERE id=%s', [c_id])

    data = db.fetchone()

    return query, data
Exemple #8
0
def get_latest_articale():
    conn, db = connection()

    query = db.execute(
        'SELECT * FROM articale WHERE approve=0 ORDER BY id DESC LIMIT 3')

    data = db.fetchall()

    return query, data
Exemple #9
0
def delete(id, username):
    c_id = clean(id)
    c_username = clean(username)
    conn, db = connection()

    query = db.execute('DELETE FROM articale WHERE id = %s AND author = %s',
                       (c_id, c_username))

    conn.commit()

    db.close
Exemple #10
0
def Add_Articale(title, user, content):
    c_title = clean(title)
    c_content = clean(content)

    conn, db = connection()

    query = db.execute(
        'INSERT INTO articale (title,author,content,approve) VALUES (%s,%s,%s,0)',
        (c_title, user, c_content))

    conn.commit()

    db.close()
Exemple #11
0
def update(id, title, content):
    c_id = clean(id)
    c_title = clean(title)
    c_content = clean(content)
    conn, db = connection()

    query = db.execute(
        'UPDATE articale SET title=%s, content = %s WHERE id = %s',
        (c_title, c_content, c_id))

    conn.commit()

    db.close
Exemple #12
0
def check_user(username):
    c_username = clean(username)
    # create connection
    conn, db = connection()

    # execute query

    query = db.execute('SELECT * FROM users WHERE username = %s', [c_username])

    #fetch data

    data = db.fetchone()

    return query, data
Exemple #13
0
def add_user(name, username, email, password):
    # get data & clean it

    c_name = clean(name)
    c_username = clean(username)
    c_email = clean(email)
    c_password = sha256_crypt.encrypt(clean(password))

    # create connection

    conn, db = connection()

    # execute query

    query = db.execute(
        "INSERT INTO users (name,username,email,password,admin) VALUES (%s,%s,%s,%s,0)",
        (c_name, c_username, c_email, c_password))
    # save change
    conn.commit()
    # close connection
    db.close()
Exemple #14
0
def update_user(name, username, email, id):
    # get data & clean it

    c_name = clean(name)
    c_username = clean(username)
    c_email = clean(email)
    c_id = clean(id)

    # create connection

    conn, db = connection()

    # execute query

    query = db.execute(
        "UPDATE users SET name=%s,username=%s,email=%s WHERE id = %s",
        (c_name, c_username, c_email, c_id))
    # save change
    conn.commit()
    # close connection
    db.close()