mirror of
https://github.com/minetest/contentdb.git
synced 2024-12-22 14:02:24 +01:00
Improve claim_forums error messages
This commit is contained in:
parent
71e68a6056
commit
4147e5edc7
@ -15,11 +15,12 @@
|
|||||||
# along with this program. If not, see <https://www.gnu.org/licenses/>.
|
# along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
from flask_babel import gettext
|
from flask_babel import gettext
|
||||||
|
from flask_login import current_user
|
||||||
|
|
||||||
from . import bp
|
from . import bp
|
||||||
from flask import redirect, render_template, session, request, flash, url_for
|
from flask import redirect, render_template, session, request, flash, url_for
|
||||||
from app.models import db, User, UserRank
|
from app.models import db, User, UserRank
|
||||||
from app.utils import random_string, login_user_set_active, is_username_valid
|
from app.utils import random_string, login_user_set_active
|
||||||
from app.tasks.forumtasks import check_forum_account
|
from app.tasks.forumtasks import check_forum_account
|
||||||
from app.utils.phpbbparser import get_profile
|
from app.utils.phpbbparser import get_profile
|
||||||
|
|
||||||
@ -31,23 +32,22 @@ def claim():
|
|||||||
|
|
||||||
@bp.route("/user/claim-forums/", methods=["GET", "POST"])
|
@bp.route("/user/claim-forums/", methods=["GET", "POST"])
|
||||||
def claim_forums():
|
def claim_forums():
|
||||||
|
if current_user.is_authenticated:
|
||||||
|
return redirect(url_for("homepage.home"))
|
||||||
|
|
||||||
username = request.args.get("username")
|
username = request.args.get("username")
|
||||||
if username is None:
|
if username is None:
|
||||||
username = ""
|
username = ""
|
||||||
else:
|
else:
|
||||||
method = request.args.get("method")
|
method = request.args.get("method")
|
||||||
|
|
||||||
if not is_username_valid(username):
|
|
||||||
flash(gettext("Invalid username, Only alphabetic letters (A-Za-z), numbers (0-9), underscores (_), minuses (-), and periods (.) allowed. Consider contacting an admin"), "danger")
|
|
||||||
return redirect(url_for("users.claim_forums"))
|
|
||||||
|
|
||||||
user = User.query.filter_by(forums_username=username).first()
|
user = User.query.filter_by(forums_username=username).first()
|
||||||
if user and user.rank.at_least(UserRank.NEW_MEMBER):
|
if user and user.rank.at_least(UserRank.NEW_MEMBER):
|
||||||
flash(gettext("User has already been claimed"), "danger")
|
flash(gettext("User has already been claimed"), "danger")
|
||||||
return redirect(url_for("users.claim_forums"))
|
return redirect(url_for("users.claim_forums"))
|
||||||
elif method == "github":
|
elif method == "github":
|
||||||
if user is None or user.github_username is None:
|
if user is None or user.github_username is None:
|
||||||
flash(gettext("Unable to get GitHub username for user"), "danger")
|
flash(gettext("Unable to get GitHub username for user. Make sure the forum account exists."), "danger")
|
||||||
return redirect(url_for("users.claim_forums", username=username))
|
return redirect(url_for("users.claim_forums", username=username))
|
||||||
else:
|
else:
|
||||||
return redirect(url_for("vcs.github_start"))
|
return redirect(url_for("vcs.github_start"))
|
||||||
@ -62,9 +62,11 @@ def claim_forums():
|
|||||||
ctype = request.form.get("claim_type")
|
ctype = request.form.get("claim_type")
|
||||||
username = request.form.get("username")
|
username = request.form.get("username")
|
||||||
|
|
||||||
if not is_username_valid(username):
|
if User.query.filter(User.username == username, User.forums_username.is_(None)).first():
|
||||||
flash(gettext("Invalid username, Only alphabetic letters (A-Za-z), numbers (0-9), underscores (_), minuses (-), and periods (.) allowed. Consider contacting an admin"), "danger")
|
flash(gettext("A ContentDB user with that name already exists. Please contact an admin to link to your forum account"), "danger")
|
||||||
elif ctype == "github":
|
return redirect(url_for("users.claim_forums"))
|
||||||
|
|
||||||
|
if ctype == "github":
|
||||||
task = check_forum_account.delay(username)
|
task = check_forum_account.delay(username)
|
||||||
return redirect(url_for("tasks.check", id=task.id, r=url_for("users.claim_forums", 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":
|
elif ctype == "forum":
|
||||||
|
Loading…
Reference in New Issue
Block a user