Example #1
0
 def post(self, ownerName, storeName):
     if userModel.find_by_username(ownerName):
         store = storeModel.find_store_by_name_and_ownerName(storeName, ownerName)
         if store:
             return {"Error": "Store Already exist"}, 400
         store = storeModel(ownerName, storeName)
         store.create_store()
         return {"Store": "Added Successfully"}
     return {"Error": "Owner is not registered."}
Example #2
0
 def delete(self, ownerName, storeName):
     if userModel.find_by_username(ownerName):
         store = storeModel.find_store_by_name_and_ownerName(storeName, ownerName)
         if store:
             for item in itemModel.query.filter_by(storeName=storeName):
                 item.delete_from_db()
             store.delete_store_and_items()
             return {"Store": "Deleted Successfully"}
         return {"Error": "Store Not Found"}, 404
     return {"Error": "Owner is not registered"}
Example #3
0
 def post(cls):
     data = _user_parser.parse_args()
     user = userModel.find_by_username(data['username'])
     if user and safe_str_cmp(data['password'], user.password):
         access_token = create_access_token(identity=user.id, fresh=True)
         refresh_token = create_refresh_token(user.id)
         return {
             "access_token": access_token,
             "refresh_token": refresh_token
         }
     return {"Login": "******"}
Example #4
0
 def post(self):
     data = _user_parser.parse_args()
     if userModel.find_by_username(data['username']):
         return {"Registration": "Username already exist"}, 400
     connection = sqlite3.connect('data.db')
     cursor = connection.cursor()
     cursor.execute("INSERT INTO users VALUES(NULL,?,?)",
                    (data['username'], data['password']))
     connection.commit()
     connection.close()
     return {"Registeration": "Successful"}, 201
Example #5
0
 def get(self, ownerName, storeName):
     if userModel.find_by_username(ownerName):
         if storeModel.find_store_by_name_and_ownerName(storeName, ownerName):
             return storeModel.find_store_by_name_and_ownerName(storeName, ownerName).json()
         return {"Error": "Store Not Found"}, 404
     return{"Error": "Owner is not registered"}