Beispiel #1
0
def recover_password():

    data = json.loads(request.data)
    username = data.get('username', None)

    if (not username or username == ""):
        return jsonify({
            "RESULT": "No ha brindado toda la informacion necesaria",
            "RETURNCODE": "-1",
            "METHOD": "POST"
        })

    user = UsersHandler.getUserByUsername(username)

    if (user == None):
        return jsonify({
            "RESULT": f"No existe ningun usuario con username {username}",
            "RETURNCODE": "1",
            "METHOD": "POST"
        })

    else:
        return jsonify({
            "RESULT": user.password,
            "RETURNCODE": "0",
            "METHOD": "POST"
        })
Beispiel #2
0
def addComment():

    data = json.loads(request.data)

    author = data.get('author', None)
    body = data.get('body', None)

    recipeAuthor = data.get('recipeAuthor', None)
    recipeTitle = data.get('recipeTitle', None)

    list = [author, body, recipeAuthor, recipeTitle]
    for element in list:
        if (not element or element == ""):
            return jsonify({
                "RESULT": "No ha brindado toda la informacion necesaria",
                "RETURNCODE": "-1",
                "METHOD": "POST"
            })

    recipe = RecipesHandler.getRecipeByAuthorAndTitle(recipeAuthor,
                                                      recipeTitle)
    if (recipe == None):
        return jsonify({
            "RESULT": "No existe esa combinacion autor-receta",
            "RETURNCODE": "1",
            "METHOD": "POST"
        })

    date = datetime.now().strftime("%d-%m-%Y %H:%M:%S")

    theAuthor = UsersHandler.getUserByUsername(author)
    if (theAuthor == None):
        return jsonify({
            "RESULT": "No existe el autor del comentario",
            "RETURNCODE": "2",
            "METHOD": "POST"
        })

    print("HERE IS THE AUTHOR FOR COMMENT", theAuthor.type)

    recipe.addComment(author, theAuthor.type, body, date)

    return jsonify({
        "RESULT": "Comentario realizado correctamente",
        "RETURNCODE": "0",
        "METHOD": "POST"
    })