예제 #1
0
def uploadMunicpio():
    response = {"result": 0, "error": "", "data": ""}
    if request.method == "POST":
        PATH_FILE = 'csvs/'
        if 'file' in request.files:
            file = request.files['file']
            if file.filename != '':
                if file and allowed_file(file.filename):
                    if not os.path.exists(PATH_FILE):
                        os.makedirs(PATH_FILE)
                    extension = "." + file.filename.rsplit('.', 1)[1].lower()
                    filename = extension
                    r_save = file.save(os.path.join(PATH_FILE, filename))
                    with open(PATH_FILE + filename) as csvfile:
                        reader = csv.DictReader(csvfile)
                        lista = []
                        aux1 = []
                        cont = 0
                        for row in reader:
                            lista.append(row)
                        for row in lista:
                            if row.keys() >= {
                                    "c_estado", "d_municipio", "c_mnpio"
                            }:
                                insertData = {
                                    "c_estado": row["c_estado"],
                                    "d_municipio": row["d_municipio"],
                                    "c_mnpio": row["c_mnpio"]
                                }
                                insert = Main.insertTable(
                                    "municipio", insertData, 1)
                                if insert != None:
                                    response["data"] = insert
                                else:
                                    response["error"] = "Hay campos vacios"
                            else:
                                response[
                                    "error"] = "Error Not Parameters Found"
                else:
                    response["error"] = "Error filename"
            else:
                response["error"] = "Error filename vacio"
        else:
            response["error"] = "Error file"
    else:
        reponse["error"] = "Es un POST"
    return response
예제 #2
0
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