def index(): from .badge_blueprint import badge_description_to_json kwargs = { "circles": [circle_to_json(c) for c in Circle.query.all()], "badge_descriptions": [badge_description_to_json(bd) for bd in BadgeDescription.query.all()], "stripe_pubkey": stripe_pubkey, "gitRevision": current_app.config.get("GIT_REVISION", None) } if flask_login.current_user.is_authenticated: account = flask_login.current_user.account # type: Account circles = account_management.get_circles_for_account(account.id) badges = badge_management.badges_for_account(account.id) circles_with_admin_access = account_management.get_circles_with_admin_access( account.id) account_json = profile_to_json(account, circles, badges, full=True) circles_with_admin_access_json = [ circle_to_json(c) for c in circles_with_admin_access ] kwargs["profile"] = account_json kwargs["circles_with_admin_access"] = [ c.id for c in circles_with_admin_access ] return render_template("index.html", **kwargs)
def data_account_summary(account_id): account = Account.find_account_by_id(account_id) if account is None: abort(404) badges = badge_management.badges_for_account(account.id) open_door_event = event_management.last_door_open(account) # Add to response from .badge_blueprint import badge_to_json summary = { "account": account_to_json(account), "badges": [badge_to_json(b) for b in badges], "lastDoorOpen": open_door_event.to_dict() if open_door_event else None, } # Add information about membership if current user is in a circle admin_circle = Circle.get_by_name('insight-fee') if account_management.is_account_in_circle( flask_login.current_user.account, admin_circle): membership = get_membership(account) membership_details = {} if membership is not None: membership_details['fee'] = membership.fee membership_details[ 'first_membership'] = membership.first_membership membership_details[ 'start_membership'] = membership.start_membership else: membership_details['fee'] = 0 summary['membership'] = membership_details return jsonify(summary)
def index(): if flask_login.current_user.is_authenticated: account = flask_login.current_user.account circles = account_management.get_circles_for_account(account.id) badges = badge_management.badges_for_account(account.id) account = account_to_json(account, circles, badges) else: account = None return render_template("index.html", account=account)
def data_account_list(): accounts_plus_plus = [ (account, account_management.get_circles_for_account(account.id), badge_management.badges_for_account(account.id)) for account in Account.query.all() ] accounts = [ account_to_json(account, circles, badges) for (account, circles, badges) in accounts_plus_plus ] return jsonify(accounts)
def data_account_summary(account_id): account = Account.find_account_by_id(account_id) if account is None: abort(404) circles = account_management.get_circles_for_account(account.id) badges = badge_management.badges_for_account(account.id) open_door_event = event_management.last_door_open(account) from .badge_blueprint import badge_to_json summary = { "account": account_to_json(account, circles, None), "badges": [badge_to_json(b) for b in badges], "lastDoorOpen": open_door_event.to_dict() if open_door_event else None } return jsonify(summary)
def service_authz_login(): username = request.json["username"] account = Account.find_account_by_username(username) password = request.json["password"] if not account: logger.info("Login: Bad login attempt, no such user: {}".format(username)) raise P2k16UserException("Invalid credentials") if not account.valid_password(password): logger.info("Login: Bad login attempt, wrong password: {}".format(username)) raise P2k16UserException("Invalid credentials") circles = account_management.get_circles_for_account(account.id) badges = badge_management.badges_for_account(account.id) logger.info("Login: username={}, circles={}".format(username, circles)) authenticated_account = auth.AuthenticatedAccount(account, circles) flask_login.login_user(authenticated_account) return jsonify(account_to_json(account, circles, badges))
def _manage_membership(account_id: int, create: bool): account = Account.find_account_by_id(account_id) if account is None: abort(404) circle_id = request.json["circle_id"] a = flask_login.current_user.account if create: account_management.add_account_to_circle(account.id, circle_id, a.id) else: account_management.remove_account_from_circle(account.id, circle_id, a.id) circles = account_management.get_circles_for_account(account.id) badges = badge_management.badges_for_account(account.id) db.session.commit() return jsonify(account_to_json(account, circles, badges))
def create(): account = flask_login.current_user.account # type: Account title = request.json["title"] recipient_username = request.json.get("recipient", None) if recipient_username: recipient = Account.find_account_by_username(recipient_username) if not recipient: raise P2k16UserException( "No such username: {}".format(recipient_username)) else: recipient = account badge_management.create_badge(recipient, account, title) circles = account_management.get_circles_for_account(account.id) badges = badge_management.badges_for_account(account.id) db.session.commit() return jsonify(account_to_json(account, circles, badges))