def getCookieUser(cookie): db.create_all() cookieUser = db.engine.execute( "SELECT cookieUser FROM cookies WHERE cookieValue = '" + cookie + "'").fetchone() if cookieUser[0]: return cookieUser[0] return False
def checkAuth(user, cookie): db.create_all() cookieUser = db.engine.execute( "SELECT cookieUser FROM cookies WHERE cookieValue = '" + cookie + "'").fetchone() if user == cookieUser[0]: return return False
def checkCookie(cookie): db.create_all() cookieExists = db.engine.execute( "SELECT * FROM cookies WHERE cookieValue = '" + cookie + "'").fetchone() if cookieExists: return True return False
def getUserMemes(username): db.create_all() uid = db.engine.execute("SELECT uid FROM user WHERE username = '******'").fetchone() if not uid: return False memeList = db.engine.execute("SELECT * FROM meme WHERE uploaded_by = '" + str(uid[0]) + "'").fetchall() return memeList
def setCookie(cookie, userName): db.create_all() db.engine.execute( "INSERT INTO cookies (cookieValue, cookieUser) VALUES ('" + cookie + "', '" + userName + "')") try: db.session.commit() except: db.session.rollback()
def createUser(username, password, email): db.create_all() db.engine.execute( "INSERT INTO user (username, email, password, role) VALUES ('" + username + "', '" + email + "', '" + password + "', 'user')") try: db.session.commit() except: db.session.rollback()
def checkPw(email, password): db.create_all() userpw = db.engine.execute("SELECT password FROM user WHERE email = '" + email + "'").fetchone() username = db.engine.execute("SELECT username FROM user WHERE email = '" + email + "'").fetchone() if not userpw: return False, None if password == userpw[0]: return True, username return False, None
def checkUserAndEmail(username, email): db.create_all() userExist = db.engine.execute("SELECT * FROM user WHERE username = '******'").fetchone() emailExist = db.engine.execute("SELECT * FROM user WHERE email = '" + email + "'").fetchone() #check if they exist, if not then make them. if not userExist and not emailExist: return True else: return False
def insertMeme(user, memeName, filename): db.create_all() userID = db.engine.execute("SELECT uid FROM user WHERE username = '******'").fetchone() db.engine.execute( "INSERT INTO meme (meme_name, meme_path, uploaded_by, likes) VALUES ('" + memeName + "', '" + filename + "', " + str(userID[0]) + ", 0)") try: db.session.commit() return except: db.session.rollback() return
def setup(): db.create_all() #db.engine.execute("INSERT INTO user (username, email, password, role) VALUES ('asd', '*****@*****.**', 'asd', 'admin')") db.engine.execute( "INSERT INTO meme (meme_name, meme_path, uploaded_by, likes) VALUES ('Cookie Monster', 'cookiemonster.jpg', 1, 0)" ) db.engine.execute( "INSERT INTO meme (meme_name, meme_path, uploaded_by, likes) VALUES ('Freezes', 'freezes.jpg', 1, 0)" ) db.engine.execute( "INSERT INTO meme (meme_name, meme_path, uploaded_by, likes) VALUES ('Stealing Dataz', 'stealingdataz.jpeg', 1, 0)" ) db.engine.execute( "INSERT INTO meme (meme_name, meme_path, uploaded_by, likes) VALUES ('You can do it!', 'youcandoit.jpg', 1, 0)" ) db.engine.execute( "INSERT INTO meme (meme_name, meme_path, uploaded_by, likes) VALUES ('Not sure...', 'notsure.jpg', 2, 0)" ) db.engine.execute( "INSERT INTO meme (meme_name, meme_path, uploaded_by, likes) VALUES ('Web Devs', 'webdevs.jpg', 2, 0)" ) db.engine.execute("INSERT INTO tags (tagName) VALUES ('Funny')") db.engine.execute("INSERT INTO tags (tagName) VALUES ('Cool')") db.engine.execute("INSERT INTO tags (tagName) VALUES ('Another')") db.engine.execute("INSERT INTO tag_join (tagID, mid) VALUES (1, 1)") db.engine.execute("INSERT INTO tag_join (tagID, mid) VALUES (2, 1)") db.engine.execute("INSERT INTO tag_join (tagID, mid) VALUES (1, 2)") try: db.session.commit() return except: db.session.rollback()
def checkCookieTimeout(cookie): db.create_all() lastAction = db.engine.execute( "SELECT lastAction FROM cookies WHERE cookieValue = '" + cookie + "'").fetchone() currentTime = time.time() timeSinceLastAction = currentTime - int(lastAction[0]) if timeSinceLastAction < 600: db.engine.execute("UPDATE cookies set lastAction = '" + str(int(currentTime)) + "' WHERE cookieValue = '" + cookie + "'") try: db.session.commit() except: db.session.rollback() return True db.engine.execute("DELETE FROM cookies WHERE cookieValue = '" + cookie + "'") try: db.session.commit() except: db.session.rollback() return False
def getAllMemes(): db.create_all() allList = db.engine.execute("SELECT * FROM meme").fetchall() return allList