Skip to content

Commit

Permalink
Allow username alias
Browse files Browse the repository at this point in the history
- Bump to 0.13.2
  • Loading branch information
smathot committed Mar 11, 2024
1 parent 880971c commit 599a834
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 5 deletions.
2 changes: 1 addition & 1 deletion heymans/__init__.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
"""AI-based chatbot that provides sensible answers based on documentation"""

__version__ = '0.13.1'
__version__ = '0.13.2'
20 changes: 17 additions & 3 deletions heymans/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -186,14 +186,28 @@ def process_ai_message(msg):

def validate_user(username, password):
"""user_validation.validate() should connect to an authentication system
that verifies the account. Whitespace has been stripped from both the
username and the password. The username is converted to lowercase.
that verifies the account.
Parameters
----------
username : str
Lowercase. Whitespace has been stripped.
password : str
Whitespace has been stripped.
Returns
-------
str or None:
If the user is validated, the username is returned. This is typically
equal to the `username` parameter, but in some cases it may differ, for
example if the user logs in with an email address instead of the actual
username. If the user is not validated, None is returned.
"""
try:
import user_validation
except ImportError:
logger.info('no user validation script found')
return True
return username
logger.info('using validation script')
return user_validation.validate(username, password)

Expand Down
3 changes: 2 additions & 1 deletion heymans/routes/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,8 @@ def login_handler(form, failed=False):
if form.validate_on_submit():
username = form.username.data.strip().lower()
password = form.password.data.strip()
if not config.validate_user(username, password):
username = config.validate_user(username, password)
if username is None:
return redirect('/login_failed')
kdf = PBKDF2HMAC(algorithm=hashes.SHA256(),
length=32,
Expand Down

0 comments on commit 599a834

Please sign in to comment.