aboutsummaryrefslogtreecommitdiff
path: root/app/blueprints
diff options
context:
space:
mode:
authorrubenwardy <rw@rubenwardy.com>2020-04-14 14:39:49 +0100
committerrubenwardy <rw@rubenwardy.com>2020-04-14 14:39:59 +0100
commitdadfe72b480f05d6d31aaf575afaa34e53c450ab (patch)
tree7c7d890e9935ee6d1271380ce17dac9c4ae9f8c0 /app/blueprints
parent9cc3eba0099c46cb0818e5beb06f855441814b0c (diff)
downloadcheatdb-dadfe72b480f05d6d31aaf575afaa34e53c450ab.tar.xz
Improve user authentication error handling
Diffstat (limited to 'app/blueprints')
-rw-r--r--app/blueprints/users/claim.py28
-rw-r--r--app/blueprints/users/profile.py4
2 files changed, 21 insertions, 11 deletions
diff --git a/app/blueprints/users/claim.py b/app/blueprints/users/claim.py
index 7c6283d..4e0f1ec 100644
--- a/app/blueprints/users/claim.py
+++ b/app/blueprints/users/claim.py
@@ -34,15 +34,16 @@ def claim():
if user and user.rank.atLeast(UserRank.NEW_MEMBER):
flash("User has already been claimed", "danger")
return redirect(url_for("users.claim"))
- elif user is None and method == "github":
- flash("Unable to get Github username for user", "danger")
- return redirect(url_for("users.claim"))
- elif user is None:
- flash("Unable to find that user", "danger")
+ 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"))
+ 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 user is not None and method == "github":
- return redirect(url_for("github.start"))
token = None
if "forum_token" in session:
@@ -70,8 +71,17 @@ def claim():
sig = None
try:
profile = getProfile("https://forum.minetest.net", username)
- sig = profile.signature
- except IOError:
+ sig = profile.signature if profile else None
+ except IOError as e:
+ if hasattr(e, 'message'):
+ message = e.message
+ else:
+ message = str(e)
+
+ flash("Error whilst attempting to access forums: " + message, "danger")
+ return redirect(url_for("users.claim", 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))
diff --git a/app/blueprints/users/profile.py b/app/blueprints/users/profile.py
index 177eefe..f3c697d 100644
--- a/app/blueprints/users/profile.py
+++ b/app/blueprints/users/profile.py
@@ -16,7 +16,7 @@
from flask import *
-from flask_user import *
+from flask_user import signals, current_user, user_manager
from flask_login import login_user, logout_user
from app.markdown import render_markdown
from . import bp
@@ -192,7 +192,7 @@ def set_password():
# Send 'password_changed' email
if user_manager.USER_ENABLE_EMAIL and current_user.email:
- emails.send_password_changed_email(current_user)
+ user_manager.email_manager.send_password_changed_email(current_user)
# Send password_changed signal
signals.user_changed_password.send(current_app._get_current_object(), user=current_user)