コード例 #1
0
def currentBio(username):
    fpdatabase = connection.fpdatabase()
    my_cursor = fpdatabase.cursor()
    q = "SELECT bio FROM user WHERE userID = %s"
    my_cursor.execute(q, (username, ))
    results = my_cursor.fetchone()
    return results
コード例 #2
0
ファイル: Signup.py プロジェクト: mmill224/capstone-fall2020
def addUser(username, firstname, middlename, lastname, email, password):
    fpdatabase = connection.fpdatabase()
    initalCheck = userExists(
        username
    )  # this is inefficient because it still does the rest of the function if there's already a record with that userID
    admin = 0
    my_cursor = fpdatabase.cursor()
    sqlStuff = "INSERT INTO user (userID,firstName, middleName, lastName, email, password, profilePicture, bio, admin) VALUES (%s,%s,%s,%s,%s,%s,%s,%s,%s)"
    my_cursor.execute(sqlStuff, (
        username,
        firstname,
        middlename,
        lastname,
        email,
        passHash(password),
        False,
        "",
        admin,
    ))
    fpdatabase.commit()
    my_cursor.close()
    afterCheck = userExists(username)
    if initalCheck == False and afterCheck == True:
        return True
    else:
        return False
コード例 #3
0
def getUserInfo(username):
    fpdatabase = connection.fpdatabase()
    my_cursor = fpdatabase.cursor()
    sql = "SELECT firstName, lastName, profilePicture FROM user WHERE userID = %s"
    my_cursor.execute(sql, (username, ))
    results = my_cursor.fetchone()
    my_cursor.close()
    return results
コード例 #4
0
def adminCheck(username):
    fpdatabase = connection.fpdatabase()
    my_cursor = fpdatabase.cursor()
    q = "SELECT admin FROM user WHERE userID = %s"
    my_cursor.execute(q, (username, ))
    results = my_cursor.fetchone()
    print(results)
    return results
コード例 #5
0
ファイル: test.py プロジェクト: mmill224/capstone-fall2020
def cleanUp(testData):
    fpdatabase = connection.fpdatabase()
    my_cursor = fpdatabase.cursor()
    sql = "DELETE FROM user WHERE userID = %s"
    user = (testData["username"],)
    my_cursor.execute(sql, user)
    fpdatabase.commit()
    my_cursor.close()
コード例 #6
0
def changeProfilePic(username, newPick):
    fpdatabase = connection.fpdatabase()
    my_cursor = fpdatabase.cursor()
    update = "UPDATE user SET profilePicture = %s WHERE userID = %s"
    my_cursor.execute(update, (
        newPick,
        username,
    ))
    fpdatabase.commit()
コード例 #7
0
def userExists(username):
    fpdatabase = connection.fpdatabase()
    my_cursor = fpdatabase.cursor()
    sql = "SELECT * FROM user WHERE userID= %s"
    my_cursor.execute(sql, (username, ))
    results = my_cursor.fetchone()
    if results != None:
        return True
    else:
        return False
コード例 #8
0
def deleteSelfPost(postID, username):
    fpdatabase = connection.fpdatabase()
    my_cursor = fpdatabase.cursor()
    sql = "DELETE FROM post WHERE postID = %s AND postUser = %s"
    my_cursor.execute(sql, (
        postID,
        username,
    ))
    fpdatabase.commit()
    my_cursor.close()
コード例 #9
0
def deletePost(admin):
    fpdatabase = connection.fpdatabase()
    my_cursor = fpdatabase.cursor()
    if admin == (1, ):
        sql = "DELETE FROM post WHERE postID = %s"
        post = (input("Enter postId you wish to delete: "), )
        my_cursor.execute(sql, post)
        fpdatabase.commit()
        print("post deleted")
        my_cursor.close()
コード例 #10
0
def deleteUser(admin):
    fpdatabase = connection.fpdatabase()
    my_cursor = fpdatabase.cursor()
    if admin == (1, ):
        sql = "DELETE FROM user WHERE userID = %s"
        user = (input("Enter userId you wish to delete: "), )
        my_cursor.execute(sql, user)
        fpdatabase.commit()
        print("User deleted")
        my_cursor.close()
コード例 #11
0
def createPost(image, description, username, imageName):
    fpdatabase = connection.fpdatabase()
    my_cursor = fpdatabase.cursor()
    post = "INSERT INTO post (image, description, postUser, imageName) VALUES (%s,%s,%s, %s)"
    my_cursor.execute(post, (
        image,
        description,
        username,
        imageName,
    ))
    fpdatabase.commit()
    my_cursor.close()
コード例 #12
0
def passwordCheck(username, password):
    fpdatabase = connection.fpdatabase()
    my_cursor = fpdatabase.cursor()
    sql = "SELECT password FROM user WHERE userID = %s"
    my_cursor.execute(sql, (username, ))
    results = my_cursor.fetchone()
    if (bcrypt.verify(password, results[0])) == True:
        print("login sucsess")
        return True
    else:
        print("login failed")
        return False
コード例 #13
0
def viewPosts(username=""):
    fpdatabase = connection.fpdatabase()
    my_cursor = fpdatabase.cursor()
    if username == "":  # this is the case that we want all posts from all users, and in that case we just want first, last, profile pic
        my_cursor.execute(
            "SELECT postID, image, description, firstName, lastName, profilePicture, imageName from post JOIN user on userID = postUser order by createdAt desc"
        )  # this needs to be a join "Select "
        results = my_cursor.fetchall()
        return results
    else:  # this is the case where we want JUST the posts from this one user, and we want that joined with first, last, profile pic, and bio ( this is inefficient unfortunately )
        q = "SELECT postID, image, description, firstName, lastName, profilePicture, imageName, bio from post right join user ON userID = %s WHERE userID = postUser order by createdAt desc"  # this needs to only get the posts from username (the parameter)
        my_cursor.execute(q, (username, ))
        results = my_cursor.fetchall()
        return results
コード例 #14
0
def createEvent(username):
    fpdatabase = connection.fpdatabase()
    eventName = input("Please enter a event name")
    description = input("Please enter a description: ")
    date = input("Please enter a date: ")
    location = input("Please enter a location: ")
    my_cursor = fpdatabase.cursor()
    post = "INSERT INTO event (eventName,description, location, eventUser) VALUES (%s,%s,%s,%s)"
    my_cursor.execute(post, (
        eventName,
        description,
        location,
        username,
    ))
    fpdatabase.commit()
    my_cursor.close()
コード例 #15
0
def updateBio(username, newBio):
    fpdatabase = connection.fpdatabase()
    bio = currentBio(username)
    my_cursor = fpdatabase.cursor()
    update = "UPDATE user SET bio = %s WHERE userID = %s"
    my_cursor.execute(update, (
        newBio,
        username,
    ))
    fpdatabase.commit()
    bio3 = currentBio(username)
    if bio == bio3:
        print("not changed")
        return False
    else:
        print("bio changed")
        return True
コード例 #16
0
def getMostRecentPostId():
    fpdatabase = connection.fpdatabase()
    my_cursor = fpdatabase.cursor()
    my_cursor.execute("SELECT postID from post order by createdAt desc")
    result = my_cursor.fetchone()
    return result
コード例 #17
0
def viewEvents():
    fpdatabase = connection.fpdatabase()
    my_cursor = fpdatabase.cursor()
    my_cursor.execute("SELECT * FROM event")
    results = my_cursor.fetchall()
    return results