From 21f1035b66fb0daf7ec6cfbbcf2da946d0f83fd8 Mon Sep 17 00:00:00 2001 From: Kiril Kovachev Date: Mon, 14 Oct 2024 12:52:07 +0100 Subject: [PATCH] Flash localized messages from auth --- kanken_online/auth.py | 8 ++++---- kanken_online/lang.py | 14 ++++++++++++-- 2 files changed, 16 insertions(+), 6 deletions(-) diff --git a/kanken_online/auth.py b/kanken_online/auth.py index 6d8cc73..50069b0 100644 --- a/kanken_online/auth.py +++ b/kanken_online/auth.py @@ -14,9 +14,9 @@ def register(): error = None if not username: - error = "Username is required." + error = "username_required" elif not password: - error = "Password is required." + error = "password_required" if error is None: try: @@ -46,9 +46,9 @@ def login(): ).fetchone() if user is None: - error = "Incorrect username." + error = "incorrect_username" elif not check_password_hash(user["password"], password): - error = "Incorrect password." + error = "incorrect_password" if error is None: session.clear() diff --git a/kanken_online/lang.py b/kanken_online/lang.py index b99beb2..6d18558 100644 --- a/kanken_online/lang.py +++ b/kanken_online/lang.py @@ -12,7 +12,9 @@ EXISTING_STRINGS = { "search", "search_placeholder", "include_kanji", - "include_kotoba" + "include_kotoba", + "username_required", + "password_required" } ENGLISH = { @@ -29,7 +31,11 @@ ENGLISH = { "search": "Search", "search_placeholder": "Enter kanji or word", "include_kanji": "Include kanji", - "include_kotoba": "Include kotoba" + "include_kotoba": "Include kotoba", + "username_required": "Username required.", + "password_required": "Password required.", + "incorrect_username": "Incorrect username.", + "incorrect_password": "Incorrect password." } JAPANESE = { @@ -47,6 +53,10 @@ JAPANESE = { "search_placeholder": "漢字・言葉を入力", "include_kanji": "漢字を含む", "include_kotoba": "言葉を含む", + "username_required": "ユーザー名が必要です", + "password_required": "パスワードが必要です", + "incorrect_username": "ユーザー名が違います", + "incorrect_password": "パスワードが違います" } LANGUAGES = [