예제 #1
0
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)
예제 #2
0
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="")
예제 #3
0
def validatepicture(username):

    if request.method == "POST":
        print("1 validate")
        print(request.files)
        if request.files:
            print("2 validate")
            image = request.files["image"]
            print(image)
            if image.filename == "":
                asd = fetchone(
                    "select pid from registration where username = %s",
                    [username])
                oldpic = fetchone("select img from profile where pid = %s",
                                  [asd])
                return oldpic

            if not allowed_image(image.filename):

                print(image.filename)
                print("That image extension is not allowed")
                return redirect(request.url)

            else:
                filename = secure_filename(image.filename)

            print(image)
            image.save(os.path.join(UPLOAD_FOLDER, image.filename))

            return "static/img/uploads/" + str(image.filename)
예제 #4
0
def booking_game(matchid):
    matchid = int(matchid)
    players = request.form["players"]
    print(players)
    if players == "0":
        flash("Var vänlig och boka en plats")
        print("players = 0" + players)
        return render_template("match_profile.html",
                               match=show_match.show_Match_Profile(matchid))

    else:
        print("antal högre än 0:" + players)
        booked = fetchone("select booked from match where matchid = %s",
                          [matchid])

        def new_booked():
            print(players)
            if (int(players) + booked[0]) > 4:
                return "4"
            else:
                return int(players) + booked[0]

            print(matchid, session["username"])

        creatorName = fetchone("select creator from match where matchid = %s",
                               [matchid])
        sql = "insert into booking values(%s,%s,%s,%s)"
        val = matchid, session["username"], creatorName, players
        insert(sql, val)

        sql = "UPDATE match SET booked = %s WHERE matchid = %s;"
        val = new_booked(), matchid
        update(sql, val)

        sql = "UPDATE match SET players = %s WHERE matchid = %s;"
        searching = fetchone("select players from match where matchid = %s",
                             [matchid])
        print(searching[0])
        searching = searching[0] - int(players)
        val = searching, matchid
        update(sql, val)

        return start_page()

    sql = "UPDATE match SET players = %s WHERE matchid = %s;"
    searching = fetchone("select players from match where matchid = %s",
                         [matchid])
    print(searching[0])
    searching = searching[0] - int(players)
    val = searching, matchid
    update(sql, val)

    return start_page()
예제 #5
0
def editProfile(username):

    asd = fetchone("select pid from registration where username = %s",
                   [username])
    oldpic = fetchone("select img from profile where pid = %s", [asd])

    img = validatepicture(username)
    info = request.form["info"]
    level = request.form["level"]
    age = request.form["age"]

    if img == oldpic and age == "" and info == "":
        print("ifsats 1")
        sql = "update profile set level = %s where pid = %s"
        val = (level, asd)
        update(sql, val)

    elif img == oldpic and age == "":
        print("ifsats 2")
        sql = "update profile set level = %s, info = %s where pid = %s"
        val = (level, info, asd)
        update(sql, val)

    elif img == oldpic:
        print("ifsats 3")
        sql = "update profile set level = %s, info = %s, age = %s where pid = %s"
        val = (level, info, age, asd)
        update(sql, val)

    elif img != oldpic and age == "" and info == "":
        print("ifsats 4")
        sql = "update profile set level = %s, img = %s where pid =%s"
        val = (level, img, asd)
        update(sql, val)

    elif img != oldpic and age == "":
        print("ifsats 5")
        sql = "update profile set level = %s, img = %s, info = %s where pid = %s"
        val = (level, img, info, asd)
        update(sql, val)

    else:
        print("ifsats 6")
        sql = "update profile set level = %s, img = %s, info = %s, age = %s where pid =%s"
        val = (level, img, info, age, asd)
        update(sql, val)

    for item in oldpic:
        if os.path.exists(str(item)):
            os.remove(str(item.rsplit('/')[3]))
            print("bild borttagen")
예제 #6
0
def editProfile(username):
    img = request.form["img"]
    info = request.form["info"]
    level = request.form["level"]
    age = request.form["age"]
    asd = fetchone("select pid from registration where username = %s",
                   [username])
    sql = "update profile set img = %s, info = %s, level = %s, age = %s where pid = %s"
    val = (img, info, level, age, asd)
    update(sql, val)
