Пример #1
0
def get_note(note_id):
    # get the note using the id of the user
    user_id = str(current_identity.id)

    if request.method == 'GET':
        note_result = db.get_note_by_user_id_and_note_id(user_id, note_id)

        if not note_result:
            raise ApiBadRequestException("No note found for the given note_id!")

        return data_json_response(200, note_result)

    elif request.method == 'DELETE':
        db.delete_note(user_id, note_id)

        return json_response(200, "message", "Note deleted successfully!")

    else:
        # get and validate note from request
        note_json = get_request_json()
        validate_note_json(note_json)

        title = note_json["title"]
        content = note_json["content"]
        updated = note_json["last_updated"]

        # persist the note into the database
        db.update_note(user_id, note_id, title, content, updated)

        return json_response(200, "message", "Note updated successfully!")
Пример #2
0
def reset_password():
    """User account administration"""

    # User reached route via POST (as by submitting a form via POST)
    if request.method == "POST":

        new_password = request.form.get("new-password")
        old_password = request.form.get("old-password")

        # Validate email and password
        validate_passwords(new_password, old_password)

        # Get user from database
        user = get_user_by_id_and_pass(get_session_user_id(), old_password)

        # Update user password
        update_user_password(get_session_user_id(), new_password)

        message = "Account password has been successfully changed!"

        # Redirect user to home page
        return get_account_page(user["email"], message)

    elif request.method == "DELETE":
        user_id = str(current_identity.id)
        db.delete_account(user_id)
        return json_response(200, "Message", "User deleted successfully")

    # User reached route via GET (as by clicking a link or via redirect)
    else:
        user = get_user_by_id(get_session_user_id())
        return get_account_page(user["email"], "")
Пример #3
0
def get_user_object_by_id(user_id):
    rows = db.get_user_by_id(user_id)

    if not rows:
        return json_response(403, "user not found")

    user_map = rows[0]
    return User(user_map["id"], user_map["email"], user_map["password"])
Пример #4
0
def add(request):
    json_data = json.loads(request.body)
    product = Product.objects.get(id=json_data['item']["id"])
    quantity = json_data['quantity']
    shopList = ShopList.objects.get(id=1)

    ShopItem.objects.filter(list_name=shopList, item=product).delete()

    if (int(quantity) > 0):
        shopItem = ShopItem(item=product,
                            quantity=quantity,
                            list_name=shopList)
        shopItem.save()

    return json_response(shopList.items.all().values())
Пример #5
0
def create_note():
    user_id = str(current_identity.id)

    # get and validate note from request
    note_json = get_request_json()
    validate_note_json(note_json)

    title = note_json["title"]
    content = note_json["content"]
    created = note_json["created"]

    # persist the note into the database
    db.save_note(user_id, title, content, created)

    return json_response(200, "message", "Note created.")
Пример #6
0
def is_authenticated():
    return json_response(200, "message", "auth ok.")
Пример #7
0
def valid_elements(request):
    return json_response(Product.objects.filter(valid=True).values())
Пример #8
0
def all(request):
    return json_response(Product.objects.filter(valid=False).values())