<commit_before>from flask import session, redirect, url_for
from flask.json import jsonify
from api import app, oauth
from api import models


@app.route("/api/v2/login")
def _get_api_v2_login():
    redirect_uri = url_for("_get_api_v2_redirect", _external=True)
    return oauth.google.authorize_redirect(redirect_uri)


@app.route("/api/v2/redirect")
def _get_api_v2_redirect():
    token = oauth.google.authorize_access_token()
    user = oauth.google.parse_id_token(token)
    session["user"] = user
    return redirect("/api/v2/whoami")


@app.route("/api/v2/logout")
def _get_api_v2_logout():
    session.pop("user", None)
    return redirect("/")


@app.route("/api/v2/whoami")
def _get_api_v2_whoami():
    try:
        return jsonify(
            {
                "google": session["user"],
                "officer": models.Officer.is_officer(
                    session["user"]["email"].split("@")[0]
                ),
                "primary": models.Officer.is_primary(
                    session["user"]["email"].split("@")[0]
                ),
                "rit_student": session["user"]["email"].split("@")[1] == "g.rit.edu",
            }
        )
    except:
        return jsonify({"error": "not logged in"})
<commit_msg>fix primary officer check in whoami<commit_after>from flask import session, redirect, url_for
from flask.json import jsonify
from api import app, oauth
from api import models


@app.route("/api/v2/login")
def _get_api_v2_login():
    redirect_uri = url_for("_get_api_v2_redirect", _external=True)
    return oauth.google.authorize_redirect(redirect_uri)


@app.route("/api/v2/redirect")
def _get_api_v2_redirect():
    token = oauth.google.authorize_access_token()
    user = oauth.google.parse_id_token(token)
    session["user"] = user
    return redirect("/api/v2/whoami")


@app.route("/api/v2/logout")
def _get_api_v2_logout():
    session.pop("user", None)
    return redirect("/")


@app.route("/api/v2/whoami")
def _get_api_v2_whoami():
    try:
        return jsonify(
            {
                "google": session["user"],
                "officer": models.Officer.is_officer(
                    session["user"]["email"].split("@")[0]
                ),
                "primary": models.Officer.is_primary_officer(
                    session["user"]["email"].split("@")[0]
                ),
                "rit_student": session["user"]["email"].split("@")[1] == "g.<EMAIL>",
            }
        )
    except:
        return jsonify({"error": "not logged in"})

{'fraction_non_alphanumeric': 0.15533596837944663, 'fraction_numerical': 0.010276679841897233, 'mean_word_length': 2.620886981402003, 'pattern_counts': {'":': 10, '<': 4, '<?xml version=': 0, '>': 4, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2595501', 'n_tokens_mistral': 839, 'n_tokens_neox': 820, 'n_words': 141}