Esempio n. 1
0
def verify_account(uname, psw):
    """
    Checks if the account entered is the current account that is being used and calls a function for
    searching for the account that was entered in the database
    """
    errors = 0  # keeps track of all the errors that have been found
    val_uname = get_cookie()  # gets the username the user logged in with

    if val_uname != uname:
        errors += 1
        errmsgs.append("        <p>Your username was not entered</p>")
    else:
        errors += select_account(uname, psw)

    return errors
Esempio n. 2
0
def find_accid():
    """
    Finds the id of an account for the Votes table
    """
    accid = 0

    uname = get_cookie()

    # Prepare SELECT statement
    prep_select = "SELECT accId FROM accounts WHERE uname = %s"

    cursor.execute(prep_select, (uname,))
    result = cursor.fetchall()  # returns a list of tuples

    if result:
        (val_id,) = result[0]  # unpacks the tuple
        accid = int(val_id)

    return accid
Esempio n. 3
0
def find_accid():
    """
    Finds the ID of an account for the Salt table
    """
    # The "uname" cookie is used so the original "username" is always used
    uname = get_cookie()
    accid = 0

    # Prepare SELECT statement
    prep_select = "SELECT accId FROM accounts WHERE uname = %s"

    # A tuple should always be used to bind placeholders
    cursor.execute(prep_select, (uname, ))
    result = cursor.fetchall()  # returns a list of tuples

    if result:
        # Should only return one row
        (val_accid, ) = result[0]  # unpacks the tuple
        accid = val_accid

    return accid
Esempio n. 4
0
def find_account():
    """
    Searches for a user by using the uname cookie
    """
    uname = get_cookie()  # gets the username of the user

    # Prepare SELECT statements
    prep_select = "SELECT uname, fname, lname, age, addr, city, state, zipCode, poliAffil FROM accounts WHERE uname = %s"

    # A tuple should always be used when binding placeholders (%s)
    cursor.execute(
        prep_select,
        (uname, )  # you use (value,) when searching for a single value
    )

    result = cursor.fetchall()  # returns a list of tuples

    if result:
        return result[0]
    else:
        return ("", "", "", "", "", "", "", "", "")
Esempio n. 5
0
def find_encdata():
    """
    Searches the Accounts table for the user's encrypted password and email address
    """
    # The "uname" cookie is used in order to ensure that the original username is always used
    uname_cookie = get_cookie()  # gets the value of the "uname" cookie

    # Prepare SELECT statement
    prep_select = "SELECT pwd, email FROM accounts WHERE uname = %s"

    # A tuple should always be used when binding placeholders (%s)
    cursor.execute(
        prep_select,
        (uname_cookie, ),  # you use (value,) when searching for a single value
    )

    result = cursor.fetchall()  # returns a list of tuples

    if result:
        return result[0]
    else:
        return ("", "")
Esempio n. 6
0
def delete_account():
    """
    Deletes the current account that is being used
    """
    global err, errmsg
    uname = get_cookie()  # gets the current username that is being used

    try:
        # Prepared DELETE statement
        prep_delete = "DELETE FROM accounts WHERE uname = %s"

        # A tuple should always be used for binding placeholders (%s)
        cursor.execute(
            prep_delete,
            (uname, )  # you use (value,) when searching for a single value
        )

        delete_salt()

        db.commit()  # saves changes
    except mysql.Error as e:
        errmsg = "        <p>" + str(e) + "</p>"
        err = True
Esempio n. 7
0
def check_donations():
    """
    Checks if the user donated to any candidates
    """
    # The "uname" cookie is used in order to ensure that the original username is always used
    uname_cookie = get_cookie()  # gets the value of the "uname" cookie

    # Prepare SELECT statement
    prep_select = (
        "SELECT credCardNum, cvv FROM donations NATURAL JOIN accounts WHERE uname = %s"
    )

    # A tuple should always be used when binding placeholders (%s)
    cursor.execute(
        prep_select,
        (uname_cookie, ),  # you use (value,) when searching for a single value
    )

    result = cursor.fetchall()  # returns a list of tuples

    if result:
        return True
    else:
        return False
Esempio n. 8
0
if "psw1" in form or "psw2" in form:
    if "psw1" in form:
        psw1 = form.getvalue("psw1")

    if "psw2" in form:
        psw2 = form.getvalue("psw2")

    errctr += valid_account(uname, psw1, psw2)
else:
    errctr += valid_username(uname)

# Determines if select_account() should be called
if errctr == 0:
    # Checks if the account that was entered already exists
    errctr += select_account()
    uname_cookie = get_cookie()  # gets the original username that was used

    # Sets the "uname" cookie to a new value if a new username was submitted
    if uname_cookie != uname:
        uname_cookie = c.SimpleCookie()  # resets the cookie
        uname_cookie["uname"] = uname
        print(uname_cookie)  # prints Set-Cookie: uname=value

print("Content-Type: text/html\n")

# HTML code that is always printed
print("<!DOCTYPE html>")
print('<html lang="en">')
print("  <head>")
print("    <title>Update Account</title>")
print('    <link rel="stylesheet" href="css/main-styles.css" />')