def github_auth(): session_code = request.args["code"] access_token = get_access_token(session_code) auth_data = get_auth_data(access_token) if auth_data["login"] is None: flash("Authentication failed") return redirect(url_for("home.index")) user = User.query.filter_by(username=auth_data["login"]).first() if not user: user = User(username=auth_data["login"], email=auth_data["email"]) user.account_type = UserType.USER user.avatar_url = auth_data["avatar_url"] user.html_url = auth_data["html_url"] db.session.add(user) db.session.commit() login_user(user, True) flash("Authentication succesful") return redirect(url_for("home.index"))