Implémentation de la remise.
[photoprint.git] / skins / customer_add_control.py
1 ##parameters=**kw
2 from Products.CMFCore.utils import getToolByName
3 from Products.photoprint.utils import translate
4 from Products.CMFDefault.utils import translate as cmf_translate
5 from Products.CMFCore.exceptions import AccessControl_Unauthorized
6 from Products.Plinn.RegistrationTool import MODE_PASS_ANONYMOUS
7 rtool = getToolByName(context, 'portal_registration')
8 ptool = getToolByName(context, 'portal_properties')
9 _ = lambda msg : translate(msg, context)
10
11 kg = lambda name : kw.get(name, '').strip()
12
13 cmfprops = {'username' : kg('member_id')
14 ,'email' : kg('member_email')}
15
16 failMessage = rtool.testPropertiesValidity(cmfprops)
17 if failMessage is not None :
18 return context.setStatus(False, cmf_translate(failMessage, context))
19
20 mandatoryFields = [
21 ('given_name', _('Please enter a given name.'))
22 , ('name', _('Please enter a name.'))
23 , ('member_email', _('Please enter an email.'))
24 , ('member_id', _('Please enter a member id.'))
25 , ('billing_address', _('Please enter a billing address.'))
26 , ('billing_city', _('Please enter a city.'))
27 , ('billing_zipcode', _('Please enter zip code.'))
28 , ('country', _('Please enter a country.'))
29 , ('phone', _('Please enter a phone.'))
30 ]
31
32 for name, failMessage in mandatoryFields :
33 value = kg(name)
34 if not value :
35 return context.setStatus(False, failMessage)
36
37
38 try:
39 rtool.addMember( id=kg('member_id'),
40 password=kg('password'),
41 properties={'username' : kg('member_id')
42 ,'given_name' : kg('given_name')
43 ,'name' : kg('name')
44 ,'email' : kg('member_email')
45 ,'billing_address' : kg('billing_address')
46 ,'billing_city' : kg('billing_city')
47 ,'billing_zipcode' : kg('billing_zipcode')
48 ,'country' : kg('country')
49 ,'phone' : kg('phone')
50 ,'collection_id' : kg('collection_id')
51 ,'collection_password': kg('collection_password')} )
52 except ValueError, errmsg:
53 return context.setStatus(False, _(errmsg))
54 except AccessControl_Unauthorized :
55 if rtool.getMode() == MODE_PASS_ANONYMOUS :
56 return context.setStatus(False, _('Wrong private collection credentials.'))
57 raise
58
59
60 if kg('send_password') or ptool.getProperty('validate_email') :
61 rtool.registeredNotify(kg('member_id'))
62
63 return context.setStatus(True, 'Success!')