예제 #7
0
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)
예제 #8
0
def changeProfile():
    informationProfile = fetchall(
        "select * from (profile join registration on profile.pid = registration.pid) where username = %s",
        [session["username"]])
    img = fetchone(
        "select img from(profile join registration on profile.pid = registration.pid) where username = %s",
        [session["username"]])
    return render_template("edit_profile.html",
                           user=session["username"],
                           info=informationProfile,
                           pics=img)
예제 #9
0
def show_chatt(matchid):
    matchid = int(matchid)
    print(matchid)
    antal = request.form["antal"]
    booked = fetchone("select booked from match where matchid = %s", [matchid])
    print(booked[0])
    new_booked = int(antal) + booked[0]
    print(matchid, session["username"])

    creatorName = fetchone("select skapare from match where matchid = %s",
                           [matchid])
    sql = "insert into booking values(%s,%s,%s)"
    val = matchid, session["username"], creatorName
    insert(sql, val)

    sql = "UPDATE match SET booked = %s WHERE matchid = %s;"
    val = new_booked, matchid
    print(matchid, session["username"])
    update(sql, val)

    sql = "UPDATE match SET antal = %s WHERE matchid = %s;"
    sökes = fetchone("select antal from match where matchid = %s", [matchid])
    print(sökes[0])
    sökes = sökes[0] - int(antal)
    val = sökes, matchid
    update(sql, val)

    # Future chatt fnction
    # def sessions():
    #     return render_template('session.html')

    # def messageReceived(methods=['GET', 'POST']):
    #     print('message was received!!!')

    # @socketio.on('my event')
    # def handle_my_custom_event(json, methods=['GET', 'POST']):
    #     print('received my event: ' + str(json))
    #     socketio.emit('my response', json, callback=messageReceived)
    # return render_template('session.html')

    return start_page()
예제 #10
0
def insert_match():

    players = request.form["players"]

    show_match.create_Game(session["username"])
    matchid = fetchone("select max(matchid) from match where matchid > %s",
                       "0")
    if matchid[0] == None:
        matchid = 1
    sql = "insert into booking (matchid,username,creatorname,booked) values (%s,%s,%s,%s)"
    val = matchid, session["username"], session["username"], players
    insert(sql, val)

    return start_page()
예제 #11
0
def remove_booking(matchid):
    sql = "select booked from booking where matchid=%s AND username=%s"
    val = matchid, session["username"]
    current_booking = fetchone(sql, val)

    sql = "update match set players=(players+%s) where matchid =%s"
    val = current_booking, matchid
    update(sql, val)
    sql = "update match set booked=(booked-%s) where matchid =%s"
    val = current_booking, matchid
    update(sql, val)

    sql = "delete from booking where matchid=%s AND username=%s"
    val = matchid, session["username"]
    update(sql, val)
    return show_my_games()
예제 #12
0
def change_password(password, new_password):

    cred = fetchone("select password from registration where username=%s",
                    [session["username"]])
    stored_password = cred[0]
    user_login.verify_password(stored_password, password)

    if user_login.verify_password(stored_password, password) == True:
        new_password = user_registration.hash_password(new_password)
        sql = "update registration set password = %s WHERE username = %s"
        val = new_password, session["username"]
        update(sql, val)
        print("update")
        return True

    else:
        flash("Fel lösenord")
        return False
예제 #13
0
def insert_match():

    ort = request.form["ort"]
    klass = request.form["klass"]
    antal = request.form["antal"]

    show_match.create_Game(session["username"])
    matchid = fetchone("select max(matchid) from match where matchid > %s",
                       "0")
    print(matchid)
    if matchid[0] == None:
        matchid = 1
        print(matchid)
    sql = "insert into booking (matchid,username,creatorname) values (%s,%s,%s)"
    val = matchid, session["username"], session["username"]
    insert(sql, val)
    print(matchid, session["username"])

    return render_template("find_match.html",
                           games=show_match.show_Game(ort, klass, antal))
예제 #14
0
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