コード例 #1
0
ファイル: routes.py プロジェクト: pgarr/dinner-roulette
def recipe(pk):
    recipe_model = get_recipe(pk)
    if recipe_model.status == StatusEnum.accepted or recipe_model.is_author_or_admin(
            get_current_user()):
        result = recipe_schema.dump(recipe_model)
        return jsonify({'recipe': result})
    else:
        return error_response(401, "Unauthorized")
コード例 #2
0
ファイル: routes.py プロジェクト: pgarr/dinner-roulette
def reject(pk):
    if current_user.admin:
        recipe = get_recipe(pk)
        accepted_recipe = reject_recipe(recipe)
        result = recipe_schema.dump(accepted_recipe)
        return jsonify({"message": "Recipe rejected!", "recipe": result}), 200
    else:
        return error_response(401)
コード例 #3
0
ファイル: routes.py プロジェクト: pgarr/dinner-roulette
def pending_recipes():
    if current_user.admin:
        page = request.args.get('page', 1)
        per_page = request.args.get('per_page',
                                    current_app.config['RECIPES_PER_PAGE'])
        recipes = get_pending_recipes(page=page, per_page=per_page)
        return paginated_recipes_jsonify(recipes,
                                         page,
                                         per_page,
                                         endpoint='.pending_recipes')
    else:
        return error_response(401)
コード例 #4
0
ファイル: routes.py プロジェクト: pgarr/dinner-roulette
def fresh_login():
    json = request.json
    if json:
        username = json.get('username', '')
        password = json.get('password', '')
    else:
        return bad_request("Lack of required payload data")

    payload = get_fresh_jwt_token(username, password, with_refresh_token=False)
    if payload:
        return jsonify(payload), 200
    else:
        return error_response(401, "Bad username or password")
コード例 #5
0
ファイル: routes.py プロジェクト: pgarr/dinner-roulette
def reset_password_request():
    json = request.json
    if json:
        email = json.get('email', '')
    else:
        return bad_request("Lack of required payload data")

    user = get_user_by_email(email)

    if user:
        send_password_reset_email(user)
        return jsonify({'message': 'Done!'}), 202
    else:
        return error_response(422, "Email address not registered")
コード例 #6
0
ファイル: routes.py プロジェクト: pgarr/dinner-roulette
def update_recipe(pk):
    json_data = request.get_json()
    if not json_data:
        return bad_request('No input data provided')
    recipe_model = get_recipe(pk)
    if current_user == recipe_model.author or current_user.admin:
        try:
            data = recipe_schema.load(json_data)
        except ValidationError as err:
            return jsonify(err.messages), 422
        recipe_model = save_recipe_from_schema(data, recipe_model)
        result = recipe_schema.dump(recipe_model)
        return jsonify({
            "message":
            "Changes will be seen for other users after administrator acceptance.",
            "recipe": result
        }), 200
    else:
        return error_response(401)
コード例 #7
0
ファイル: routes.py プロジェクト: pgarr/dinner-roulette
def create_recipe():
    if not current_user:
        return error_response(401, "Unauthorized")

    json_data = request.get_json()
    if not json_data:
        return bad_request('No input data provided')
    try:
        data = recipe_schema.load(json_data)
    except ValidationError as err:
        return jsonify(err.messages), 422
    model = init_recipe(author=current_user)
    model = save_recipe_from_schema(data, model)
    result = recipe_schema.dump(model)
    return jsonify({
        "message":
        "Recipe will be seen for other users after administrator acceptance.",
        "recipe": result
    }), 201
コード例 #8
0
ファイル: routes.py プロジェクト: pgarr/dinner-roulette
def reset_password(token):
    json = request.json
    if json:
        password = json.get('password', '')
    else:
        return bad_request("Lack of required payload data")

    user = verify_reset_password_token(token)
    if not user:
        return error_response(401, 'Invalid token')

    is_password_valid, password_check_dict = validate_password(password)

    if is_password_valid:
        set_new_password(user, password)
        return jsonify({'message': 'Done!'}), 200
    else:
        payload = {
            'password': {
                'valid': is_password_valid,
                'checks': password_check_dict
            }
        }
        return jsonify(payload), 422