from flask import jsonify from flask_restplus.namespace import RequestParser from ....resources.customer import CustomerManager ################# # Parser # ################# Parser = RequestParser() Parser.add_argument('index', help="Index of the address to be deleted", type=int, required=True, location="form") ################# # Method # ################# def Delete(args, identity): index = args['index'] cm = CustomerManager() result = cm.delete_billing(identity, index) if result == -2: response = jsonify({ "statusCode": 400, "message": "Address index given is out of the array.", }) elif result == -1:
from flask import jsonify from flask_restplus.namespace import RequestParser from ...resources.customer import CustomerManager ################# # Parser # ################# Parser = RequestParser() Parser.add_argument('first_name', help='Customer first name', required=True, location='form') Parser.add_argument('last_name', help='Customer last name', required=True, location='form') Parser.add_argument('email', help='Customer email', required=True, location='form') Parser.add_argument('password', help='Customer password', required=True, location='form') Parser.add_argument('phone', help='Customer phone number', required=False, location='form') #################
from flask import jsonify, request, make_response from flask_restplus.namespace import RequestParser, request from ....resources.admin import AdminManagement from flask_jwt_extended import (create_access_token, create_refresh_token) from ....resources.mail.reset_password import send_reset_password_email ################# # Parser # ################# Parser = RequestParser() Parser.add_argument('email', help="The user's email", required=True, location='form') ################# # Method # ################# def Post(args): email = args['email'] am = AdminManagement() result, accessCode = am.request_reset(email) print("I received a {} and a {}".format(result, accessCode)) if result == 1: # Successfully requested send_reset_password_email(accessCode, email) response = jsonify({ "statusCode": 200,
from flask import jsonify from flask_restplus.namespace import RequestParser from flask_restplus import inputs from ....resources.customer import CustomerManager ################# # Parser # ################# Parser = RequestParser() Parser.add_argument('address', required=True, location='form') Parser.add_argument('country', required=True, location='form') Parser.add_argument('state', required=True, location='form') Parser.add_argument('city', required=True, location='form') Parser.add_argument('zip_code', required=True, location='form') Parser.add_argument('first_name', required=True, location='form') Parser.add_argument('last_name', required=True, location='form') Parser.add_argument( 'is_default', help= 'Blank for false, filled in if you want to override the current default', type=inputs.boolean, required=False, location='form') ################# # Method # ################# def Post(args, identity): address = args['address'] country = args['country']
from flask import jsonify from flask_restplus.namespace import RequestParser from ....resources.order import UserOrder ################# # Parser # ################# Parser = RequestParser() Parser.add_argument( 'user_billing', help="Index in the array of the user's billing addresses to be used.", required=True, type=int, location='form') Parser.add_argument( 'user_shipping', help="Index in the array of the user's billing addresses to be used.", required=True, type=int, location='form') Parser.add_argument( 'payment', help='User payment provider information. Depends on the provider', required=True, location='form') ################# # Method # ################# def Put(args, identity):
from flask import jsonify, request, make_response from flask_restplus.namespace import RequestParser, request from ...resources.admin import AdminManagement from flask_jwt_extended import (create_access_token, create_refresh_token) from ...resources.validation import is_admin, is_not_admin_response ################# # Parser # ################# Parser = RequestParser() Parser.add_argument('current_password', help='Current password of admin', required=True, location='form') Parser.add_argument('first_name', help='First name of the admin', required=False, location='form') Parser.add_argument('last_name', help='Last name of the admin', required=False, location='form') Parser.add_argument('new_password', help='Password that will replace the current one', required=False, location='form') ################# # Method # #################
from flask import jsonify from flask_restplus.namespace import RequestParser from ...resources.admin import AdminManagement from flask_jwt_extended import (create_access_token, create_refresh_token, jwt_required, jwt_refresh_token_required, get_jwt_identity, get_raw_jwt) from ...resources.password_management import hash_password, verify_hash from ...resources.mail.reset_password import send_reset_password_email from ...resources.validation import is_admin, is_not_admin_response ################# # Parser # ################# Parser = RequestParser() Parser.add_argument('first_name', help='First name of the admin to be registered', required=True, location='form') Parser.add_argument('last_name', help='Last name of the admin to be registered', required=True, location='form') Parser.add_argument( 'email', help='Email address under which the admin will be registered', required=True, location='form') ################# # Method #
from flask import jsonify from flask_restplus.namespace import RequestParser from ....resources.customer import CustomerManager from flask_jwt_extended import (create_access_token, create_refresh_token, jwt_required, jwt_refresh_token_required, get_jwt_identity, get_raw_jwt) from datetime import timedelta ################# # Parser # ################# Parser = RequestParser() Parser.add_argument("email", help="Customer's e-mail tied to their account.", required=False, location="form") Parser.add_argument("password", help="Customer's password.", required=False, location="form") ################# # Method # ################# def Post(args): email = args['email'] password = args['password'] print("The user {} is trying to log in.".format(email)) cm = CustomerManager()
from ....resources.card import CardManager from flask import jsonify from flask_restplus.namespace import RequestParser from flask_jwt_extended import (jwt_required, get_jwt_identity) from jwt.exceptions import ExpiredSignatureError ################# # Parser # ################# Parser = RequestParser() Parser.add_argument('card_token', help='Token returned from front end by Stripe.js', required=True) ################# # Method # ################# def Put(args, identify): token = args['card_token'] cm = CardManager() result = cm.add_card(identify, token) if result is 0: return jsonify({ "statusCode": 200, "message": "Card info successfully updated" })
from flask import jsonify from flask_restplus.namespace import RequestParser from ....resources.product import UserProduct ################# # Parser # ################# Parser = RequestParser() Parser.add_argument('sort', type=int, help='ID of the Sorting method to be used', required=False) Parser.add_argument( 'search_name', help='A description of the filtering parameters to be used', required=False) Parser.add_argument( 'digital_filtering', type=int, help= 'If value is: -1, results will exclude digital products. 1, results will exclude physical products. 0, results will include everything.', required=False) Parser.add_argument('page', type=int, help='Page the request is asking for', required=False) Parser.add_argument('page_size', type=int, help='Page the request is asking for', required=False) Parser.add_argument(
from ....resources.card import CardManager from flask import jsonify from flask_restplus.namespace import RequestParser from flask_jwt_extended import (jwt_required, get_jwt_identity) from jwt.exceptions import ExpiredSignatureError ################# # Parser # ################# Parser = RequestParser() Parser.add_argument('card_id', help='ID of the card to be removed.', required=True) ################# # Method # ################# def Delete(args, identify): card_id = args['card_id'] cm = CardManager() result = cm.delete_card(identify, card_id) if result: return jsonify({ "statusCode": 200, "message": "Card information was deleted succesfully" }) else:
from flask import jsonify from flask_restplus.namespace import RequestParser from werkzeug.datastructures import FileStorage from ....resources.product import AdminProduct from ....resources.validation import is_admin, is_not_admin_response from ....resources.images import upload_image from ....resources import responses import tempfile ################# # Parser # ################# Parser = RequestParser() Parser.add_argument('name', help='Name of the product to be added', required=True, location='form') Parser.add_argument('price', help='Price in cents of the product to be added', type=int, required=True, location='form') Parser.add_argument('image', help='Picture of the product to be added', type=FileStorage, location='files', required=False) Parser.add_argument('digital', help="Whether the product is a digital product or not", type=bool, required=True, location='form')
from flask import jsonify from flask_restplus.namespace import RequestParser from ....resources.order import AdminOrder from ....resources.validation import is_admin, is_not_admin_response ################# # Parser # ################# Parser = RequestParser() Parser.add_argument('sort', type=int, help='ID of the sorting method to be used', required=False) Parser.add_argument( 'filter', help= 'A comma separated string of all the status names that we are excluding. Capitalizes the first letter of each word internally.', required=False) Parser.add_argument('page', type=int, help='Page the request is asking for', required=False) Parser.add_argument('page_size', type=int, help='Page the request is asking for', required=False) ################# # Method # ################# def Get(args, identity):
from flask import jsonify from flask_restplus.namespace import RequestParser from ...resources.cart import CartManager ################# # Parser # ################# Parser = RequestParser() Parser.add_argument('product_id', help="The ObjectID of the product to be affected.", required=True) Parser.add_argument( 'quantity', type=int, help="The new quantity of the product. Must be greater than 0.", required=True) ################# # Method # ################# def Put(args, identity): product_id = args['product_id'] quantity = args['quantity'] customer_id = identity if quantity <= 0: response = jsonify({ "statusCode": 406,
from ....resources.card import CardManager from flask import jsonify from flask_restplus.namespace import RequestParser from flask_jwt_extended import (jwt_required, get_jwt_identity) from jwt.exceptions import ExpiredSignatureError ################# # Parser # ################# Parser = RequestParser() Parser.add_argument( 'card', help='''This will expect an card_id o a token from Stripe.js''', required=True) Parser.add_argument('order_id', help=r"Order's identifier", required=True) ################# # Method # ################# CLIENT = 1 GUEST = 0 def PayPut(args, identify): token = args['card'] order_id = args['order_id'] cm = CardManager()
from flask import jsonify from flask_restplus.namespace import RequestParser from ...resources.validation import is_admin, is_not_admin_response from ...resources.admin import AdminManagement ################# # Parser # ################# Parser = RequestParser() Parser.add_argument('sort', type=int, help='NYI ID of the Sorting method to be used.', required=False) Parser.add_argument('page', type=int, help='Page the request is asking for.', required=False) Parser.add_argument( 'page_size', type=int, help='Elements to be displayed by page. Server has a default.', required=False) Parser.add_argument( 'search_field', help= 'Field in which we are looking. Expects: "Email" or "Name". Name looks up both First name and Last name.', required=False) Parser.add_argument( 'search_value', help= 'Value that is being asked for. Name or Email value. Must not be blank if search_field is in the query.', required=False)
from flask import jsonify from flask_restplus.namespace import RequestParser from flask_restplus import inputs from ....resources.customer import CustomerManager ################# # Parser # ################# Parser = RequestParser() #We need the old address to find the object we will replace Parser.add_argument('index', type=int, required=True, location='form', help="Index of the address to be updated") Parser.add_argument('address', required=False, location='form') Parser.add_argument('between', required=False, location='form') Parser.add_argument('country', required=False, location='form') Parser.add_argument('state', required=False, location='form') Parser.add_argument('city', required=False, location='form') Parser.add_argument('zip_code', required=False, location='form') Parser.add_argument('first_name', required=False, location='form') Parser.add_argument('last_name', required=False, location='form') Parser.add_argument('delivery_notes', required=False, location='form') Parser.add_argument( 'is_default', help= 'Blank for false, filled in if you want to override the current default', type=inputs.boolean, required=False, location='form') #################
from flask import jsonify, Flask from ....resources.token import revoke_token from flask_restplus.namespace import RequestParser from flask_jwt_extended import (jwt_required, get_raw_jwt) ################# # Parser # ################# Parser = RequestParser() Parser.add_argument('Authorization', help='Token of the admin.', required=True, location='headers') ################# # Method # ################# @jwt_required def Delete(args): ''' jti = unique identifier of the token ''' jti = get_raw_jwt()['jti'] print(jti) try: revoke_token(jti) response = jsonify({ 'message': 'Access token has been revoked', "statusCode": 200
from flask import jsonify, request, make_response from flask_restplus.namespace import RequestParser, request from ....resources.admin import AdminManagement from flask_jwt_extended import (create_access_token, create_refresh_token) ################# # Parser # ################# Parser = RequestParser() Parser.add_argument( 'access_code', help="Access code the user got in their email to reset their password", required=True) Parser.add_argument('email', help="The user's email", required=True, location='form') Parser.add_argument('password', help='The new password', required=True, location='form') ################# # Method # ################# def Put(args): email = args['email'] password = args['password'] code = args['access_code']
from flask import jsonify from flask_restplus.namespace import RequestParser from ....resources.order import UserOrder ################# # Parser # ################# Parser = RequestParser() Parser.add_argument('sort', type=int, help='ID of the sorting method to be used (NYI)', required=False) Parser.add_argument( 'filter', help= 'Comma separated string of all filters that apply. If left blank it will give every order. Otherwise it will be an inclusive filter. Only giving out the statuses that are in the filter.', required=False) Parser.add_argument('page', type=int, help='Page the request is asking for', required=False) ################# # Method # ################# def Get(args, identity): filter = args['filter'] sort = 0 if not args['sort'] else args['sort'] page = 0 if not args['page'] else args['page'] uo = UserOrder()
from flask import jsonify from flask_restplus.namespace import RequestParser from flask_jwt_extended import (jwt_required, get_jwt_identity) from jwt.exceptions import ExpiredSignatureError from ...resources.cart import CartManager ################# # Parser # ################# Parser = RequestParser() Parser.add_argument('product_id', help="The ObjectID of the product to be affected.", required=True) ################# # Method # ################# @jwt_required def Delete(args, identity): pid = args['product_id'] cm = CartManager() response = None try: if identity is not None: cart = cm.get_cart(identity, exclude=False) products = [x["_id"] for x in cart["products"]] if len(cart):
from flask import jsonify from flask_restplus.namespace import RequestParser from ....resources.product import AdminProduct from ....resources.validation import is_admin, is_not_admin_response from bson.errors import InvalidId from ....resources import responses ################# # Parser # ################# Parser = RequestParser() Parser.add_argument('id', help='ID of the product to be deleted', required=True) ################# # Method # ################# def Delete(args, identity): pId = args['id'] ap = AdminProduct() if not is_admin(identity): response = is_not_admin_response else: try: result = ap.delete_product(pId) if result == 1: response = responses.success("Deleted a product")
from flask import jsonify from flask_restplus import Resource from flask_restplus.namespace import RequestParser from flask_jwt_extended import (create_access_token, jwt_refresh_token_required, get_jwt_identity) ################# # Parser # ################# Parser = RequestParser() ################# # Method # ################# @jwt_refresh_token_required def Put(args): ''' Refresh token ''' _id = get_jwt_identity() access_token = create_access_token(identity=_id) return {'access_token': access_token}
from flask import jsonify from flask_restplus.namespace import RequestParser from ...resources.validation import is_admin, is_not_admin_response from ...resources.admin import AdminManagement ################# # Parser # ################# Parser = RequestParser() Parser.add_argument('id', help='ID of the admin to be deleted', required=True, location='form') ################# # Method # ################# def Delete(args, identity): if not is_admin(identity): response = is_not_admin_response else: admin_id = args['id'] print("{} == {} ? ".format(identity, admin_id)) if identity == admin_id: response = jsonify({ "statusCode": 406, "message": "Admin can not delete itself." })