Ejemplo n.º 1
0
def login():
    # on récupère le json envoyé par le client
    formulaire_login = (request.get_json())

    # on récupère l'email
    email = formulaire_login["email"]

    # on check si l'email existe, si oui on check password
    sql_request = f'''SELECT * FROM players WHERE players_email = "{email}"'''

    players_avec_cette_email = sql_select(sql_request)

    if len(players_avec_cette_email) > 0:
        # on récupère le password
        password = formulaire_login["password"]

        # on check si le password est correcte
        sql_request = f'''SELECT players_id FROM players WHERE players_email = "{email}" AND players_password = "******"'''

        id_players_avec_email_et_password = sql_select(sql_request)

        if len(id_players_avec_email_et_password) > 0:
            print(id_players_avec_email_et_password[0]["players_id"])
            player_id = {"id" : int(id_players_avec_email_et_password[0]["players_id"])}
            return jsonify(player_id)
        else:
            return "Password Incorrect", 403
    else:
        return "Email non existant", 403
Ejemplo n.º 2
0
def index():
    # requête pour récupérer les joueurs
    request_sql = f'''SELECT players_id, players_pseudo 
       FROM players'''

    # on exécute la requete
    data = sql_select(request_sql)

    # on print le résultat de la requête
    print(data)

    # on parcourt le résultat
    for player in data:
        # on récupère l'id du joueur
        player_id = player["players_id"]

        # requête pour récupérer les chats d'un joueur
        request_sql = f'''SELECT * FROM cats 
           JOIN rooms ON rooms.rooms_id = cats.rooms_id 
           WHERE rooms.players_id = {player_id}'''

        cats = sql_select(request_sql)
        print(f'''CHATS DU JOUEUR {player_id} : \n''')
        print(len(cats))

        # on ajoute le nombre de chats (le nombre d'objets dans la liste renvoyée par le serveur) au player actuel
        player["cats_count"] = len(cats)

    # on renvoie le résultat jsonifié
    return jsonify(data), 200



    return "Ok", 200
Ejemplo n.º 3
0
def login():
    formulaire_login = (request.get_json())

    # on récupère l'email
    email = formulaire_login["email"]

    # on check si l'email existe, si oui on envoie une erreur
    sql_request = f'''SELECT * FROM players WHERE players_email = "{email}"'''

    players_avec_cette_email = sql_select(sql_request)

    if len(players_avec_cette_email) > 0:
        password = formulaire_login["password"]
        sql_request = f'''SELECT players_id FROM players WHERE players_email = "{email}" AND players_password = "******"'''
        players_avec_cette_email_et_le_password = sql_select(sql_request)

        if len(players_avec_cette_email_et_le_password) > 0:
            player_id = {
                "id":
                int(players_avec_cette_email_et_le_password[0]["players_id"])
            }
            return jsonify(player_id)
        else:
            return "mdp mauvais"
    else:
        return "email pas bon"
Ejemplo n.º 4
0
def index():
    # On exécute un SELECT pour récupérer tous les players, dans une liste
    data = sql_select('''SELECT players_id, players_pseudo FROM players''')
    print(data)
    all_users = []
    # On parcourt la liste de joueurs renvoyée par la base
    for player_row in data:
        # On récupère les informations du player contenues dans le JSON, pour les stocker dans des variables
        players_id = str(player_row["players_id"])
        players_pseudo = player_row["players_pseudo"]

        # On récupère tous les chats qui sont dans une salle qui appartient au joueur qu'on parcourt
        sql_request = f'''SELECT * 
            FROM cats 
            JOIN rooms 
            ON cats.rooms_id = rooms.rooms_id 
            AND rooms.players_id = {players_id}'''

        cats = sql_select(sql_request)
        print(cats)

        # Le nombre de chats est égal à la taille de la liste
        cats_count = len(cats)

        # On crée un dictionnaire avec les informations attendues par le client
        user_dict = {
            'pseudo': players_pseudo,
            'cats_count': cats_count,
            'id': players_id
        }
        # On l'ajoute à la liste
        all_users.append(user_dict)

    # On retourne notre liste de dictionnaires convertie en JSON
    return jsonify(all_users)
