Skip to content

Commit

Permalink
fix: make otl link invalid if user was purged
Browse files Browse the repository at this point in the history
  • Loading branch information
mutantsan committed Oct 5, 2023
1 parent 19688fd commit 5686e2b
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 2 deletions.
9 changes: 9 additions & 0 deletions ckanext/let_me_in/tests/test_views.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,3 +33,12 @@ def test_user_login_expires_the_otl(self, app, user):
"You have tried to use a one-time login link that has expired"
in app.get(otl["url"]).body
)

def test_visit_link_after_user_has_been_deleted(self, app, user):
otl = call_action("lmi_generate_otl", uid=user["id"])

user = cast(model.User, model.User.get(user["id"]))
user.purge()
user.commit()

assert "Invalid login link" in app.get(otl["url"]).body
4 changes: 2 additions & 2 deletions ckanext/let_me_in/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,9 @@ def get_secret(encode: bool) -> str:
return _get_secret(encode)


def get_user(user_id: str) -> model.User:
def get_user(user_id: str) -> model.User | None:
"""Get a user by its ID/name"""
return cast(model.User, model.User.get(user_id))
return model.User.get(user_id)


def update_user_last_active(user: model.User) -> None:
Expand Down
5 changes: 5 additions & 0 deletions ckanext/let_me_in/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,11 @@ def login_with_token(token):
tk.h.flash_error(tk._("Invalid login link."))
else:
user = lmi_utils.get_user(token["user_id"])

if not user:
tk.h.flash_error(tk._("Invalid login link."))
return tk.h.redirect_to("user.login")

context = {}

for plugin in p.PluginImplementations(ILetMeIn):
Expand Down

0 comments on commit 5686e2b

Please sign in to comment.