]> CRI, Mines Paris - PSL - photoprint.git/commitdiff
Remise en route des inscriptions client.
authorBenoît Pin <benoit.pin@gmail.com>
Mon, 1 Sep 2014 21:09:14 +0000 (23:09 +0200)
committerBenoît Pin <benoit.pin@gmail.com>
Mon, 1 Sep 2014 21:09:14 +0000 (23:09 +0200)
skins/customer_join_form.py
skins/customer_join_template.pt
skins/validatePrivateAccess.py
utils.py

index 13422ea74bdc79ca4412264ea369b46406b2291a..f5f0f7cab9456771c2b3a1cbf650d941667e38d5 100755 (executable)
@@ -40,9 +40,9 @@ continuationFields = [
        , 'password'
        , 'confirm'
        , 'send_password'
        , 'password'
        , 'confirm'
        , 'send_password'
-       , 'wedding_id'
-       , 'wedding_password'
-       , 'wedding_password_confirm'
+       , 'collection_id'
+       , 'collection_password'
+       , 'collection_password_confirm'
        , 'billing_address'
        , 'billing_city'
        , 'billing_zipcode'
        , 'billing_address'
        , 'billing_city'
        , 'billing_zipcode'
index 3693f7bb1b9af9fc65a8ce39f50e076b3310d470..503c8253d907925c003b4a32a092baa623eec306 100644 (file)
         <tr>
           <th>Identifiant collection privée</th>
           <td>
         <tr>
           <th>Identifiant collection privée</th>
           <td>
-            <input type="text" name="wedding_id" tal:attributes="value options/wedding_id"/>
+            <input type="text" name="collection_id" tal:attributes="value options/collection_id"/>
           </td>
         </tr>
         <tr>
           <th>Mot de passe associé</th>
           <td>
           </td>
         </tr>
         <tr>
           <th>Mot de passe associé</th>
           <td>
-            <input type="password" name="wedding_password" tal:attributes="value options/wedding_password" />
+            <input type="password" name="collection_password" tal:attributes="value options/collection_password" />
           </td>
         </tr>
         <tr>
           <th>Confirmation du mot de passe</th>
           <td>
           </td>
         </tr>
         <tr>
           <th>Confirmation du mot de passe</th>
           <td>
-            <input type="password" name="wedding_password_confirm" tal:attributes="value options/wedding_password_confirm" />
+            <input type="password" name="collection_password_confirm" tal:attributes="value options/collection_password_confirm" />
           </td>
         </tr>
         <tr>
           </td>
         </tr>
         <tr>
index 19e3a7de09f0c198759048419d837a01566d35d7..7fc653034a52f2c648204651024b7df165147c2a 100755 (executable)
@@ -1,15 +1,16 @@
 ##parameters=**kw
 ##parameters=**kw
+from Products.photoprint.utils import grantAccess
 kg = lambda name : kw.get(name,'').strip()
 
 kg = lambda name : kw.get(name,'').strip()
 
-weddingId = kg('wedding_id')
-if not weddingId :
+collectionId = kg('collection_id')
+if not collectionId :
        return True
 
 else :
        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')
        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 :
        if msg :
                return context.setStatus(False, msg)
        else :
index 0982bc7c0d6b24422e0f2e0c38177c2d65e66450..9f4706f8deebb417831676dfc3c7b573597f4341 100755 (executable)
--- 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 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')
 
 
 security = ModuleSecurityInfo('Products.photoprint.utils')
 
@@ -29,3 +33,34 @@ def translate(msgid, mapping=None, default=None) :
 
 security.declarePublic('Message')
 Message = _ = MessageFactory('photoprint')
 
 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)