Ejemplo n.º 5
0
def login():
    # on récupère le json envoyé par le client
    formulaire_login = (request.get_json())

    # on récupère l'email
    email = formulaire_login["email"]

    # on check si l'email existe
    sql_request = f'''SELECT * FROM players WHERE players_email = "{email}"'''

    players_avec_cette_email = sql_select(sql_request)

    if len(players_avec_cette_email) == 0:
        return "email non existant dans la base", 401

    #TOUT LE CODE ICI S'EXECUTE SI ON RENTRE PAS DANS LE IF (SI L'EMAIL EXISTE) :

    # on récupère le password
    password = formulaire_login["password"]

    sql_request = f'''SELECT * FROM players 
    WHERE players_email = "{email}"
    AND players_password = "******"'''

    # on check si le mdp existe
    players_avec_ce_password = sql_select(sql_request)

    if len(players_avec_ce_password) == 0:
        return "Mot de passe non existant", 401

    thisdict = {"id": (players_avec_ce_password[0]["players_id"])}
    return jsonify(thisdict), 200
Ejemplo n.º 6
0
def login():
    # on recupere le json envoyé par le client
    formulaire_connexion = (request.get_json())

    # on récupère l'email et le mdp
    email = formulaire_connexion["email"]
    password = formulaire_connexion["password"]

    # on vérifie que l'adresse mail existe
    sql_request = f'''SELECT * FROM players WHERE players_email = "{email}" '''

    players_avec_cet_email = sql_select(sql_request)

    if len(players_avec_cet_email) == 0:
        return "email incorrect", 503

    # on vérifie la correspondance email/mdp
    password = formulaire_connexion["password"]

    sql_request = f'''SELECT * FROM players WHERE players_email = "{email}" AND players_password = "******"'''
    players_bon_password = sql_select(sql_request)

    if len(players_bon_password) == 0:
        return "Mot de passe incorrect", 503

    print(players_bon_password[0]["players_id"])
    thisDict = {"id": players_bon_password[0]["players_id"]}
    return jsonify(thisDict), 200
Ejemplo n.º 7
0
def login():
    # on récupère le json envoyé par le client
    formulaire_login = (request.get_json())

    # on récupère l'email
    email = formulaire_login["email"]

    # on check si l'email existe, si oui c'est good
    sql_request = f'''SELECT * FROM players WHERE players_email = "{email}"'''

    players_avec_cette_email = sql_select(sql_request)

    if len(players_avec_cette_email) > 0:

        # on récupère le password
        password = formulaire_login["password"]

        sql_request = f'''SELECT players_id FROM players WHERE players_email  = "{email}" AND players_password = "******"'''
        players_id_avec_cette_email_et_ce_password = sql_select(sql_request)

        if len(players_id_avec_cette_email_et_ce_password) > 0:
            print("bon compte")
            player_id = {"id": int(players_avec_cette_email[0]["players_id"])}
            return jsonify(player_id)

        else:
            return "mauvais mdp"

    else:
        return "mauvais email"
Ejemplo n.º 8
0
def login():
    formulaire_connexion = (request.get_json())

    # on récupère l'email
    email = formulaire_connexion["email"]

    #on vérifie si l'adresse mail est bonne
    sql_request = f''' SELECT * FROM players WHERE players_email = "{email}" '''

    players_avec_cet_email = sql_select(sql_request)

    if len(players_avec_cet_email) == 0:
        return "Email non existant", 501

    password = formulaire_connexion["password"]

    sql_request = f'''SELECT * FROM players WHERE players_email = "{email}" AND players_password = "******"'''

    players_avec_son_mdp = sql_select(sql_request)

    if len(players_avec_son_mdp) == 0:
        return "Mot de passe éronné ", 501

    print(players_avec_son_mdp[0]["players_id"])
    Id = {"id": players_avec_son_mdp[0]["players_id"]}

    return jsonify(Id), 200
Ejemplo n.º 9
0
def login():

    formulaire_inscription = request.get_json()

    email = formulaire_inscription["email"]
    password = formulaire_inscription["password"]
    sql_request = f'''SELECT * FROM players WHERE players_email = "{email}"'''

    players_avec_cette_email = sql_select(sql_request)

    if len(players_avec_cette_email) == 0:
        return "Email non inscrit", 503

    sql_request_mdp = f'''SELECT * FROM players WHERE players_password = "******" AND players_email = "{email}"'''

    mauvais_mot_de_passe = sql_select(sql_request_mdp)

    if len(mauvais_mot_de_passe) == 0:
        return "Mot de passe incorrect", 503

    id_player = mauvais_mot_de_passe[0]["players_id"]

    print(id_player)

    dictionary = {"id": id_player}

    return jsonify(dictionary), 200
