diff --git a/app/blueprints/github/__init__.py b/app/blueprints/github/__init__.py index 0867273..c2d9901 100644 --- a/app/blueprints/github/__init__.py +++ b/app/blueprints/github/__init__.py @@ -71,7 +71,7 @@ def callback(oauth_token): else: if userByGithub is None: flash("Unable to find an account for that Github user", "danger") - return redirect(url_for("users.claim")) + return redirect(url_for("users.claim_forums")) elif login_user_set_active(userByGithub, remember=True): addAuditLog(AuditSeverity.USER, userByGithub, "Logged in using GitHub OAuth", url_for("users.profile", username=userByGithub.username)) diff --git a/app/blueprints/users/account.py b/app/blueprints/users/account.py index 4da4504..3e4473e 100644 --- a/app/blueprints/users/account.py +++ b/app/blueprints/users/account.py @@ -111,7 +111,7 @@ def handle_register(form): if user_by_name: if user_by_name.rank == UserRank.NOT_JOINED and user_by_name.forums_username: flash("An account already exists for that username but hasn't been claimed yet.", "danger") - return redirect(url_for("users.claim", username=user_by_name.forums_username)) + return redirect(url_for("users.claim_forums", username=user_by_name.forums_username)) else: flash("That username is already in use, please choose another.", "danger") return diff --git a/app/blueprints/users/claim.py b/app/blueprints/users/claim.py index 1512d41..414d918 100644 --- a/app/blueprints/users/claim.py +++ b/app/blueprints/users/claim.py @@ -27,8 +27,14 @@ def check_username(username): return username is not None and len(username) >= 2 and re.match("^[A-Za-z0-9._-]*$", username) + @bp.route("/user/claim/", methods=["GET", "POST"]) def claim(): + return render_template("users/claim.html") + + +@bp.route("/user/claim-forums/", methods=["GET", "POST"]) +def claim_forums(): username = request.args.get("username") if username is None: username = "" @@ -37,26 +43,23 @@ def claim(): if not check_username(username): flash("Invalid username - must only contain A-Za-z0-9._. Consider contacting an admin", "danger") - return redirect(url_for("users.claim")) + return redirect(url_for("users.claim_forums")) user = User.query.filter_by(forums_username=username).first() if user and user.rank.atLeast(UserRank.NEW_MEMBER): flash("User has already been claimed", "danger") - return redirect(url_for("users.claim")) + return redirect(url_for("users.claim_forums")) elif method == "github": if user is None or user.github_username is None: - flash("Unable to get Github username for user", "danger") - return redirect(url_for("users.claim", username=username)) + flash("Unable to get GitHub username for user", "danger") + return redirect(url_for("users.claim_forums", username=username)) else: return redirect(url_for("github.start")) - elif user is None and request.method == "POST": - flash("Unable to find user", "danger") - return redirect(url_for("users.claim")) if "forum_token" in session: token = session["forum_token"] else: - token = randomString(32) + token = randomString(12) session["forum_token"] = token if request.method == "POST": @@ -67,12 +70,12 @@ def claim(): flash("Invalid username - must only contain A-Za-z0-9._. Consider contacting an admin", "danger") elif ctype == "github": task = checkForumAccount.delay(username) - return redirect(url_for("tasks.check", id=task.id, r=url_for("users.claim", username=username, method="github"))) + return redirect(url_for("tasks.check", id=task.id, r=url_for("users.claim_forums", username=username, method="github"))) elif ctype == "forum": user = User.query.filter_by(forums_username=username).first() if user is not None and user.rank.atLeast(UserRank.NEW_MEMBER): flash("That user has already been claimed!", "danger") - return redirect(url_for("users.claim")) + return redirect(url_for("users.claim_forums")) # Get signature sig = None @@ -86,11 +89,11 @@ def claim(): message = str(e) flash("Error whilst attempting to access forums: " + message, "danger") - return redirect(url_for("users.claim", username=username)) + return redirect(url_for("users.claim_forums", username=username)) if profile is None: flash("Unable to get forum signature - does the user exist?", "danger") - return redirect(url_for("users.claim", username=username)) + return redirect(url_for("users.claim_forums", username=username)) # Look for key if sig and token in sig: @@ -106,12 +109,12 @@ def claim(): return redirect(url_for("users.set_password")) else: flash("Unable to login as user", "danger") - return redirect(url_for("users.claim", username=username)) + return redirect(url_for("users.claim_forums", username=username)) else: flash("Could not find the key in your signature!", "danger") - return redirect(url_for("users.claim", username=username)) + return redirect(url_for("users.claim_forums", username=username)) else: flash("Unknown claim type", "danger") - return render_template("users/claim.html", username=username, key="cdb_" + token) + return render_template("users/claim_forums.html", username=username, key="cdb_" + token) diff --git a/app/tasks/phpbbparser.py b/app/tasks/phpbbparser.py index 8da594a..4e84733 100644 --- a/app/tasks/phpbbparser.py +++ b/app/tasks/phpbbparser.py @@ -91,12 +91,13 @@ def getProfileURL(url, username): def getProfile(url, username): url = getProfileURL(url, username) - req = urllib.request.urlopen(url, timeout=5) - if req.getcode() == 404: - return None + try: + req = urllib.request.urlopen(url, timeout=5) + except urllib.error.HTTPError as e: + if e.code == 404: + return None - if req.getcode() != 200: - raise IOError(req.getcode()) + raise IOError(e) contents = req.read().decode("utf-8") soup = BeautifulSoup(contents, "lxml") diff --git a/app/templates/users/claim.html b/app/templates/users/claim.html index 30bcb09..5e696d5 100644 --- a/app/templates/users/claim.html +++ b/app/templates/users/claim.html @@ -1,135 +1,26 @@ {% extends "base.html" %} {% block title %} -Creating an Account +{{ _("Create Account") }} {% endblock %} {% block content %} -
- If you have a forum account, you'll need to prove that you own it - to get an account on ContentDB. -
+- Please log out to continue. -
-- Logout -
- {% else %} -- Don't have a forum account? - You don't need one, however it's recommended to make the most - out of the Minetest community. -
++ ContentDB will link your account to your forum account. +
- - Create a Forum Account - - {% endif %} -+ You don't need a forum account, however, it's recommended to make the most + out of the Minetest community. +
- {% if not current_user.is_authenticated %} -- Only do this if you don't have a forum account! -
-- If you have a forum account, please use one of the other two - options. -
- - Register -+ Yes, I have a forums account + No, I don't have one + Create forum account +
{% endblock %} diff --git a/app/templates/users/claim_forums.html b/app/templates/users/claim_forums.html new file mode 100644 index 0000000..9e02ac0 --- /dev/null +++ b/app/templates/users/claim_forums.html @@ -0,0 +1,113 @@ +{% extends "base.html" %} + +{% block title %} +Create Account from Forums User +{% endblock %} + +{% block content %} +
+ You'll need to use prove that you have access to your forum account using one of the options below.
+ This is so ContentDB can link your account to your forum account.
+
+ Don't have a forums account? + You can still sign up without one. +
+ +#} +{# If you have a forum account, please use one of the other two#} +{# options.#} +{#
#} +{##} +{# Register#} +{#