Skip to content
5 changes: 5 additions & 0 deletions openlibrary/accounts/model.py
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,11 @@ def create_link_doc(key, username, email):
}


def clear_cookies():
web.setcookie('pd', "", expires=-1)
web.setcookie('sfw', "", expires=-1)


class Link(web.storage):
def get_expiration_time(self):
d = self['expires_on'].split(".")[0]
Expand Down
4 changes: 4 additions & 0 deletions openlibrary/plugins/admin/code.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
import openlibrary

from openlibrary import accounts
from openlibrary.accounts.model import clear_cookies
from openlibrary.accounts.model import OpenLibraryAccount
from openlibrary.core import admin as admin_stats, helpers as h, imports, cache
from openlibrary.core.waitinglist import Stats as WLStats
Expand Down Expand Up @@ -465,7 +466,10 @@ def POST_set_bot_flag(self, account, bot):

def POST_su(self, account):
code = account.generate_login_code()
# Clear all existing admin cookies before logging in as another user
clear_cookies()
web.setcookie(config.login_cookie_name, code, expires="")

return web.seeother("/")

def POST_anonymize_account(self, account, test):
Expand Down
18 changes: 18 additions & 0 deletions openlibrary/plugins/upstream/account.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
OpenLibraryAccount,
InternetArchiveAccount,
valid_email,
clear_cookies,
)
from openlibrary.plugins.upstream import borrow, forms, utils
from openlibrary.utils.dateutil import elapsed_time
Expand Down Expand Up @@ -434,6 +435,23 @@ def POST_resend_verification_email(self, i):
return render.message(title, message)


class account_logout(delegate.page):
"""Account logout.

This registers a handler to the /account/logout endpoint in infogami so that additional logic, such as clearing admin cookies,
can be handled prior to the calling of infogami's standard logout procedure

"""

path = "/account/logout"

def POST(self):
clear_cookies()
from infogami.core.code import logout as infogami_logout

return infogami_logout().POST()


class account_verify(delegate.page):
"""Verify user account."""

Expand Down