Ejemplo n.º 10
0
def login():
    # on récupère le json envoyé par le client
    formulaire_connexion = (request.get_json())

    # on récupère l'email
    email = formulaire_connexion["email"]

    # on check si l'email existe, si oui on envoie une erreur
    sql_request = f'''SELECT * FROM players WHERE players_email = "{email}"'''

    players_avec_cette_email = sql_select(sql_request)

    if len(players_avec_cette_email) == 0:
        return "Email non existant", 503

    #on récupère le password
    password = formulaire_connexion["password"]

    # on check si le password existe, si oui on envoie une erreur
    sql_request = f'''SELECT * FROM players WHERE players_password = "******" AND players_email = "{email}"'''

    players_avec_ce_password = sql_select(sql_request)

    if len(players_avec_ce_password) == 0:
        return "password non existant", 503
    

    return "Not implemented", 501
Ejemplo n.º 11
0
def login():
    # on récupère le json envoyé par le client
    formulaire_login = (request.get_json())

    # on récupère l'email
    email = formulaire_login["email"]

    # on check si l'email existe, si NON on envoie une erreur
    sql_request = f'''SELECT * FROM players WHERE players_email = "{email}"'''

    players_avec_cette_email = sql_select(sql_request)
    # == teste l'égalité
    # >= supérieur ou égal
    # != différent de
    if len(players_avec_cette_email) == 0:
        return "Email n,'existe  pas", 503

    #on récupére le mot de passe
    password = formulaire_login["password"]

    #on check si le mot de passe marche
    sql_request = f'''SELECT * FROM players WHERE players_email = "{email}" AND players_password = "******"'''
    players_avec_ce_password = sql_select(sql_request)
    if len(players_avec_ce_password) == 0:
        return "Password n, existe pas", 401

    thisdict = {
        "id":(players_avec_ce_password[0]["players_id"])
    }
    return jsonify(thisdict), 200
Ejemplo n.º 12
0
def login():
    # on récupère le json envoyé par le client
    formulaire_login = (request.get_json())

    # on récupère l'email
    email = formulaire_login["email"]

    # on check si l'email existe
    sql_request = f'''SELECT * FROM players WHERE players_email = "{email}"'''

    players_avec_cette_email = sql_select(sql_request)

    if len(players_avec_cette_email) == 0:
        return "Mail incorrect", 503

    # on recupere le password client
    password = formulaire_login["password"]

    # on check si le password existe
    sql_request = f'''SELECT * FROM players WHERE players_password = "******"'''

    players_avec_ce_mdp = sql_select(sql_request)
    print(players_avec_ce_mdp)

    if len(players_avec_ce_mdp) == 0:
        return "password  incorrect", 503

    return "ok", 501
Ejemplo n.º 13
0
def get_rooms_request(players_id):
    sql_request = f f''''SELECT * FROM rooms.player_id = {players_id}'''
    room_spawn = sql_select(sql_request)

    for room in room_spawn:
        room_id = room["rooms_id"]
        sql_request = f'''SELECT * FROM cats WHERE cats.rooms.id = {players_id}'''
        room["cats"] = sql_select(sql_request)
    return jsonify(room_spawn)
Ejemplo n.º 14
0
def get_rooms_request(players_id):
    sql_request = f'''SELECT * FROM rooms WHERE players_id = "{players_id}"'''
    room_du_player = sql_select(sql_request)

    for room in room_du_player:
        sql_request = f'''SELECT * FROM cats WHERE rooms_id = "{room["rooms_id"]}"'''
        room["cats"] = sql_select(sql_request)

    return jsonify(room_du_player)
Ejemplo n.º 15
0
def get_rooms_request(players_id):
    sql_request = f'''SELECT * FROM rooms WHERE players_id = "{players_id}"'''
    player_avec_la_room = sql_select(sql_request)

    for room in player_avec_la_room:
        sql_request = f'''SELECT * FROM cats WHERE rooms_id = "{room["rooms_id"]}"'''
        room["cats"] = sql_select(sql_request)

    print(player_avec_la_room)
    return jsonify(player_avec_la_room)
Ejemplo n.º 16
0
def get_rooms_request(players_id):
    sql_request = f'''SELECT * FROM rooms WHERE players_id = {players_id}'''
    all_rooms = sql_select(sql_request)
    print(all_rooms)

    for room in all_rooms:
        request_sql = f'''SELECT * FROM cats WHERE rooms_id = {room["rooms_id"]} '''
        room["cats"] = sql_select(request_sql)
        print(room)

    return jsonify(all_rooms), 200
Ejemplo n.º 17
0
def get_rooms_request(players_id):
    #on recup les infos des rooms appartenant au joueur
    sql_request = f'''SELECT * FROM rooms WHERE players_id = "{players_id}"'''
    player_rooms_info = sql_select(sql_request)


    for room in player_rooms_info:
        sql_request = f'''SELECT * FROM cats WHERE rooms_id = "{room["rooms_id"]}"'''
        room["cats"] = sql_select(sql_request)

    print(player_rooms_info)
    return jsonify(player_rooms_info)
