From dd004fc4dd10a5f8917306afca2bb191c9a98329 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Benoi=CC=82t=20Pin?= Date: Mon, 24 Jun 2013 01:49:19 +0200 Subject: [PATCH] =?utf8?q?D=C3=A9but=20d'impl=C3=A9mentation=20du=20reset?= =?utf8?q?=20des=20mots=20de=20passe.?= MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit --- RegistrationTool.py | 57 +++++++- skins/custom_generic/login_form.pt | 131 ++++++++----------- skins/generic/request_password_reset_form.pt | 30 +++++ 3 files changed, 143 insertions(+), 75 deletions(-) create mode 100644 skins/generic/request_password_reset_form.pt diff --git a/RegistrationTool.py b/RegistrationTool.py index 77f8bdc..7d2f29b 100644 --- a/RegistrationTool.py +++ b/RegistrationTool.py @@ -1,7 +1,7 @@ # -*- coding: utf-8 -*- ####################################################################################### # Plinn - http://plinn.org # -# Copyright (C) 2005-2007 Benoît PIN # +# © 2005-2013 Benoît PIN # # # # This program is free software; you can redistribute it and/or # # modify it under the terms of the GNU General Public License # @@ -17,7 +17,7 @@ # along with this program; if not, write to the Free Software # # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. # ####################################################################################### -""" Plinn registration tool: implements 3 modes to register members : +""" Plinn registration tool: implements 3 modes to register members: anonymous, manager, reviewed. @@ -29,11 +29,16 @@ from Products.PageTemplates.PageTemplateFile import PageTemplateFile from Products.CMFDefault.RegistrationTool import RegistrationTool as BaseRegistrationTool from AccessControl import ClassSecurityInfo, ModuleSecurityInfo from AccessControl.Permission import Permission +from BTrees.OOBTree import OOBTree from Products.CMFCore.permissions import ManagePortal, AddPortalMember from Products.CMFCore.exceptions import AccessControl_Unauthorized from Products.CMFCore.utils import getToolByName +from Products.CMFCore.utils import getUtilityByInterfaceName from Products.GroupUserFolder.GroupsToolPermissions import ManageGroups +from Products.Plinn.utils import Message as _ +from DateTime import DateTime from types import TupleType, ListType +from uuid import uuid4 security = ModuleSecurityInfo('Products.Plinn.RegistrationTool') MODE_ANONYMOUS = 'anonymous' @@ -72,6 +77,7 @@ class RegistrationTool(BaseRegistrationTool) : def __init__(self) : self._mode = MODE_ANONYMOUS self._chain = '' + self._passwordResetRequests = OOBTree() security.declareProtected(ManagePortal, 'configureTool') def configureTool(self, registration_mode, chain, REQUEST=None) : @@ -183,5 +189,52 @@ class RegistrationTool(BaseRegistrationTool) : """ notify member creation """ member.notifyWorkflowCreated() member.indexObject() + + + security.declarePublic('requestPasswordReset') + def requestPasswordReset(self, userid): + """ add uuid / (userid, expiration) pair and return uuid """ + self.clearExpiredPasswordResetRequests() + mtool = getUtilityByInterfaceName('Products.CMFCore.interfaces.IMembershipTool') + if mtool.getMemberById(userid) : + uuid = str(uuid4()) + self._passwordResetRequests[uuid] = (userid, DateTime() + 1) + return uuid + + security.declarePrivate('clearExpiredPasswordResetRequests') + def clearExpiredPasswordResetRequests(self): + now = DateTime() + for uuid, record in self._passwordResetRequest.items() : + userid, date = record + if date < now : + del self._passwordResetRequests[uuid] + + + security.declarePublic('resetPassword') + def resetPassword(self, userid, uuid, password, confirm) : + record = self._passwordResetRequests.get(uuid) + if not record : + return _('Invalid reset password request.') + + recUserid, expiration = record + + if recUserid != userid : + return _('Invalid userid.') + + if expiration < now : + self.clearExpiredPasswordResetRequests() + return _('Your reset password request has expired. You can ask a new one.') + + msg = self.testPasswordValidity(password, confirm=confirm) + if not msg : # None if everything ok. Err message otherwise. + mtool = getUtilityByInterfaceName('Products.CMFCore.interfaces.IMembershipTool') + member = mtool.getMemberById(userid) + if member : + member.setSecurityProfile(password=password) + del self._passwordResetRequests[uuid] + return _('Password successfully resetted.') + else : + return _('"%s" username not found.') % userid + InitializeClass(RegistrationTool) \ No newline at end of file diff --git a/skins/custom_generic/login_form.pt b/skins/custom_generic/login_form.pt index 3d3c4bb..0ebaefc 100644 --- a/skins/custom_generic/login_form.pt +++ b/skins/custom_generic/login_form.pt @@ -1,81 +1,66 @@ - -
-
-

Log in

- -
- - - - - - - - - - - + + + + + + + + + + + + +
- Login + +
+
+

Log in

+ + + + + + + + + + + + - - - - - - - - - - - - - - - - -
Login + - -
- Password - - -
- -
- - -
- - -

Forgot your password? -

- -

Having trouble logging in? Make sure to enable cookies in - your web browser. -

-

Don't forget to logout or exit your browser when you're - done. -

- -

Setting the 'Remember my name' option will set a cookie - with your username, so that when you next log in, your user name will - already be filled in for you. -

-
-
- +
Password + +

+ + +

+ +
+ + +

+ Having trouble logging in? Make sure to enable cookies in your web + browser. +

+

+ Don't forget to logout or exit your browser when you're done. +

+

+ Setting the 'Remember my name' option will set a cookie with your + username, so that when you next log in, your user name will already be + filled in for you. +

+
+
+ - diff --git a/skins/generic/request_password_reset_form.pt b/skins/generic/request_password_reset_form.pt new file mode 100644 index 0000000..fe7c384 --- /dev/null +++ b/skins/generic/request_password_reset_form.pt @@ -0,0 +1,30 @@ + + + + + +
+
+

Password reset

+

+ Enter your username below and click on the "Send" button. You will + receive an email with a link to reset your password. +

+

+ If this will not work for you (for example, if you forget your + username or didn't enter your email address) send email to me@here.com. +

+
+ + +
+
+
+ + -- 2.20.1