Skip to content

Commit

Permalink
Notify user events on creation and authentication (Fixes #53)
Browse files Browse the repository at this point in the history
  • Loading branch information
ericof committed Jun 25, 2024
1 parent 6346418 commit 3dd95a6
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 2 deletions.
1 change: 1 addition & 0 deletions news/53.feature
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Notify user events on creation and authentication. [@Arkusm][@ericof]
13 changes: 11 additions & 2 deletions src/pas/plugins/oidc/plugins.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,9 @@
from plone.protect.utils import safeWrite
from Products.CMFCore.utils import getToolByName
from Products.PageTemplates.PageTemplateFile import PageTemplateFile
from Products.PlonePAS.events import UserInitialLoginInEvent
from Products.PlonePAS.events import UserLoggedInEvent
from Products.PluggableAuthService.events import PrincipalCreated
from Products.PluggableAuthService.interfaces.plugins import IAuthenticationPlugin
from Products.PluggableAuthService.interfaces.plugins import IChallengePlugin
from Products.PluggableAuthService.interfaces.plugins import IUserAdderPlugin
Expand All @@ -18,6 +21,7 @@
from secrets import choice
from typing import List
from ZODB.POSException import ConflictError
from zope.event import notify
from zope.interface import implementer
from zope.interface import Interface

Expand Down Expand Up @@ -214,12 +218,17 @@ def rememberIdentity(self, userinfo):
# depending on your setup.
# https://bandit.readthedocs.io/en/1.7.4/plugins/b110_try_except_pass.html
pass
self._updateUserProperties(user, userinfo)
break
else:
notify(PrincipalCreated(user))
self._updateUserProperties(user, userinfo)
notify(UserInitialLoginInEvent(user))
notify(UserLoggedInEvent(user))
break
else:
# if time.time() > user.getProperty(LAST_UPDATE_USER_PROPERTY_KEY) + config.get(autoUpdateUserPropertiesIntervalKey, 0):
with safe_write(self.REQUEST):
self._updateUserProperties(user, userinfo)
notify(UserLoggedInEvent(user))

if self.getProperty("create_groups"):
groupid_property = self.getProperty("user_property_as_groupid")
Expand Down

0 comments on commit 3dd95a6

Please sign in to comment.