diff --git a/tests/integration/it_auth_test.py b/tests/integration/it_auth_test.py index 6497b4f0..9da5c4d2 100644 --- a/tests/integration/it_auth_test.py +++ b/tests/integration/it_auth_test.py @@ -12,7 +12,7 @@ def test_incorrect_username(db_session): """Do not remove db_session dependency. It is injected in order to trigger db migration. """ - assert (login("unknown", "unknown") == "Incorrect username.") + assert (login("unknown", "unknown") == "login.failed") def test_incorrect_password(db_session): @@ -24,7 +24,7 @@ def test_incorrect_password(db_session): db_session.add(employee) db_session.commit() error = login("vgv", "unknown") - assert (error == "Incorrect password.") + assert (error == "login.failed") def test_login(db_session): diff --git a/timeless/auth/auth.py b/timeless/auth/auth.py index c6c20af6..815799a3 100644 --- a/timeless/auth/auth.py +++ b/timeless/auth/auth.py @@ -4,17 +4,16 @@ def login(username="", password=""): """Login user - @todo #59:30min The backend should return only error codes for login procedure, - not hardcoded messages. The codes should then be translated into (mapped to) - Strings on the UI, so we can easily have internationalization or change - error messages without having to rebuild + redeploy the backend. + @todo #201:30min Translate login error codes. + The codes returned from login errors should then be translated into ( + mapped to) Strings on the UI, so we can easily have + internationalization or change error messages without having to + rebuild + redeploy the backend. """ user = Employee.query.filter_by(username=username).first() error = None - if user is None: - error = "Incorrect username." - elif not user.validate_password(password): - error = "Incorrect password." + if user is None or not user.validate_password(password): + error = "login.failed" if error is None: session.clear() session["user_id"] = user.id