fix: disable public signup and restore local login flow
This commit is contained in:
@@ -11,6 +11,10 @@ from ..models import User
|
||||
bp = Blueprint("auth", __name__)
|
||||
|
||||
|
||||
def registration_open() -> bool:
|
||||
return User.query.count() == 0
|
||||
|
||||
|
||||
@bp.route("/login", methods=["GET", "POST"])
|
||||
def login():
|
||||
if current_user.is_authenticated:
|
||||
@@ -24,13 +28,16 @@ def login():
|
||||
flash(f"Willkommen zurück, {user.name}.", "success")
|
||||
return redirect(url_for("tasks.my_tasks"))
|
||||
flash("Die Kombination aus E-Mail und Passwort passt leider nicht.", "error")
|
||||
return render_template("auth/login.html", form=form)
|
||||
return render_template("auth/login.html", form=form, registration_open=registration_open())
|
||||
|
||||
|
||||
@bp.route("/register", methods=["GET", "POST"])
|
||||
def register():
|
||||
if current_user.is_authenticated:
|
||||
return redirect(url_for("tasks.my_tasks"))
|
||||
if not registration_open():
|
||||
flash("Freie Registrierung ist deaktiviert.", "info")
|
||||
return redirect(url_for("auth.login"))
|
||||
|
||||
form = RegisterForm()
|
||||
if form.validate_on_submit():
|
||||
@@ -50,4 +57,3 @@ def logout():
|
||||
logout_user()
|
||||
flash("Du bist jetzt abgemeldet.", "info")
|
||||
return redirect(url_for("auth.login"))
|
||||
|
||||
|
||||
Reference in New Issue
Block a user