Ejemplo n.º 18
0
def get_rooms_request(players_id):

    request_sql = f'''SELECT * FROM rooms WHERE rooms.players_id ={players_id}'''
    rooms_spawn = sql_select(request_sql)

    for room in rooms_spawn:

        room_id = room["rooms_id"]
        request_sql = f'''SELECT * FROM cats 
        WHERE cats.rooms_id = {room_id}'''
        room["cats"] = sql_select(request_sql)

    return jsonify(rooms_spawn)
Ejemplo n.º 19
0
def sign_up():
    # on récupère le json envoyé par le client
    formulaire_inscription = (request.get_json())

    # on récupère l'email
    email = formulaire_inscription["email"]

    # on check si l'email existe, si oui on envoie une erreur
    sql_request = f'''SELECT * FROM players WHERE players_email = "{email}"'''

    players_avec_cette_email = sql_select(sql_request)

    if len(players_avec_cette_email) > 0:
        return "Email déjà existant", 503

    # on ajoute le joueur
    sql_request = f'''INSERT INTO players(players_pseudo, players_email, players_password)
        VALUES("{formulaire_inscription["pseudo"]}", 
        "{formulaire_inscription["email"]}", 
        "{formulaire_inscription["password"]}")'''

    players_id = sql_insert(sql_request)

    add_room(players_id, 0, 0, formulaire_inscription["seed"])

    return "OK", 200
Ejemplo n.º 20
0
def delete_room(players_id, rooms_id):
    sql_request = f'''SELECT * FROM cats WHERE cats.rooms_id = "{rooms_id}"'''
    checkcat = sql_select(sql_request)
    if len(checkcat) > 0:
        return "il y a un  chat ici", 404
    else:
        sql_request = f'''DELETE FROM rooms WHERE rooms_id = "{rooms_id}" AND rooms.players_id = "{players_id}"'''
        sql_delete(sql_request)
        return "la salle a été supprimée", 200
Ejemplo n.º 21
0
def get_rooms_request(players_id):
    # Requête SQL pour obtenir les infos sur les rooms
    sql_request = f'''
    SELECT * FROM `rooms` 
    WHERE players_id = {players_id}'''

    # On stock le résultat de la requête SQL
    players_rooms = sql_select(sql_request)
    print(players_rooms)
    # On parcourt les salles pour y ajouter les chats présents dans chaque salle
    for rooms in players_rooms:
        room_id = rooms["rooms_id"]
        sql_request2 = f'''SELECT * FROM `cats`
        WHERE rooms_id = {room_id}'''
        cats = sql_select(sql_request2)
        rooms["cats"] = cats

    return jsonify(players_rooms), 200
Ejemplo n.º 22
0
def delete_room(players_id, rooms_id):
    request_sql = f'''SELECT * FROM cats WHERE cats.rooms_id = {rooms_id}'''
    checkcat = sql_select(request_sql)

    if len(checkcat) > 0:
        return "Il y a un chat dans la salle ! ASSASSIN", 404
    else:
        request_sql = f'''DELETE FROM rooms WHERE rooms_id = {rooms_id} and rooms.players_id = {players_id} '''
        sql_delete(request_sql)
        return "la salle a été supprime", 200
Ejemplo n.º 23
0
def delete_room(players_id, rooms_id):
    # Requête pour vérifier que le rooms_id est bien lié au players_id
    sql_request2 = f'''SELECT * FROM `rooms`
    WHERE `rooms_id` = {rooms_id} AND `players_id` = {players_id}'''
    room_player = sql_select(sql_request2)
    if len(room_player) == 0:
        return "Le joueur n'a pas cette salle", 403
    else:
        # Requête pour vérifier qu'il n y a pas de chat dans la salle
        sql_request3 = f'''SELECT * FROM `cats`
        WHERE `rooms_id` = {rooms_id} '''
        cats = sql_select(sql_request3)
        # Requête pour supprimer une ligne dans la table rooms
        sql_request = f'''DELETE FROM `rooms` WHERE `rooms`.`rooms_id` = {rooms_id}'''
        if len(cats) == 0:
            sql_delete(sql_request)
            return "OK", 200
        else:
            return "Suppression impossible, des chats sont présents dans la salle !", 403
