def post(self, username): data = request.get_json(force=True) data['username'] = username data['_id'] = 0 if AccountsModel.find_by_name(username, data['account_name']): return {'message': "An account '{}' already exists.".format(account_name)}, 400 account = AccountsModel(data) try: account.insert_to_db() except: return {"message": "An error occurred creating the store."}, 500 return account.json(), 201
def post(self): parser = reqparse.RequestParser( ) # create parameters parser from request # define al input parameters need and its type parser.add_argument(n.USR, type=str, required=True, help="Username") parser.add_argument(n.PSW, type=str, required=True, help="Password") data = parser.parse_args() with lock.lock: user = AccountsModel.find_by_username(data[n.USR]) if user: return {n.MSG: "User already in database"}, 400 user = AccountsModel(data[n.USR]) user.hash_password(data[n.PSW]) user.save_to_db() return user.json(), 200