diff --git a/news/53.feature b/news/53.feature new file mode 100644 index 0000000..db6e924 --- /dev/null +++ b/news/53.feature @@ -0,0 +1 @@ +Notify user events on creation and authentication. [@Arkusm][@ericof] diff --git a/src/pas/plugins/oidc/plugins.py b/src/pas/plugins/oidc/plugins.py index bc8368b..2e5ca41 100644 --- a/src/pas/plugins/oidc/plugins.py +++ b/src/pas/plugins/oidc/plugins.py @@ -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 @@ -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 @@ -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")