Improve claim user UX

This commit is contained in:
rubenwardy 2020-12-22 10:58:43 +00:00
parent d7d9131de8
commit 60362abef1
8 changed files with 156 additions and 148 deletions

View File

@ -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))

View File

@ -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

View File

@ -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)

View File

@ -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")

View File

@ -1,135 +1,26 @@
{% extends "base.html" %}
{% block title %}
Creating an Account
{{ _("Create Account") }}
{% endblock %}
{% block content %}
<div class="card">
<h2 class="card-header">{{ self.title() }}</h2>
<h1>{{ self.title() }}</h1>
<div class="card-body">
<p>
If you have a forum account, you'll need to prove that you own it
to get an account on ContentDB.
</p>
<h2>{{ _("Do you have an account on the Minetest Forums?") }}</h2>
{% if current_user.is_authenticated %}
<p>
Please log out to continue.
</p>
<p>
<a href="{{ url_for('users.logout', next=url_for('users.claim')) }}" class="btn">Logout</a>
</p>
{% else %}
<p>
<b>Don't have a forum account?</b>
You don't need one, however it's recommended to make the most
out of the Minetest community.
</p>
<p>
ContentDB will link your account to your forum account.
</p>
<a class="btn btn-primary" href="https://forum.minetest.net/ucp.php?mode=register">
Create a Forum Account
</a>
{% endif %}
</div>
</div>
<p>
You don't need a forum account, however, it's recommended to make the most
out of the Minetest community.
</p>
{% if not current_user.is_authenticated %}
<div class="row mt-4">
<div class="col-sm-4">
<div class="card">
<div class="card-header">
<span class="badge badge-pill badge-dark mr-2">Option 1</span>
Use GitHub field in forum profile
</div>
<form method="post" class="card-body" action="{{ url_for('users.claim') }}">
<input class="form-control" type="hidden" name="claim_type" value="github">
<input class="form-control" type="hidden" name="csrf_token" value="{{ csrf_token() }}" />
<p>
Enter your forum username here:
</p>
<input class="form-control my-4" type="text" name="username" value="{{ username }}"
placeholder="Forum username" pattern="[a-zA-Z0-9._ -]+" title="Only a-zA-Z0-9._ allowed" required>
<p>
You'll need to have the GitHub field in your forum profile
filled out. Log into the forum and
<a href="https://forum.minetest.net/ucp.php?i=173">
do that here</a>.
</p>
<input class="btn btn-primary" type="submit" value="Next: log in with GitHub">
</form>
</div>
</div>
<div class="col-sm-4">
<div class="card">
<div class="card-header">
<span class="badge badge-pill badge-dark mr-2">Option 2</span>
Verification token
</div>
<form method="post" class="card-body" action="{{ url_for('users.claim') }}">
<input type="hidden" name="claim_type" value="forum">
<input type="hidden" name="csrf_token" value="{{ csrf_token() }}" />
<p>
Enter your forum username here:
</p>
<input class="form-control my-3" type="text" name="username" value="{{ username }}"
placeholder="Forum username" pattern="[a-zA-Z0-9._ -]+" title="Only a-zA-Z0-9._ allowed" required>
<p>
Go to
<a href="https://forum.minetest.net/ucp.php?i=profile&mode=signature">
User Control Panel > Profile > Edit signature
</a>
</p>
<p>
Paste this into your signature:
</p>
<input class="form-control my-3" type="text" value="{{ key }}" readonly size=32>
<p>
Click next so we can check it.
</p>
<p>
Don't worry, you can remove it after this is done.
</p>
<input class="btn btn-primary" type="submit" value="Next">
</form>
</div>
</div>
<div class="col-sm-4">
<div class="card">
<div class="card-header">
<span class="badge badge-pill badge-dark mr-2">Option 3</span>
Email/password sign up
</div>
<div class="card-body">
<p class="alert alert-danger">
<b>Only do this if you don't have a forum account!</b>
</p>
<p>
If you have a forum account, please use one of the other two
options.
</p>
<a class="btn btn-primary" href="{{ url_for('users.register') }}">Register</a>
</div>
</div>
</div>
</div>
{% endif %}
<p class="mt-5">
<a class="btn btn-primary mr-3" href="{{ url_for('users.claim_forums') }}"><b>Yes</b>, I have a forums account</a>
<a class="btn btn-primary mr-3" href="{{ url_for('users.register') }}"><b>No</b>, I don't have one</a>
<a class="btn btn-secondary" href="https://forum.minetest.net/ucp.php?mode=register">Create forum account</a>
</p>
{% endblock %}

