summaryrefslogtreecommitdiffstats
path: root/accounts/views/login/__init__.py
diff options
context:
space:
mode:
Diffstat (limited to 'accounts/views/login/__init__.py')
-rw-r--r--accounts/views/login/__init__.py46
1 files changed, 27 insertions, 19 deletions
diff --git a/accounts/views/login/__init__.py b/accounts/views/login/__init__.py
index ee049bf..1285605 100644
--- a/accounts/views/login/__init__.py
+++ b/accounts/views/login/__init__.py
@@ -13,7 +13,7 @@ from typing import Union
from .forms import LoginForm
-bp = Blueprint('login', __name__)
+bp = Blueprint("login", __name__)
def is_safe_url(target: str):
@@ -21,36 +21,44 @@ def is_safe_url(target: str):
test_url = urlparse(urljoin(request.host_url, target))
print(target)
print(test_url)
- return test_url.scheme in ('http', 'https') and \
- ref_url.netloc == test_url.netloc and \
- test_url.path == target
+ return (
+ test_url.scheme in ("http", "https")
+ and ref_url.netloc == test_url.netloc
+ and test_url.path == target
+ )
-@bp.route('/login', methods=['GET', 'POST'])
+@bp.route("/login", methods=["GET", "POST"])
def login() -> Union[str, Response]:
if current_user.is_authenticated:
- return redirect(url_for('default.index'))
+ return redirect(url_for("default.index"))
form = LoginForm(request.form)
if form.validate_on_submit():
try:
- user = accounts_app.user_backend.auth(form.username.data,
- form.password.data)
+ user = accounts_app.user_backend.auth(
+ form.username.data, form.password.data
+ )
login_user(user)
- flash('Erfolgreich eingeloggt', 'success')
+ flash("Erfolgreich eingeloggt", "success")
- next = request.form['next']
- return redirect(next if is_safe_url(next) else url_for('default.index'))
- except (accounts_app.user_backend.NoSuchUserError,
- accounts_app.user_backend.InvalidPasswordError):
- flash('Ungültiger Benutzername und/oder Passwort', 'error')
+ next = request.form["next"]
+ return redirect(
+ next if is_safe_url(next) else url_for("default.index")
+ )
+ except (
+ accounts_app.user_backend.NoSuchUserError,
+ accounts_app.user_backend.InvalidPasswordError,
+ ):
+ flash("Ungültiger Benutzername und/oder Passwort", "error")
- return render_template("login/login.html", form=form,
- next=request.values.get('next'))
+ return render_template(
+ "login/login.html", form=form, next=request.values.get("next")
+ )
-@bp.route('/logout')
+@bp.route("/logout")
def logout() -> Response:
logout_user()
- flash('Erfolgreich ausgeloggt.', 'success')
- return redirect(url_for('.login'))
+ flash("Erfolgreich ausgeloggt.", "success")
+ return redirect(url_for(".login"))