Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix login json SFW #7935

Merged
merged 1 commit into from
Jun 6, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 5 additions & 4 deletions openlibrary/plugins/upstream/account.py
Original file line number Diff line number Diff line change
Expand Up @@ -336,9 +336,10 @@ def POST(self):
raise olib.code.BadRequest(error)
expires = 3600 * 24 * 365 if remember.lower() == 'true' else ""
web.setcookie(config.login_cookie_name, web.ctx.conn.get_auth_token())
ol_account = OpenLibraryAccount.get(email=email)
if ol_account.get_user().get_safe_mode() == 'yes':
web.setcookie('sfw', 'yes', expires=expires)
if audit.get('ia_email'):
ol_account = OpenLibraryAccount.get(email=audit['ia_email'])
if ol_account and ol_account.get_user().get_safe_mode() == 'yes':
web.setcookie('sfw', 'yes', expires=expires)
Comment on lines +339 to +342
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Get ia_email once, not twice...

Suggested change
if audit.get('ia_email'):
ol_account = OpenLibraryAccount.get(email=audit['ia_email'])
if ol_account and ol_account.get_user().get_safe_mode() == 'yes':
web.setcookie('sfw', 'yes', expires=expires)
if (
ia_email := audit.get('ia_email')
and ol_account := OpenLibraryAccount.get(email=ia_email)
and ol_account.get_user().get_safe_mode() == 'yes'
):
web.setcookie('sfw', 'yes', expires=expires)

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm pretty sure in this code ia_email will be undefined within the if statement.
Screenshot 2023-06-06 at 11 41 33 AM

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Today I Learned: You need an extra sent of parens around the ia_email := audit.get('ia_email') bit just to make it work properly! Thanks @mekarpeles

# Fallback to infogami user/pass
else:
from infogami.plugins.api.code import login as infogami_login
Expand Down Expand Up @@ -403,7 +404,7 @@ def POST(self):
config.login_cookie_name, web.ctx.conn.get_auth_token(), expires=expires
)
ol_account = OpenLibraryAccount.get(email=email)
if ol_account.get_user().get_safe_mode() == 'yes':
if ol_account and ol_account.get_user().get_safe_mode() == 'yes':
web.setcookie('sfw', 'yes', expires=expires)
blacklist = [
"/account/login",
Expand Down