Example #1
0
def oauth_continue():
    if "code" not in request.args or "state" not in request.args:
        return redirect(url_for("onboarding.log_in"))
    code, state = request.args["code"], request.args["state"]
    try:
        try:
            token = authentication_provider_get_token(code, state)
            github = get_username_from_token(token)
        except AuthenticationIntegrityError:
            raise ValidationError("OAuth session expired. Please try again.")
        except AuthenticationTemporaryError:
            logging.exception("Something odd occurred with GitHub OAuth")
            raise ValidationError("GitHub temporary OAuth issue. Please try again.")
    except ValidationError as e:
        return redirect_with_error(url_for("onboarding.log_in"), e)
    authenticate_as_github_username(github)

    # Route the user to the correct onboarding step.
    # OR, if they've finished onboarding, take them to the dashboard.
    # _get_current_step() will perform student dashboard authentication if onboarding is complete.
    current_step = _get_current_step()
    if current_step == "ta.index" and "login_next__ta" in session:
        return redirect(session.pop("login_next__ta"))
    elif current_step == "dashboard.index" and "login_next__dashboard" in session:
        return redirect(session.pop("login_next__dashboard"))
    else:
        return redirect(url_for(current_step))
Example #2
0
def oauth_continue():
    if "code" not in request.args or "state" not in request.args:
        return redirect(url_for("onboarding.log_in"))
    code, state = request.args["code"], request.args["state"]
    try:
        try:
            token = authentication_provider_get_token(code, state)
            github = get_username_from_token(token)
        except AuthenticationIntegrityError:
            raise ValidationError("OAuth session expired. Please try again.")
        except AuthenticationTemporaryError:
            logging.exception("Something odd occurred with GitHub OAuth")
            raise ValidationError(
                "GitHub temporary OAuth issue. Please try again.")
    except ValidationError as e:
        return redirect_with_error(url_for("onboarding.log_in"), e)
    authenticate_as_github_username(github)

    # Route the user to the correct onboarding step.
    # OR, if they've finished onboarding, take them to the dashboard.
    # _get_current_step() will perform student dashboard authentication if onboarding is complete.
    current_step = _get_current_step()
    if current_step == "ta.index" and "login_next__ta" in session:
        return redirect(session.pop("login_next__ta"))
    elif current_step == "dashboard.index" and "login_next__dashboard" in session:
        return redirect(session.pop("login_next__dashboard"))
    else:
        return redirect(url_for(current_step))
Example #3
0
def log_out():
    if request.method == "POST":
        authenticate_as_user(None)
        authenticate_as_github_username(None)
        return redirect(url_for("onboarding.log_in"))
    elif github_username() or user_id():
        return render_template("onboarding/log_out.html")
    else:
        return redirect(url_for("onboarding.log_in"))
Example #4
0
def log_out():
    if request.method == "POST":
        authenticate_as_user(None)
        authenticate_as_github_username(None)
        return redirect(url_for("onboarding.log_in"))
    elif github_username() or user_id():
        return render_template("onboarding/log_out.html")
    else:
        return redirect(url_for("onboarding.log_in"))