Ejemplo n.º 24
0
def delete_room(players_id, rooms_id):
    sql_request = f'''SELECT * FROM cats WHERE rooms_id = "{rooms_id}"'''
    get_cats = sql_select(sql_request)

    if len(get_cats) > 0:
        return "Tu en peux pas supprimer car il y a des pauvres petits minouches dans cette room", 403
    else:
        sql_request = f'''DELETE FROM rooms WHERE players_id = "{players_id}" AND rooms_id = "{rooms_id}"'''
        sql_delete(sql_request)
        return "Ok la room est supprimée du coup !"
Ejemplo n.º 25
0
def delete_room(players_id, rooms_id):

    sql_request = f'''SELECT * FROM cats WHERE rooms_id = "{rooms_id}"'''
    chats = sql_select(sql_request)

    if len(chats) > 0:
        return "il y a des chats dans cette salle", 403
    else:
        sql_request = f'''DELETE FROM rooms WHERE players_id = "{players_id}" AND rooms_id = "{rooms_id}"'''
        sql_delete(sql_request)
        return "Salle supprimée", 200
Ejemplo n.º 26
0
def delete_room(players_id, rooms_id):

    sql_request = f'''SELECT * FROM cats WHERE rooms_id = "{rooms_id}"'''
    get_chats = sql_select(sql_request)

    if len(get_chats) > 0:
        return "Il y à des chats dans cette room", 403
    else:
        sql_request = f'''DELETE FROM rooms WHERE players_id = "{players_id}" AND rooms_id = "{rooms_id}"'''
        sql_delete(sql_request)
        return "OK Room Deleted", 200
Ejemplo n.º 27
0
def add_room(players_id, pos_x, pos_y, seed):

    request_sql = f'''SELECT * FROM rooms WHERE rooms.players_id = {players_id} AND rooms.rooms_position_x = {pos_x} AND rooms.rooms_position_y = {pos_y}'''

    checkroom = sql_select(request_sql)

    if len(checkroom) > 0:
        return "Il y a deja une salle à cet endroit", 404
    else:
        request_sql = f'''INSERT INTO rooms(players_id, rooms_position_x, rooms_position_y, rooms_seed) 
        VALUES ('{players_id}', '{pos_x}', '{pos_y}', '{seed}')'''
        room_build = sql_insert(request_sql)
        return jsonify({"id": room_build})
Ejemplo n.º 28
0
def add_room(players_id, pos_x, pos_y, seed):
    sql_request = f'''SELECT * FROM rooms 
    WHERE players_id = "{players_id}"
    AND rooms_position_x = "{pos_x}"
    AND rooms_position_x = "{pos_y}"'''
    player_rooms_info = sql_select(sql_request)

    if len(player_rooms_info) > 0:
        return "Il y a déjà une room ici", 403
    else:
        sql_request = f'''INSERT INTO rooms (rooms_position_x, rooms_position_y, rooms_seed, players_id)
        VALUES("{pos_x}", "{pos_y}", "{seed}", "{players_id}")'''
        execute = sql_insert(sql_request)
        return {"id": execute}, 200
Ejemplo n.º 29
0
def add_room(players_id, pos_x, pos_y, seed):
    sql_request = f'''SELECT * FROM rooms 
    WHERE rooms.players_id = "{players_id}" 
    AND rooms.rooms_position_x = "{pos_x}" 
    AND rooms.rooms_position_y = "{pos_y}"'''
    checkroom = sql_select(sql_request)
    if len(checkroom) > 0:

        return "il y a deja une room ici", 404
    else:
        sql_request = f'''INSERT INTO rooms (players_id, rooms_position_x, rooms_position_y, rooms_seed)
        VALUES("{players_id}", "{pos_x}", "{pos_y}", "{seed}")'''
        room_build = sql_insert(sql_request)
        return jsonify({"id": room_build}), 200
Ejemplo n.º 30
0
def login():
    #On recupere le json envoyé par le client

    formulaire_login = (request.get_json())

    #On recupere l'email et le password

    email = formulaire_login["email"]
    password = formulaire_login["password"]

    resquest_sql = f'''SELECT *
    FROM `players`
    WHERE players_email = "{email}" 
    '''

    players_login = sql_select(resquest_sql)

    if len(players_login) !=1:
        return "Mauvais email", 404


    resquest_sql = f'''SELECT * 
    FROM `players`
    WHERE players_email = "{email}" 
    AND players_password = "******"'''

    players_login = sql_select(resquest_sql)

    print(players_login)

    dictionnary = {"id": players_login[0]["players_id"]}

    if len(players_login) != 1:
        return "Mauvais MDP", 404
    else:
        return jsonify(dictionnary)