def delete(self): """ Delete user """ user_data = request.get_json() user = UserModel.find_by_username(user_data["user_name"]) if user is None: user = UserModel.find_by_email(user_data["email"]) if user is None: return {"message": gettext("error_user_not_found")}, 404 try: user.delete() except Exception: return {"message": gettext("error_user_deleting")}, 500 return {"message": gettext("user_deleted")}, 200
def post(self): """ Create new user """ user_data = request.get_json() if UserModel.find_by_username(user_data["user_name"]): return {"message": gettext("error_user_exists")}, 400 if UserModel.find_by_email(user_data["email"]): return {"message": gettext("error_user_exists")}, 400 user = UserModel(**user_data) try: user.save() except Exception: return {"message": gettext("error_user_creating")}, 500 return Response(user.to_json(), mimetype="application/json", status=200)