Skip to content

Commit

Permalink
Merge 825cf7f into e639554
Browse files Browse the repository at this point in the history
  • Loading branch information
hvelarde committed Nov 7, 2018
2 parents e639554 + 825cf7f commit 5f2d664
Show file tree
Hide file tree
Showing 6 changed files with 21 additions and 16 deletions.
4 changes: 2 additions & 2 deletions CHANGES.rst
Expand Up @@ -7,8 +7,8 @@ Changelog
- Deprecate Plone 4.1, Plone 4.2 and Python 2.6.
[hvelarde]

- Avoids ``TypeError`` on ``InvalidPasswordEntered`` subscriber when the list of whitelisted users has not being set.
[csanahuja]
- Avoid ``TypeError`` on Password Expiry plugin and ``InvalidPasswordEntered`` subscriber when the list of whitelisted users has not being set.
[csanahuja, hvelarde]

- Restore compatibility with Plone 4.3.
[hvelarde]
Expand Down
7 changes: 7 additions & 0 deletions collective/pwexpiry/logger.py
@@ -0,0 +1,7 @@
# -*- coding: utf-8 -*-
from collective.pwexpiry.config import PROJECTNAME

import logging


logger = logging.getLogger(PROJECTNAME)
5 changes: 1 addition & 4 deletions collective/pwexpiry/patches.py
Expand Up @@ -4,17 +4,14 @@
from collective.pwexpiry.events import InvalidPasswordEntered
from collective.pwexpiry.events import ValidPasswordEntered
from collective.pwexpiry.interfaces import ICustomPasswordValidator
from collective.pwexpiry.logger import logger
from plone import api
from Products.CMFPlone.RegistrationTool import RegistrationTool
from Products.PluggableAuthService.plugins.ZODBUserManager import ZODBUserManager # noqa: E501
from zope.component import getAdapters
from zope.event import notify

import hashlib
import logging


logger = logging.getLogger(__file__)


original_testPasswordValidity = RegistrationTool.testPasswordValidity
Expand Down
2 changes: 1 addition & 1 deletion collective/pwexpiry/pwexpiry_plugin.py
Expand Up @@ -79,7 +79,7 @@ def authenticateCredentials(self, credentials):
whitelisted = api.portal.get_registry_record(
'collective.pwexpiry.whitelisted_users'
)
if user.getId() in whitelisted:
if whitelisted and user.getId() in whitelisted:
return None

password_date = user.getProperty('password_date', '2000/01/01')
Expand Down
6 changes: 1 addition & 5 deletions collective/pwexpiry/setuphandlers.py
@@ -1,5 +1,6 @@
# -*- coding: utf-8 -*-
from collective.pwexpiry.config import IS_PLONE_5
from collective.pwexpiry.logger import logger
from collective.pwexpiry.pwdisable_plugin import addPwDisablePlugin
from collective.pwexpiry.pwexpiry_plugin import addPwExpiryPlugin
from Products.CMFCore.utils import getToolByName
Expand All @@ -8,11 +9,6 @@
from Products.PluggableAuthService.interfaces.plugins import IChallengePlugin
from zope.interface import implementer

import logging


logger = logging.getLogger('collective.pwexpiry')


@implementer(INonInstallable)
class HiddenProfiles(object): # pragma: no cover
Expand Down
13 changes: 9 additions & 4 deletions collective/pwexpiry/subscriber.py
@@ -1,5 +1,6 @@
# -*- coding: utf-8 -*-
from AccessControl import Unauthorized
from collective.pwexpiry.logger import logger
from plone import api
from plone.registry.interfaces import IRegistry
from zope.component import queryUtility
Expand All @@ -25,11 +26,14 @@ def ValidPasswordEntered(user, event):
# Enough time has elapsed
user.setMemberProperties({'account_locked': False,
'password_tries': 0})
msg = 'User {0} logged in after lock time; account is now unlocked'
logger.info(msg.format(user))
else:
user_disabled_time = disable_time - (delta.seconds / 3600)
user.REQUEST.RESPONSE.setHeader('user_disabled', user.getId())
user.REQUEST.RESPONSE.setHeader(
'user_disabled_time', (disable_time - (delta.seconds / 3600))
)
user.REQUEST.RESPONSE.setHeader('user_disabled_time', user_disabled_time)
msg = 'User {0} tried to log in but account is locked for {1} hours'
logger.warn(msg.format(user, user_disabled_time))
raise Unauthorized

else:
Expand All @@ -54,7 +58,6 @@ def InvalidPasswordEntered(user, event):
if whitelisted and user.getId() in whitelisted:
return


allowed_tries = registry['collective.pwexpiry.allowed_tries']
current_tries = user.getProperty('password_tries', 0)

Expand All @@ -67,3 +70,5 @@ def InvalidPasswordEntered(user, event):
current_time = portal.ZopeTime()
user.setMemberProperties({'account_locked_date': current_time,
'account_locked': True})
msg = 'User {0} has tried to access {1} times with an invalid password; account is locked' # noqa: E501
logger.warn(msg.format(user, current_tries))

0 comments on commit 5f2d664

Please sign in to comment.