def get_register_name(): try: user = api.get_account(flask.session) except ApiError as api_error: return _handle_errors(api_error) available_stores = logic.filter_available_stores(user["stores"]) snap_name = flask.request.args.get("snap_name", default="", type=str) conflict_str = flask.request.args.get( "conflict", default="False", type=str ) conflict = conflict_str == "True" already_owned_str = flask.request.args.get( "already_owned", default="False", type=str ) already_owned = already_owned_str == "True" is_private_str = flask.request.args.get( "is_private", default="False", type=str ) is_private = is_private_str == "True" context = { "snap_name": snap_name, "is_private": is_private, "conflict": conflict, "already_owned": already_owned, "available_stores": available_stores, } return flask.render_template("publisher/register-snap.html", **context)
def after_login(resp): flask.session["macaroon_discharge"] = resp.extensions["macaroon"].discharge if not resp.nickname: return flask.redirect(LOGIN_URL) try: account = dashboard.get_account(flask.session) flask.session["openid"] = { "identity_url": resp.identity_url, "nickname": account["username"], "fullname": account["displayname"], "image": resp.image, "email": account["email"], } except ApiCircuitBreaker: flask.abort(503) except Exception: flask.session["openid"] = { "identity_url": resp.identity_url, "nickname": resp.nickname, "fullname": resp.fullname, "image": resp.image, "email": resp.email, } return flask.redirect(open_id.get_next_url())
def after_login(resp): flask.session["macaroon_discharge"] = resp.extensions["macaroon"].discharge if not resp.nickname: return flask.redirect(LOGIN_URL) try: account = dashboard.get_account(flask.session) flask.session["openid"] = { "identity_url": resp.identity_url, "nickname": account["username"], "fullname": account["displayname"], "image": resp.image, "email": account["email"], "is_canonical": LP_CANONICAL_TEAM in resp.extensions["lp"].is_member, } owned, shared = logic.get_snap_names_by_ownership(account) flask.session["user_shared_snaps"] = shared except ApiCircuitBreaker: flask.abort(503) except Exception: flask.session["openid"] = { "identity_url": resp.identity_url, "nickname": resp.nickname, "fullname": resp.fullname, "image": resp.image, "email": resp.email, } return flask.redirect(open_id.get_next_url())
def get_account_details(): try: # We don't use the data from this endpoint. # It is mostly used to make sure the user has signed # the terms and conditions. api.get_account(flask.session) except ApiResponseErrorList as api_response_error_list: return _handle_error_list(api_response_error_list.errors) except ApiError as api_error: return _handle_error(api_error) flask_user = flask.session["openid"] subscriptions = None # don't rely on marketo to show the page, # if anything fails, just continue and don't show # this section try: subscribed_to_newsletter = False marketo_user = marketo.get_user(flask_user["email"]) if marketo_user: marketo_subscribed = marketo.get_newsletter_subscription( marketo_user["id"] ) if marketo_subscribed.get("snapcraftnewsletter"): subscribed_to_newsletter = True subscriptions = {"newsletter": subscribed_to_newsletter} except Exception: if "sentry" in flask.current_app.extensions: flask.current_app.extensions["sentry"].captureException() context = { "image": flask_user["image"], "username": flask_user["nickname"], "displayname": flask_user["fullname"], "email": flask_user["email"], "subscriptions": subscriptions, } return flask.render_template("publisher/account-details.html", **context)
def get_account_details(): try: # We don't use the data from this endpoint. # It is mostly used to make sure the user has signed # the terms and conditions. api.get_account(flask.session) except ApiResponseErrorList as api_response_error_list: return _handle_error_list(api_response_error_list.errors) except ApiError as api_error: return _handle_errors(api_error) flask_user = flask.session["openid"] context = { "image": flask_user["image"], "username": flask_user["nickname"], "displayname": flask_user["fullname"], "email": flask_user["email"], } return flask.render_template("publisher/account-details.html", **context)
def get_account_details(): try: # We don't use the data from this endpoint. # It is mostly used to make sure the user has signed # the terms and conditions. api.get_account(flask.session) except ApiResponseErrorList as api_response_error_list: return _handle_error_list(api_response_error_list.errors) except ApiError as api_error: return _handle_errors(api_error) flask_user = flask.session['openid'] context = { 'image': flask_user['image'], 'username': flask_user['nickname'], 'displayname': flask_user['fullname'], 'email': flask_user['email'], } return flask.render_template('publisher/account-details.html', **context)
def snap_count(): try: account_info = api.get_account(flask.session) except ApiResponseErrorList as api_response_error_list: return _handle_error_list(api_response_error_list.errors) except ApiError as api_error: return _handle_error(api_error) user_snaps, registered_snaps = logic.get_snaps_account_info(account_info) context = {"count": len(user_snaps), "snaps": list(user_snaps.keys())} return flask.jsonify(context)
def snap_count(): try: account_info = api.get_account(flask.session) except ApiResponseErrorList as api_response_error_list: return _handle_error_list(api_response_error_list.errors) except ApiError as api_error: return _handle_errors(api_error) user_snaps, registered_snaps = logic.get_snaps_account_info(account_info) context = {"count": len(user_snaps), "snaps": list(user_snaps.keys())} return flask.jsonify(context)
def get_account_snaps(): try: account_info = api.get_account(flask.session) except ApiResponseErrorList as api_response_error_list: return _handle_error_list(api_response_error_list.errors) except ApiError as api_error: return _handle_error(api_error) user_snaps, registered_snaps = logic.get_snaps_account_info(account_info) flask_user = flask.session["openid"] context = { "snaps": user_snaps, "current_user": flask_user["nickname"], "registered_snaps": registered_snaps, } return flask.render_template("publisher/account-snaps.html", **context)
def get_account_snaps(): try: account_info = api.get_account(flask.session) except ApiResponseErrorList as api_response_error_list: return _handle_error_list(api_response_error_list.errors) except ApiError as api_error: return _handle_errors(api_error) user_snaps, registered_snaps = logic.get_snaps_account_info(account_info) flask_user = flask.session['openid'] context = { 'snaps': user_snaps, 'current_user': flask_user['nickname'], 'registered_snaps': registered_snaps, } return flask.render_template('publisher/account-snaps.html', **context)
def get_account_snaps(): try: account_info = api.get_account(flask.session) except ApiResponseErrorList as api_response_error_list: return _handle_error_list(api_response_error_list.errors) except ApiError as api_error: return _handle_errors(api_error) user_snaps, registered_snaps = logic.get_snaps_account_info(account_info) flask_user = flask.session["openid"] context = { "snaps": user_snaps, "current_user": flask_user["nickname"], "registered_snaps": registered_snaps, } return flask.render_template("publisher/account-snaps.html", **context)
def after_login(resp): flask.session['macaroon_discharge'] = resp.extensions['macaroon'].discharge try: account = dashboard.get_account(flask.session) flask.session['openid'] = { 'identity_url': resp.identity_url, 'nickname': account['username'], 'fullname': account['displayname'], 'image': resp.image, 'email': account['email'] } except Exception: flask.session['openid'] = { 'identity_url': resp.identity_url, 'nickname': resp.nickname, 'fullname': resp.fullname, 'image': resp.image, 'email': resp.email } return flask.redirect(open_id.get_next_url())
def post_register_name(): snap_name = flask.request.form.get("snap-name") if not snap_name: return flask.redirect(flask.url_for(".get_register_name")) is_private = flask.request.form.get("is_private") == "private" store = flask.request.form.get("store") registrant_comment = flask.request.form.get("registrant_comment") try: api.post_register_name( session=flask.session, snap_name=snap_name, is_private=is_private, store=store, registrant_comment=registrant_comment, ) except ApiResponseErrorList as api_response_error_list: try: user = api.get_account(flask.session) except ApiError as api_error: return _handle_error(api_error) available_stores = logic.filter_available_stores(user["stores"]) if api_response_error_list.status_code == 409: for error in api_response_error_list.errors: if error["code"] == "already_claimed": return flask.redirect( flask.url_for("account.get_account_details")) elif error["code"] == "already_registered": return flask.redirect( flask.url_for( ".get_register_name", snap_name=snap_name, is_private=is_private, store=store, conflict=True, )) elif error["code"] == "already_owned": return flask.redirect( flask.url_for( ".get_register_name", snap_name=snap_name, is_private=is_private, store=store, already_owned=True, )) elif error["code"] == "reserved_name": return flask.redirect( flask.url_for( ".get_register_name", snap_name=snap_name, is_private=is_private, store=store, reserved=True, )) context = { "snap_name": snap_name, "is_private": is_private, "available_stores": available_stores, "errors": api_response_error_list.errors, } return flask.render_template("publisher/register-snap.html", **context) except ApiError as api_error: return _handle_error(api_error) flask.flash("".join([ snap_name, " registered.", ' <a href="https://docs.snapcraft.io/build-snaps/upload"', ' class="p-link--external"', ' target="blank">How to upload a Snap</a>', ])) return flask.redirect(flask.url_for("account.get_account"))
def post_register_name(): snap_name = flask.request.form.get("snap-name") if not snap_name: return flask.redirect(flask.url_for(".get_register_name")) is_private = flask.request.form.get("is_private") == "private" store = flask.request.form.get("store") registrant_comment = flask.request.form.get("registrant_comment") try: api.post_register_name( session=flask.session, snap_name=snap_name, is_private=is_private, store=store, registrant_comment=registrant_comment, ) except ApiResponseErrorList as api_response_error_list: try: user = api.get_account(flask.session) except ApiError as api_error: return _handle_errors(api_error) available_stores = logic.filter_available_stores(user["stores"]) if api_response_error_list.status_code == 409: for error in api_response_error_list.errors: if error["code"] == "already_claimed": return flask.redirect( flask.url_for("account.get_account_details") ) elif error["code"] == "already_registered": return flask.redirect( flask.url_for( ".get_register_name", snap_name=snap_name, is_private=is_private, conflict=True, ) ) elif error["code"] == "already_owned": return flask.redirect( flask.url_for( ".get_register_name", snap_name=snap_name, is_private=is_private, already_owned=True, ) ) context = { "snap_name": snap_name, "is_private": is_private, "available_stores": available_stores, "errors": api_response_error_list.errors, } return flask.render_template("publisher/register-snap.html", **context) except ApiError as api_error: return _handle_errors(api_error) flask.flash( "".join( [ snap_name, " registered.", ' <a href="https://docs.snapcraft.io/build-snaps/upload"', ' class="p-link--external"', ' target="blank">How to upload a Snap</a>', ] ) ) return flask.redirect(flask.url_for("account.get_account"))