def creator_profile(creator): creator = creator profil = fetchall( "select profile.info, profile.level, profile.age, profile.location FROM((Match join registration on Match.creator = registration.username)join profile on registration.pid = profile.pid) WHERE creator = %s", [creator]) img = fetchall( "select profile.img FROM((Match join registration on Match.creator = registration.username)join profile on registration.pid = profile.pid) WHERE creator = %s", [creator]) print(profil) print(img) return render_template("creator_profile.html", creator=creator, profil=profil, img=img)
def start_page(): print(session.get("username")) print(session.get("logged_in")) if not session.get("logged_in"): print("No username found in session") return log_in() else: print("Success") img = fetchone( "select img from(profile join registration on profile.pid = registration.pid) where username = %s", [session["username"]]) profileInfo = [] profileInfo = fetchall( "select * from(profile join registration on profile.pid = registration.pid) where username = %s", [session["username"]]) personName = fetchone( "select name from(person join registration on person.pid = registration.pid) where username = %s", [session["username"]]) session["logged_in"] = True return render_template("welcome.html", picture=img, user=session["username"], profileInfo=profileInfo, personName=personName)
def show_Game(ort, klass, antal): print(ort, klass, antal) # check if creator name is username session, then don't show. sql = "select ort, klass, antal, match.matchid, booked from(match join booking on match.matchid = booking.matchid) where ort = %s AND klass = %s AND antal = %s AND antal > 0;" val = ort, klass, antal games = fetchall(sql, val) return games
def user_log(): if user_login.log_in() == True: username = request.form["userName"] img = fetchone( "select img from(profile join registration on profile.pid = registration.pid) where username = %s", [username]) profileInfo = [] profileInfo = fetchall( "select * from(profile join registration on profile.pid = registration.pid) where username = %s", [username]) personName = fetchone( "select name from(person join registration on person.pid = registration.pid) where username = %s", [username]) session["username"] = username session["logged_in"] = True return render_template("welcome.html", picture=img, user=session["username"], profileInfo=profileInfo, personName=personName) elif user_login.log_in() == False: flash("Fel lösenord eller användarnamn") return render_template("log_in.html", username="")
def show_my_games(): show_match.check_date() game = fetchall( "select location, level, players, creator, match.matchid, date, gender from (match join booking on match.matchid = booking.matchid) where booking.username = %s ORDER BY date;", [session["username"]]) return render_template("my_games.html", user=session["username"], matches=game)
def changeProfile(): informationProfile = fetchall( "select * from (profile join registration on profile.pid = registration.pid) where username = %s", [session["username"]]) print(informationProfile) return render_template("edit_profile.html", user=session["username"], info=informationProfile)
def show_past_chatt(): messages = [] sql = "select writer,message,date from msg WHERE writer = %s OR reciever = %s" val = session["username"], session["username"] insert(sql, val) messages = fetchall(sql, val) return render_template("messages.html", user=session["username"], messages=messages)
def show_Match_Profile(matchid): result = fetchall( "select location, level, players, info, creator, matchid, gender from match where matchid = %s AND players > 0", [matchid]) match = [] for record in result: match.append(record) return match
def show_all_ranks(location, level): check_date() sql = "select DISTINCT location,level,players,match.matchid,gender,date,username from (match join booking on match.matchid = booking.matchid) where location = %s and level = %s AND players > 0 AND creator != %s ORDER BY date" val = (location, level, session["username"]) result = fetchall(sql, val) games = [] for record in result: games.append(record) return games
def show_my_games(): print(session["username"]) game = fetchall( "select ort, klass, antal, skapare, match.matchid from (match join booking on match.matchid = booking.matchid) where booking.username = %s", [session["username"]]) print(game) return render_template("my_games.html", user=session["username"], matches=game)
def show_all_match(ort): sql = "select ort, klass, antal, matchid from match where ort = %s AND antal > 0" val = (ort, ) result = fetchall(sql, val) games = [] for record in result: games.append(record) print(games) return games
def show_match_profile(matchid): matchid = matchid result = fetchall( "select location, level, info, creator, matchid, players from match where matchid = %s", [matchid]) my_matches = [] for record in result: my_matches.append(record) return render_template("match_profile.html", match=show_match.show_Match_Profile(matchid), my_matches=my_matches)
def show_comment(matchid): print("hej") matchid = matchid result = fetchall( "select message, writer, matchid from msg where matchid = %s ORDER BY date DESC", [matchid]) print(result) comments = [] for record in result: print(record) comments.append(record) print(comments) return comments
def register(): """ Receives User registration information from a form and creates Person,Profile % registartion in the database. """ fName = request.form["fName"] lName = request.form["lName"] email = request.form["email"] gender = request.form["gender"] username = request.form["userName"] password = request.form["pwd"] password = hash_password(password) level = request.form["level"] location = request.form["location"] username_list = fetchall("select username from registration", "") username_list = ("".join(str(username_list))) if username not in username_list: def insert_person(): sql = "insert into person(name, email, gender) values(%s,%s,%s)" name = fName + " " + lName val = ( name, email, gender, ) insert(sql, val) def insert_registration(): sql = "insert into registration(username, password) values(%s,%s)" val = ( username, password, ) insert(sql, val) def insert_profile(): sql = "insert into profile(img, level, location) values(%s, %s, %s)" image = 'static/img/uploads/blank_profile.png' val = (image, level, location) insert(sql, val) insert_person() insert_profile() insert_registration() return True else: return False
def check_date(): """ Converts database "date" to same format as date.today() and compares if the date is expired. If date expired = remove match from database. """ current = date.today() current = current.strftime("%a, %d %b %Y") current = datetime.strptime(str(current), "%a, %d %b %Y") result = fetchall("select date from match where matchid > %s", [0]) print(current) for record in result: record = datetime.strptime(record[0], "%a, %d %b %Y") if record < current: print("delete") new_record = record.strftime("%a, %d %b %Y") print(new_record) update("delete from match where date = %s", [new_record])
def my_game_info(matchid): matchid = matchid result = fetchall( "select ort, klass, info, skapare, matchid, antal from match where matchid = %s", [matchid]) my_matches = [] for record in result: my_matches.append(record) #Checks if skapare = username if my_matches[0][3] == session["username"]: return render_template("show_my_games.html", user=session["username"], my_matches=my_matches, creator=True) else: return render_template("show_my_games.html", user=session["username"], my_matches=my_matches)
def profil(): profile.editProfile(session["username"]) img = fetchone( "select img from(profile join registration on profile.pid = registration.pid) where username = %s", [session["username"]]) profileInfo = [] profileInfo = fetchall( "select * from(profile join registration on profile.pid = registration.pid) where username = %s", [session["username"]]) personName = fetchone( "select name from(person join registration on person.pid = registration.pid) where username = %s", [session["username"]]) return render_template("welcome.html", picture=img, user=session["username"], profileInfo=profileInfo, personName=personName)
def my_game_info(matchid): matchid = matchid result = fetchall( "select location, level, info, creator, matchid, players from match where matchid = %s", [matchid]) my_matches = [] for record in result: my_matches.append(record) #Checks if creator = username if my_matches[0][3] == session["username"]: return render_template("show_my_games.html", user=session["username"], my_matches=my_matches, creator=True, comments=show_comment(matchid)) else: return render_template("show_my_games.html", user=session["username"], my_matches=my_matches, comments=show_comment(matchid))
def log_in(): cred = [] cred = fetchall("select username from registration", "") usernameList = ("".join(str(cred))) username = request.form["userName"] password = request.form["pwd"] if username in usernameList: usernameToFind = (username, ) cred = fetchone("select password from registration where username=%s", usernameToFind) stored_password = cred[0] print(stored_password) print(password) if verify_password(stored_password, password): print("Password is correct") return True else: print(stored_password) print(password) print("fel lösenord") return False else: return False
def show_Game(location, level, gender): check_date() sql = "select DISTINCT location,level,players,match.matchid,gender,date,username from (match join booking on match.matchid = booking.matchid) where location = %s AND level = %s AND gender = %s AND players > 0 AND creator != %s ORDER BY date" val = location, level, gender, session["username"] games = fetchall(sql, val) return games