From 3c2f6847f02b7dc0b60fa586837e16635cef32cc Mon Sep 17 00:00:00 2001 From: =?utf8?q?Benoi=CC=82t=20Pin?= Date: Mon, 1 Sep 2014 23:09:14 +0200 Subject: [PATCH] Remise en route des inscriptions client. --- skins/customer_join_form.py | 6 +++--- skins/customer_join_template.pt | 6 +++--- skins/validatePrivateAccess.py | 11 ++++++----- utils.py | 35 +++++++++++++++++++++++++++++++++ 4 files changed, 47 insertions(+), 11 deletions(-) diff --git a/skins/customer_join_form.py b/skins/customer_join_form.py index 13422ea..f5f0f7c 100755 --- a/skins/customer_join_form.py +++ b/skins/customer_join_form.py @@ -40,9 +40,9 @@ continuationFields = [ , 'password' , 'confirm' , 'send_password' - , 'wedding_id' - , 'wedding_password' - , 'wedding_password_confirm' + , 'collection_id' + , 'collection_password' + , 'collection_password_confirm' , 'billing_address' , 'billing_city' , 'billing_zipcode' diff --git a/skins/customer_join_template.pt b/skins/customer_join_template.pt index 3693f7b..503c825 100644 --- a/skins/customer_join_template.pt +++ b/skins/customer_join_template.pt @@ -79,19 +79,19 @@ Identifiant collection privée - + Mot de passe associé - + Confirmation du mot de passe - + diff --git a/skins/validatePrivateAccess.py b/skins/validatePrivateAccess.py index 19e3a7d..7fc6530 100755 --- a/skins/validatePrivateAccess.py +++ b/skins/validatePrivateAccess.py @@ -1,15 +1,16 @@ ##parameters=**kw +from Products.photoprint.utils import grantAccess kg = lambda name : kw.get(name,'').strip() -weddingId = kg('wedding_id') -if not weddingId : +collectionId = kg('collection_id') +if not collectionId : return True else : - password = kg('wedding_password') - confirm = kg('wedding_password_confirm') + password = kg('collection_password') + confirm = kg('collection_password_confirm') memberId = kg('member_id') - msg = context.grantAccess(context, weddingId, password, confirm, memberId) + msg = grantAccess(collectionId, password, confirm, memberId) if msg : return context.setStatus(False, msg) else : diff --git a/utils.py b/utils.py index 0982bc7..9f4706f 100755 --- a/utils.py +++ b/utils.py @@ -19,6 +19,10 @@ from AccessControl import ModuleSecurityInfo from zope.i18n import translate as i18ntranslate from zope.i18nmessageid import MessageFactory from zope.globalrequest import getRequest +from Products.CMFCore.utils import getUtilityByInterfaceName +from Products.Plinn.utils import _sudo +import transaction + security = ModuleSecurityInfo('Products.photoprint.utils') @@ -29,3 +33,34 @@ def translate(msgid, mapping=None, default=None) : security.declarePublic('Message') Message = _ = MessageFactory('photoprint') + +security.declarePublic('grantAccess') +def grantAccess(collectionId, password, confirm, memberId) : + utool = getUtilityByInterfaceName('Products.CMFCore.interfaces.IURLTool') + mtool = getUtilityByInterfaceName('Products.CMFCore.interfaces.IMembershipTool') + portal = utool.getPortalObject() + + data = portal.private_collections.data + lines = filter(None, [l.strip() for l in data.split('\n')]) + assert len(lines) % 3 == 0 + collecInfos = {} + for i in xrange(0, len(lines), 3) : + collecInfos[lines[i]] = {'pw' : lines[i+1], + 'path' : lines[i+2]} + + if not collecInfos.has_key(collectionId) : + transaction.abort() + return _('Wrong private collection identifier.') + elif password != confirm : + transaction.abort() + return _("Collection's password does not match confirmation.") + else : + if collecInfos[collectionId]['pw'] != password : + transaction.abort() + return _("Wrong collection's password.") + else : + collec = portal.unrestrictedTraverse(collecInfos[collectionId]['path']) + def do() : + mtool.setLocalRoles(collec, [memberId], 'Reader') + + _sudo(do) -- 2.20.1