def get(self, item_id, item): logfile = item.logfile if not logfile: raise http_exceptions.NotFound() download = self.request_query.get("download", "no") try: download = distutils.util.strtobool(download) except Exception: download = False request_json = False for header in "Accept", "Content-Type": header = self.request_headers.get(header) or "" if header == "application/json": request_json = True break if not download and request_json: def generator(): fileobj = codecs.getreader("utf-8")(logfile, errors="ignore") result = fileobj.read(1024) while result: yield result result = fileobj.read(1024) return {"data": "".join(generator())} response = generic.fs_response(logfile, download, cache_for=LOG_CACHE_TIMEOUT) response = response.make_conditional(flask.request.environ) return response
def post_update_password(self, item_id): reset_model = password_reset.PasswordReset.get(item_id) if not reset_model: raise http_exceptions.NotFound() try: reset_model.consume(self.request_json["password"]) except Exception as exc: LOG.warning("Failed attempt to reset password for user %s: %s", reset_model.user_id, exc) if isinstance(exc, base_exceptions.PasswordResetExpiredError): message = "Token is expired" else: message = "Invalid user {0}".format(reset_model.user_id) raise http_exceptions.BadRequest(message) else: LOG.info("Password for user %s was reset.", reset_model.user_id) return {"message": "Password has been reset"}
def get(self): role_model = auth.AUTH.get_current_user().role if role_model is None: raise http_exceptions.NotFound("Cannot find role") return role_model
def get(self, item_id): reset_model = password_reset.PasswordReset.get(item_id) if not reset_model: raise http_exceptions.NotFound() return {"message": "Password reset was requested"}