View File

@ -0,0 +1,113 @@
{% extends "base.html" %}
{% block title %}
Create Account from Forums User
{% endblock %}
{% block content %}
<h1>{{ self.title() }}</h1>
<h2>{{ _("Confirm Your Account") }}</h2>
<p>
You'll need to use prove that you have access to your forum account using one of the options below.<br>
This is so ContentDB can link your account to your forum account.
</p>
<p>
Don't have a forums account?
You can still <a href="{{ url_for('users.register') }}">sign up without one</a>.
</p>
<div class="row mt-5">
<div class="col-sm-6">
<div class="card">
<div class="card-header">
<span class="badge badge-pill badge-dark mr-2">Option 1</span>
Use GitHub field in forum profile
</div>
<form method="post" class="card-body" action="">
<input class="form-control" type="hidden" name="claim_type" value="github">
<input class="form-control" type="hidden" name="csrf_token" value="{{ csrf_token() }}" />
<p>
Enter your forum username here:
</p>
<input class="form-control my-4" type="text" name="username" value="{{ username }}"
placeholder="Forum username" pattern="[a-zA-Z0-9._ -]+" title="Only a-zA-Z0-9._ allowed" required>
<p>
You'll need to have the GitHub field in your forum profile
filled out. Log into the forum and
<a href="https://forum.minetest.net/ucp.php?i=173">
do that here</a>.
</p>
<input class="btn btn-primary" type="submit" value="Next: log in with GitHub">
</form>
</div>
</div>
<div class="col-sm-6">
<div class="card">
<div class="card-header">
<span class="badge badge-pill badge-dark mr-2">Option 2</span>
Verification token
</div>
<form method="post" class="card-body" action="">
<input type="hidden" name="claim_type" value="forum">
<input type="hidden" name="csrf_token" value="{{ csrf_token() }}" />
<p>
Enter your forum username here:
</p>
<input class="form-control my-3" type="text" name="username" value="{{ username }}"
placeholder="Forum username" pattern="[a-zA-Z0-9._ -]+" title="Only a-zA-Z0-9._ allowed" required>
<p>
Go to
<a href="https://forum.minetest.net/ucp.php?i=profile&mode=signature">
User Control Panel > Profile > Edit signature
</a>
</p>
<p>
Paste this into your signature:
</p>
<input class="form-control my-3" type="text" value="{{ key }}" readonly size=32>
<p>
Click next so we can check it.
</p>
<p>
Don't worry, you can remove it after this is done.
</p>
<input class="btn btn-primary" type="submit" value="Next">
</form>
</div>
</div>
{# <div class="col-sm-4">#}
{# <div class="card">#}
{# <div class="card-header">#}
{# Email/password sign up#}
{# </div>#}
{##}
{# <div class="card-body">#}
{# <p>#}
{# If you have a forum account, please use one of the other two#}
{# options.#}
{# </p>#}
{##}
{# <a class="btn btn-primary" href="{{ url_for('users.register') }}">Register</a>#}
{# </div>#}
{# </div>#}
{# </div>#}
</div>
{% endblock %}

View File

@ -15,7 +15,7 @@
</p>
{% if not current_user.is_authenticated %}
<a class="btn btn-primary" href="{{ url_for('users.claim', username=username) }}">Claim Account</a>
<a class="btn btn-primary" href="{{ url_for('users.claim_forums', username=username) }}">Claim Account</a>
{% endif %}
</article>
{% endblock %}

View File

@ -104,7 +104,7 @@
{% if not current_user.is_authenticated and user.rank == user.rank.NOT_JOINED and user.forums_username %}
<div class="alert alert-secondary mb-5">
<a class="float-right btn btn-default btn-sm"
href="{{ url_for('users.claim', username=user.forums_username) }}">Claim</a>
href="{{ url_for('users.claim_forums', username=user.forums_username) }}">Claim</a>
Is this you? Claim your account now!
</div>