コード例 #1
0
ファイル: login.py プロジェクト: Sebastien2712/exam_Curra
def login():

    response = {"result": 0, "error": "", "data": ""}
    requ = {
        "user": request.args.get("user"),
        "password": request.args.get("password")
    }
    if requ["user"] != None and requ["password"] != None:
        userInfo = Main.getSingleFromTable(
            "user", "idUser AS ID,username,password",
            " AND username = '******' AND active = 1", 1)
        if userInfo != None:
            userLog = Main.getMultipleFromTable(
                "user_session", "*", " AND idUser= "******"ID"]) +
                " AND active = 1 ORDER BY insertDate ASC", 1)
            if len(userLog) >= 3:
                updateData = {
                    "active": "0",
                    "logoutDate": str(datetime.datetime.now())
                }
                updateWhere = {
                    "id_user_session": userLog[0]["id_user_session"]
                }
                update = Main.updateTable("user_session", updateData,
                                          updateWhere, 1)
            if requ["password"] == userInfo["password"]:
                token = ''.join(
                    choice(string.ascii_letters + string.digits)
                    for i in range(64))
                userInsert = {
                    "idUser": str(userInfo["ID"]),
                    "bearerToken": token
                }
                login = Main.insertTable("user_session", userInsert, 1)
                if login != None:
                    response["result"] = 1
                    response["data"] = {"username": userInfo["username"]}
                else:
                    response["error"] = "User Not Login"
            else:
                response["error"] = "Incorrect Password"
        else:
            response["error"] = "User Not Found"
    else:
        response["error"] = "Parameter"
    return response
コード例 #2
0
ファイル: colonia.py プロジェクト: Sebastien2712/exam_Curra
def colonia():
    response = {"result": 0, "error": "", "data": ""}
    requ = request.get_json()
    if request.headers.get('Authorization'):
        if request.method == "GET":
            if request.args.get("cp"):
                colonia = Main.getSingleFromTable(
                    "colonia", "d_asenta AS colonia",
                    " AND d_codigo= '" + str(request.args.get("cp")) + "'", 1)
                if colonia != []:
                    response["data"] = colonia
                    response["result"] = 1
                else:
                    response["error"] = "No existe esta colonia"
            else:
                response["error"] = "Se busca por Codigo Postal"
        else:
            response["error"] = "Tiene que ser un GET"
    else:
        response["error"] = "No tienes Authorization"
    return response
コード例 #3
0
def getEstado():
    response = {"result": 0, "error": "", "data": ""}
    requ = request.get_json()
    if request.headers.get('Authorization'):
        if request.method == "GET":
            if request.args.get("nombre"):
                estado = Main.getSingleFromTable(
                    "estado", "d_estado AS estado",
                    " AND d_estado= '" + str(request.args.get("nombre")) + "'",
                    1)
                if estado != []:
                    response["data"] = estado
                    response["result"] = 1
                else:
                    response["error"] = "No existe este estado"
            else:
                response["error"] = "Se busca por nombre completo"
        else:
            response["error"] = "Tiene que ser un GET"
    else:
        response["error"] = "No tienes Authorization"
    return response