This commit is contained in:
copyrighttxt
2026-08-02 14:13:03 -04:00
committed by GitHub
parent 2ae91b647b
commit 9c45d7e6c8
4 changed files with 36 additions and 20 deletions
@@ -79,5 +79,8 @@ WebsiteFeaturesDefinition = [
},
{
"name": "CurrencyExchange"
},
{
"name": "InviteKeys"
}
]
+7 -1
View File
@@ -1,7 +1,7 @@
from flask import Blueprint, render_template, request, redirect, url_for, jsonify, make_response, flash
from app.models.user import User
from app.models.invite_key import InviteKey
from app.util import auth, transactions
from app.util import auth, transactions, websiteFeatures
from app.services import invitekeys, economy
from app.extensions import db, limiter, csrf
from datetime import datetime, timedelta
@@ -11,6 +11,9 @@ inviteKeyRoute = Blueprint("invitekey", __name__, url_prefix="/")
@inviteKeyRoute.route("/invite-keys", methods=["GET"])
@auth.authenticated_required
def inviteKeysPage():
if not websiteFeatures.GetWebsiteFeature("InviteKeys"):
flash("Invite keys are temporarily disabled", "error")
return redirect("/home")
AuthenticatedUser : User = auth.GetCurrentUser()
pageNumber = request.args.get("page", 1, int)
if pageNumber < 1:
@@ -23,6 +26,9 @@ def inviteKeysPage():
@auth.authenticated_required
@csrf.exempt
def createInviteKey():
if not websiteFeatures.GetWebsiteFeature("InviteKeys"):
flash("Invite keys are temporarily disabled", "error")
return redirect("/home")
AuthenticatedUser : User = auth.GetCurrentUser()
if AuthenticatedUser is None:
return jsonify({"success": False, "message": "Unauthorized"}),401
+2
View File
@@ -24,7 +24,9 @@
<form action="/signup" method="post">
<input type="text" id="username" name="username" class="form-control" placeholder="Username" value="" required>
<input type="password" name="password" id="password" class="form-control" placeholder="Password" value="" required>
{% if InviteKeysEnabled %}
<input type="text" id="invite-key" name="invite-key" class="form-control mb-2" placeholder="Invite Key" value="" required>
{% endif %}
<div id="checkboxTerms">
<input class="form-check-input" name="agreetoTermsandPrivacy" type="checkbox" id="agreeCheckbox" required>
<label class="form-check-label" for="agreeCheckbox">
+7 -2
View File
@@ -33,7 +33,8 @@ def signup_page():
if not websiteFeatures.GetWebsiteFeature("WebSignup"):
flash("Signups are temporarily disabled")
SignupEnabled = False
return render_template("signup/signup.html", SignupEnabled=SignupEnabled)
InviteKeysEnabled = websiteFeatures.GetWebsiteFeature("InviteKeys")
return render_template("signup/signup.html", SignupEnabled=SignupEnabled, InviteKeysEnabled=InviteKeysEnabled)
def RateLimitReached(e):
flash("You are being rate limited. Please try again later.")
@@ -82,7 +83,8 @@ def signup_post():
flash("Please complete the captcha", "error")
return redirect("/signup")
if username is None or password is None or invitekey is None:
InviteKeysEnabled = websiteFeatures.GetWebsiteFeature("InviteKeys")
if username is None or password is None or (InviteKeysEnabled and invitekey is None):
flash("Please fill in all fields")
return redirect("/signup")
@@ -189,6 +191,7 @@ def signup_post():
flash("Username already taken")
return redirect("/signup")
if InviteKeysEnabled:
try:
inviteKey : InviteKey = invitekeys.GetInviteKey(invitekey)
except invitekeys.InviteExceptions.InvalidInviteKey:
@@ -242,8 +245,10 @@ def signup_post():
userAvatar.torso_color_id = random.choice(AllowedBodyColors)
db.session.add(userAvatar)
if InviteKeysEnabled:
invitekeys.UseInviteKey(invitekey, NewRegisteredUser)
db.session.commit()
redislock.release_lock("UserSignupLock", UserSignupLock)
logging.info(f"New user registered: {NewRegisteredUser.username} ({NewRegisteredUser.id})")