Skip to content

Commit fe7919f

Browse files
committed
Improve logging
1 parent d86b0fa commit fe7919f

File tree

1 file changed

+7
-0
lines changed

1 file changed

+7
-0
lines changed

src/db_auth.py

+7
Original file line numberDiff line numberDiff line change
@@ -157,6 +157,7 @@ def login(self):
157157
username = req.get(self.USERNAME)
158158
password = req.get(self.PASSWORD)
159159
if username:
160+
self.logger.debug("Attempting to login via POST params as %s" % username)
160161
user = self.find_user(db_session, name=username)
161162
login_success, login_fail_reason = self.__user_is_authorized(user, password)
162163
if login_success:
@@ -173,6 +174,7 @@ def login(self):
173174
form.terms_url = self.terms_url
174175
form.favicon = self.favicon
175176
if form.validate_on_submit():
177+
self.logger.debug("Attempting to login via form as %s" % form.username.data)
176178
user = self.find_user(db_session, name=form.username.data)
177179

178180
# force password change on first sign in of default admin user
@@ -705,6 +707,7 @@ def __user_is_authorized(self, user, password):
705707

706708
if user is None or user.password_hash is None:
707709
# invalid username or no password set
710+
self.logger.debug("Invalid username or no password set for user")
708711
return False, i18n.t('auth.auth_failed')
709712
elif user.check_password(password):
710713
# valid credentials
@@ -715,9 +718,11 @@ def __user_is_authorized(self, user, password):
715718
user.last_sign_in_at = datetime.datetime.now(datetime.UTC)
716719
user.failed_sign_in_count = 0
717720

721+
self.logger.debug("User is authorized")
718722
return True, None
719723
else:
720724
# block sign in due to too many login attempts
725+
self.logger.debug("User is authorized but account is locked")
721726
return False, i18n.t('auth.account_locked')
722727
else:
723728
# invalid password
@@ -733,8 +738,10 @@ def __user_is_authorized(self, user, password):
733738
user.failed_sign_in_count += 1
734739

735740
if user.failed_sign_in_count < self.max_login_attempts:
741+
self.logger.debug("User is not authorized")
736742
return False, i18n.t('auth.auth_failed')
737743
else:
744+
self.logger.debug("User is not authorized, account is locked due to too many attempts")
738745
return False, i18n.t('auth.account_locked')
739746

740747
def user_totp_is_valid(self, user, token):

0 commit comments

Comments
 (0)