How to use the pypistats.models.user.User function in pypistats

To help you get started, we’ve selected a few pypistats examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github crflynn / pypistats.org / pypistats / views / user.py View on Github external
if user is None:
        user = User(token=oauth_token)

    # Set this to use API to get user data
    g.user = user
    user_data = github.get("user")

    # extract data
    uid = user_data["id"]
    username = user_data["login"]
    avatar_url = user_data["avatar_url"]

    # Create/update the user
    user = User.query.filter_by(uid=uid).first()
    if user is None:
        user = User(
            token=oauth_token,
            uid=uid,
            username=username,
            avatar_url=avatar_url,
        )
    else:
        user.username = username
        user.avatar_url = avatar_url
        user.token = oauth_token

    user.save()

    session["username"] = user.username
    session["user_id"] = user.id
    g.user = user
github crflynn / pypistats.org / pypistats / views / user.py View on Github external
# Ensure a user with token doesn't already exist
    user = User.query.filter_by(token=oauth_token).first()
    if user is None:
        user = User(token=oauth_token)

    # Set this to use API to get user data
    g.user = user
    user_data = github.get("user")

    # extract data
    uid = user_data["id"]
    username = user_data["login"]
    avatar_url = user_data["avatar_url"]

    # Create/update the user
    user = User.query.filter_by(uid=uid).first()
    if user is None:
        user = User(
            token=oauth_token,
            uid=uid,
            username=username,
            avatar_url=avatar_url,
        )
    else:
        user.username = username
        user.avatar_url = avatar_url
        user.token = oauth_token

    user.save()

    session["username"] = user.username
    session["user_id"] = user.id
github crflynn / pypistats.org / pypistats / views / user.py View on Github external
def authorized(oauth_token):
    """Github authorization callback."""
    next_url = request.args.get("next") or url_for("user.user")
    if oauth_token is None:
        flash("Authorization failed.")
        return redirect(next_url)

    # Ensure a user with token doesn't already exist
    user = User.query.filter_by(token=oauth_token).first()
    if user is None:
        user = User(token=oauth_token)

    # Set this to use API to get user data
    g.user = user
    user_data = github.get("user")

    # extract data
    uid = user_data["id"]
    username = user_data["login"]
    avatar_url = user_data["avatar_url"]

    # Create/update the user
    user = User.query.filter_by(uid=uid).first()
    if user is None:
        user = User(
            token=oauth_token,
            uid=uid,
github crflynn / pypistats.org / pypistats / views / user.py View on Github external
def authorized(oauth_token):
    """Github authorization callback."""
    next_url = request.args.get("next") or url_for("user.user")
    if oauth_token is None:
        flash("Authorization failed.")
        return redirect(next_url)

    # Ensure a user with token doesn't already exist
    user = User.query.filter_by(token=oauth_token).first()
    if user is None:
        user = User(token=oauth_token)

    # Set this to use API to get user data
    g.user = user
    user_data = github.get("user")

    # extract data
    uid = user_data["id"]
    username = user_data["login"]
    avatar_url = user_data["avatar_url"]

    # Create/update the user
    user = User.query.filter_by(uid=uid).first()
    if user is None:
        user = User(
github crflynn / pypistats.org / pypistats / run.py View on Github external
def before_request():
    """Execute before requests."""
    g.user = None
    if "user_id" in session:
        g.user = User.query.get(session["user_id"])
    if "db" not in g:
        g.db = db