Add otp validation + handle key error for add product
This commit is contained in:
parent
e1f9db5479
commit
8cc568f736
1 changed files with 23 additions and 15 deletions
|
@ -53,8 +53,12 @@ class AddProduct(Resource):
|
||||||
def post():
|
def post():
|
||||||
data = request.json
|
data = request.json
|
||||||
logging.debug("Got data: {}".format(str(data)))
|
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_key = "/v1/products/"
|
||||||
product_value = {
|
product_value = {
|
||||||
"name": data["product_name"],
|
"name": data["product_name"],
|
||||||
|
@ -69,6 +73,10 @@ class AddProduct(Resource):
|
||||||
client.put(product_key, product_value, value_in_json=True)
|
client.put(product_key, product_value, value_in_json=True)
|
||||||
return {"message":
|
return {"message":
|
||||||
"Product {} created".format(data['product_name'])}, 200
|
"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):
|
class UserRegisterPayment(Resource):
|
||||||
|
|
Loading…
Add table
Reference in a new issue