def decorated_function(*args, **kwargs): token = None apt_login = None if "Authorization" in flask.request.headers: base64string = flask.request.headers["Authorization"] base64string = base64string.split()[1].strip() userstring = base64.b64decode(base64string) (apt_login, token) = userstring.decode("utf-8").split(":") token_auth = False if token and apt_login: user = UsersLogic.get_by_api_login(apt_login).first() if (user and user.api_token == token and user.api_token_expiration >= datetime.date.today()): token_auth = True flask.g.user = user if not token_auth: output = { "output": "notok", "error": "Login invalid/expired. " "Please visit https://copr.fedoraproject.org/api " "get or renew your API token.", } jsonout = flask.jsonify(output) jsonout.status_code = 500 return jsonout return f(*args, **kwargs)
def decorated_function(*args, **kwargs): token = None apt_login = None if "Authorization" in flask.request.headers: base64string = flask.request.headers["Authorization"] base64string = base64string.split()[1].strip() userstring = base64.b64decode(base64string) (apt_login, token) = userstring.decode("utf-8").split(":") token_auth = False if token and apt_login: user = UsersLogic.get_by_api_login(apt_login).first() if (user and user.api_token == token and user.api_token_expiration >= datetime.date.today()): token_auth = True flask.g.user = user if not token_auth: output = { "output": "notok", "error": "Login invalid/expired. Please visit {0}/api to get or renew your API token." .format(app.config["FRONTEND_BASE_URL"]), } jsonout = flask.jsonify(output) jsonout.status_code = 500 return jsonout return f(*args, **kwargs)
def decorated_function(*args, **kwargs): token = None apt_login = None if "Authorization" in flask.request.headers: base64string = flask.request.headers["Authorization"] base64string = base64string.split()[1].strip() userstring = base64.b64decode(base64string) (apt_login, token) = userstring.split(":") token_auth = False if token and apt_login: user = UsersLogic.get_by_api_login(apt_login).first() if (user and user.api_token == token and user.api_token_expiration >= datetime.date.today()): token_auth = True flask.g.user = user if not token_auth: output = { "output": "notok", "error": "Login invalid/expired. " "Please visit https://copr.fedoraproject.org/api " "get or renew your API token.", } jsonout = flask.jsonify(output) jsonout.status_code = 500 return jsonout return f(*args, **kwargs)
def decorated_function(*args, **kwargs): token = None apt_login = None if "Authorization" in flask.request.headers: base64string = flask.request.headers["Authorization"] base64string = base64string.split()[1].strip() userstring = base64.b64decode(base64string) (apt_login, token) = userstring.decode("utf-8").split(":") token_auth = False if token and apt_login: user = UsersLogic.get_by_api_login(apt_login).first() if (user and user.api_token == token and user.api_token_expiration >= datetime.date.today()): if user.proxy and "username" in flask.request.form: user = UsersLogic.get( flask.request.form["username"]).first() token_auth = True flask.g.user = user if not token_auth: url = 'https://' + app.config["PUBLIC_COPR_HOSTNAME"] url = helpers.fix_protocol_for_frontend(url) output = { "output": "notok", "error": "Login invalid/expired. Please visit {0}/api to get or renew your API token." .format(url), } jsonout = flask.jsonify(output) jsonout.status_code = 401 return jsonout return f(*args, **kwargs)