Add otp validation + handle key error for add product
This commit is contained in:
parent
e1f9db5479
commit
8cc568f736
|
@ -53,8 +53,12 @@ class AddProduct(Resource):
|
|||
def post():
|
||||
data = request.json
|
||||
logging.debug("Got data: {}".format(str(data)))
|
||||
# TODO: Add validation
|
||||
otp_response = check_otp(data["name"], data["realm"],
|
||||
data["token"])
|
||||
if otp_response != 200:
|
||||
return {"message": "Wrong Credentials"}, 403
|
||||
|
||||
try:
|
||||
product_key = "/v1/products/"
|
||||
product_value = {
|
||||
"name": data["product_name"],
|
||||
|
@ -69,6 +73,10 @@ class AddProduct(Resource):
|
|||
client.put(product_key, product_value, value_in_json=True)
|
||||
return {"message":
|
||||
"Product {} created".format(data['product_name'])}, 200
|
||||
except KeyError as ke:
|
||||
logging.error("KeyError occurred. details = {}".format(str(ke)))
|
||||
return {"message":
|
||||
"Missing or wrong parameters"}, 400
|
||||
|
||||
|
||||
class UserRegisterPayment(Resource):
|
||||
|
|
Loading…
Reference in New Issue