From 60362abef1dd4eb45fbee93751f55aa72afd39ce Mon Sep 17 00:00:00 2001
From: rubenwardy
Date: Tue, 22 Dec 2020 10:58:43 +0000
Subject: [PATCH] Improve claim user UX
---
app/blueprints/github/__init__.py | 2 +-
app/blueprints/users/account.py | 2 +-
app/blueprints/users/claim.py | 33 +++--
app/tasks/phpbbparser.py | 11 +-
app/templates/users/claim.html | 139 ++-----------------
app/templates/users/claim_forums.html | 113 +++++++++++++++
app/templates/users/forums_no_such_user.html | 2 +-
app/templates/users/profile.html | 2 +-
8 files changed, 156 insertions(+), 148 deletions(-)
create mode 100644 app/templates/users/claim_forums.html
diff --git a/app/blueprints/github/__init__.py b/app/blueprints/github/__init__.py
index 0867273a..c2d99015 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 4da45043..3e4473e0 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 1512d415..414d918a 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 8da594a5..4e847339 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 30bcb099..5e696d55 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 %}
-
-
+
{{ self.title() }}
-
-
- If you have a forum account, you'll need to prove that you own it
- to get an account on ContentDB.
-
+
{{ _("Do you have an account on the Minetest Forums?") }}
- {% if current_user.is_authenticated %}
-
- 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
-
-
-
-
- {% endif %}
+
+ 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 00000000..9e02ac05
--- /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 %}
+ {{ self.title() }}
+
+ {{ _("Confirm Your Account") }}
+
+
+ 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#}
+{#
#}
+{#
#}
+{#
#}
+
+{% endblock %}
diff --git a/app/templates/users/forums_no_such_user.html b/app/templates/users/forums_no_such_user.html
index 0241461b..8f98b2b7 100644
--- a/app/templates/users/forums_no_such_user.html
+++ b/app/templates/users/forums_no_such_user.html
@@ -15,7 +15,7 @@
{% if not current_user.is_authenticated %}
- Claim Account
+ Claim Account
{% endif %}
{% endblock %}
diff --git a/app/templates/users/profile.html b/app/templates/users/profile.html
index d420a4b6..3c13ac47 100644
--- a/app/templates/users/profile.html
+++ b/app/templates/users/profile.html
@@ -104,7 +104,7 @@
{% if not current_user.is_authenticated and user.rank == user.rank.NOT_JOINED and user.forums_username %}
Claim
+ href="{{ url_for('users.claim_forums', username=user.forums_username) }}">Claim
Is this you? Claim your account now!