Commit c201450a authored by Fabien Morin's avatar Fabien Morin

* add a script generateNewLogin to generate new login (remove spaces and...

* add a script generateNewLogin to generate new login (remove spaces and accents, add a number at the end if the login already exists, ...)
* send credentials using portal_notification

git-svn-id: https://svn.erp5.org/repos/public/erp5/trunk@24260 20353a03-c40f-0410-a6d1-a30d3c3de9de
parent 4378fdb3
from zLOG import LOG
def sendCrendentialsByEMail(self, login, password, user_email):
activity_tool = self.getPortalObject().portal_activities
from Products.MailHost.MailHost import MailHostError
from Products.CMFActivity.ActivityTool import Message
import socket
portal = activity_tool.getPortalObject()
mail_text="""From: %s
To: %s
Subject: %s
Thanks for registrering to SAFI, now you can connect in on www.safi.sn with the followin credentials :
Login: %s
Password: %s
""" % ('no-reply@safi.sn', user_email, 'your credential for www.safi.sn',
login, password)
try:
activity_tool.MailHost.send( mail_text )
except (socket.error, MailHostError), message:
LOG('ActivityTool.notifyUser', 0, 'Mail containing failure information failed to be sent: %s.' % (message))
def getPoralTypeListForWorkflow(self, workflow):
'''
return a list of portal_types that use workflow
......
......@@ -24,7 +24,9 @@
<item>
<key> <string>activate_script_name</string> </key>
<value>
<tuple/>
<list>
<string>sendCrendentialsByEMail</string>
</list>
</value>
</item>
<item>
......
......@@ -72,21 +72,17 @@ if not len(result):\n
address_city=changed_object.getAddressCity(),\n
address_region=changed_object.getAddressRegion(),\n
corporate_registration_code=changed_object.getRccm(),\n
vat_code=changed_object.getNinea())\n
vat_code=changed_object.getNinea(),\n
default_email_text=changed_object.getEmail()\n
)\n
else:\n
organisation = result[0].getObject()\n
\n
# set the login and password required a manager role, so a script with a \n
# proxy role is used\n
login = changed_object.getCompanyName().lower()\n
login = context.generateNewLogin(text=changed_object.getCompanyName())\n
password = changed_object.Person_generatePassword()\n
context.EGov_setLoginAndPasswordAsManager(organisation, login, password)\n
\n
# here, call a method to send credentials by email\n
# XXX in the future, it should be possible to chose the mean to receive\n
# credentials (email, sms, postal mail)\n
user_email = changed_object.getEmail()\n
context.sendCrendentialsByEMail(login, password, user_email)\n
</string> </value>
</item>
<item>
......@@ -138,10 +134,9 @@ context.sendCrendentialsByEMail(login, password, user_email)\n
<string>result</string>
<string>len</string>
<string>organisation</string>
<string>context</string>
<string>login</string>
<string>password</string>
<string>context</string>
<string>user_email</string>
</tuple>
</value>
</item>
......
......@@ -66,18 +66,16 @@ from Products.DCWorkflow.DCWorkflow import ValidationFailed\n
result = portal_catalog( portal_type=\'Organisation\',\n
vat_code=changed_object.getNinea())\n
\n
\n
if len(result) > 1:\n
raise ValidationFailed, "Error : There is more than one company with the "\\\n
" NINEA code \'%s\'" % ninea \n
msg = "Error : There is more than one company with the NINEA code ${code}"\n
msg = translateString(msg, mapping=dict(code=ninea))\n
raise ValidationFailed, msg \n
\n
if len(result) == 1 and result[0].getObject().getReference():\n
raise ValidationFailed, "Error : A company with the NINEA code \'%s\'"\\\n
" already exists and have already an account" % ninea\n
\n
if len((changed_object.portal_catalog(portal_type=\'Organisation\',\n
reference=login))):\n
raise ValidationFailed, "Error : A company with the login \'%s\'"\\\n
" already exists" % login\n
msg = "Error : A company with the NINEA code ${code} already exists and have already an account"\n
msg = translateString(msg, mapping=dict(code=ninea))\n
raise ValidationFailed, msg\n
]]></string> </value>
......@@ -135,6 +133,9 @@ if len((changed_object.portal_catalog(portal_type=\'Organisation\',\n
<string>ValidationFailed</string>
<string>result</string>
<string>len</string>
<string>msg</string>
<string>translateString</string>
<string>dict</string>
</tuple>
</value>
</item>
......
<?xml version="1.0"?>
<ZopeData>
<record id="1" aka="AAAAAAAAAAE=">
<pickle>
<tuple>
<global name="PythonScript" module="Products.PythonScripts.PythonScript"/>
<tuple/>
</tuple>
</pickle>
<pickle>
<dictionary>
<item>
<key> <string>Script_magic</string> </key>
<value> <int>3</int> </value>
</item>
<item>
<key> <string>_bind_names</string> </key>
<value>
<object>
<klass>
<global name="NameAssignments" module="Shared.DC.Scripts.Bindings"/>
</klass>
<tuple/>
<state>
<dictionary>
<item>
<key> <string>_asgns</string> </key>
<value>
<dictionary>
<item>
<key> <string>name_container</string> </key>
<value> <string>container</string> </value>
</item>
<item>
<key> <string>name_context</string> </key>
<value> <string>context</string> </value>
</item>
<item>
<key> <string>name_m_self</string> </key>
<value> <string>script</string> </value>
</item>
<item>
<key> <string>name_subpath</string> </key>
<value> <string>traverse_subpath</string> </value>
</item>
</dictionary>
</value>
</item>
</dictionary>
</state>
</object>
</value>
</item>
<item>
<key> <string>_body</string> </key>
<value> <string encoding="cdata"><![CDATA[
\'\'\'\n
This script remove accents and spaces and other things from the text to generate a new login\n
\'\'\'\n
\n
inc = 1\n
new_login = login\n
\n
# XXX here it should be possible to use a regular expression\n
login = text.lower()\n
login = login.replace(\' \', \'_\')\n
login = login.replace(\'\xc3\xa9\', \'e\')\n
login = login.replace(\'\xc3\xa8\', \'e\')\n
login = login.replace(\'\xc3\xa0\', \'a\')\n
login = login.replace(\'\xc3\xa7\', \'c\')\n
\n
# search if the login already exists\n
result = context.portal_catalog(reference=login)\n
\n
while len(result) > 0:\n
\n
if new_login.rfind(\'-\'):\n
# if a number has already been added to the end of the login, increase it\n
if new_login[new_login.rfind(\'-\')+1:].isdigit():\n
inc = int(new_login[new_login.rfind(\'-\')+1:]) + 1\n
\n
new_login = \'%s-%s\' % (login, inc)\n
result = context.portal_catalog(reference=new_login)\n
\n
return new_login\n
]]></string> </value>
</item>
<item>
<key> <string>_code</string> </key>
<value>
<none/>
</value>
</item>
<item>
<key> <string>_params</string> </key>
<value> <string>text</string> </value>
</item>
<item>
<key> <string>errors</string> </key>
<value>
<tuple/>
</value>
</item>
<item>
<key> <string>func_code</string> </key>
<value>
<object>
<klass>
<global name="FuncCode" module="Shared.DC.Scripts.Signature"/>
</klass>
<tuple/>
<state>
<dictionary>
<item>
<key> <string>co_argcount</string> </key>
<value> <int>1</int> </value>
</item>
<item>
<key> <string>co_varnames</string> </key>
<value>
<tuple>
<string>text</string>
<string>inc</string>
<string>login</string>
<string>new_login</string>
<string>_getattr_</string>
<string>context</string>
<string>result</string>
<string>len</string>
<string>_getitem_</string>
<string>int</string>
</tuple>
</value>
</item>
</dictionary>
</state>
</object>
</value>
</item>
<item>
<key> <string>func_defaults</string> </key>
<value>
<none/>
</value>
</item>
<item>
<key> <string>id</string> </key>
<value> <string>generateNewLogin</string> </value>
</item>
<item>
<key> <string>warnings</string> </key>
<value>
<tuple/>
</value>
</item>
</dictionary>
</pickle>
</record>
</ZopeData>
......@@ -3,27 +3,186 @@
<record id="1" aka="AAAAAAAAAAE=">
<pickle>
<tuple>
<global name="ExternalMethod" module="Products.ExternalMethod.ExternalMethod"/>
<global name="PythonScript" module="Products.PythonScripts.PythonScript"/>
<tuple/>
</tuple>
</pickle>
<pickle>
<dictionary>
<item>
<key> <string>_function</string> </key>
<value> <string>sendCrendentialsByEMail</string> </value>
<key> <string>Script_magic</string> </key>
<value> <int>3</int> </value>
</item>
<item>
<key> <string>_bind_names</string> </key>
<value>
<object>
<klass>
<global name="NameAssignments" module="Shared.DC.Scripts.Bindings"/>
</klass>
<tuple/>
<state>
<dictionary>
<item>
<key> <string>_asgns</string> </key>
<value>
<dictionary>
<item>
<key> <string>name_container</string> </key>
<value> <string>container</string> </value>
</item>
<item>
<key> <string>name_context</string> </key>
<value> <string>context</string> </value>
</item>
<item>
<key> <string>name_m_self</string> </key>
<value> <string>script</string> </value>
</item>
<item>
<key> <string>name_subpath</string> </key>
<value> <string>traverse_subpath</string> </value>
</item>
</dictionary>
</value>
</item>
</dictionary>
</state>
</object>
</value>
</item>
<item>
<key> <string>_body</string> </key>
<value> <string encoding="cdata"><![CDATA[
"""\n
This script tries to send a message containing the credentials to the\n
organisation. It uses portal_notifications and the getObject API of ERP5Catalog.\n
"""\n
object = state_change[\'object\']\n
\n
translateString = object.Base_translateString\n
portal_catalog = object.portal_catalog\n
\n
# get the new organisation :\n
result = portal_catalog(portal_type=\'Organisation\',\n
vat_code=object.getNinea())\n
\n
if len(result) > 1:\n
msg = "Error : There is more than one company with the NINEA code ${code}"\n
msg = translateString(msg, mapping=dict(code=ninea))\n
raise ValidationFailed, msg \n
\n
if len(result) == 0 and result[0].getObject().getReference():\n
msg = "No organisation with the NINEA code ${code}"\n
msg = translateString(msg, mapping=dict(code=ninea))\n
raise ValidationFailed, msg \n
\n
organisation = result[0]\n
\n
# Build the message and translate it\n
subject = translateString("Your credential for ${site_address}", mapping=dict(site_address=\'www.safi.sn\'))\n
msg = """Thanks for registrering to SAFI, now you can connect in on ${site_address} with this credentials : \n
\n
Login : ${login}\n
Password : ${password}\n
\n
This credentials are usefull to follow your application and more. Please visit ${site_address} for more information.\n
"""\n
msg = translateString(msg,\n
mapping=dict(site_address=\'www.safi.sn\',\n
login=organisation.getReference(),\n
password=organisation.getPassword())\n
)\n
\n
# We can now notify the owner through the notification tool\n
object.portal_notifications.sendMessage(sender=\'no-reply\',\n
recipient=organisation.getReference(), subject=subject, message=msg,\n
portal_type_list=(\'Person\', \'Organisation\'))\n
]]></string> </value>
</item>
<item>
<key> <string>_code</string> </key>
<value>
<none/>
</value>
</item>
<item>
<key> <string>_params</string> </key>
<value> <string>state_change</string> </value>
</item>
<item>
<key> <string>_proxy_roles</string> </key>
<value>
<tuple>
<string>Assignor</string>
<string>Manager</string>
</tuple>
</value>
</item>
<item>
<key> <string>errors</string> </key>
<value>
<tuple/>
</value>
</item>
<item>
<key> <string>func_code</string> </key>
<value>
<object>
<klass>
<global name="FuncCode" module="Shared.DC.Scripts.Signature"/>
</klass>
<tuple/>
<state>
<dictionary>
<item>
<key> <string>co_argcount</string> </key>
<value> <int>1</int> </value>
</item>
<item>
<key> <string>co_varnames</string> </key>
<value>
<tuple>
<string>state_change</string>
<string>_getitem_</string>
<string>object</string>
<string>_getattr_</string>
<string>translateString</string>
<string>portal_catalog</string>
<string>result</string>
<string>len</string>
<string>msg</string>
<string>dict</string>
<string>ninea</string>
<string>ValidationFailed</string>
<string>organisation</string>
<string>subject</string>
</tuple>
</value>
</item>
</dictionary>
</state>
</object>
</value>
</item>
<item>
<key> <string>_module</string> </key>
<value> <string>ERP5EGov_Extensions</string> </value>
<key> <string>func_defaults</string> </key>
<value>
<none/>
</value>
</item>
<item>
<key> <string>id</string> </key>
<value> <string>sendCrendentialsByEMail</string> </value>
</item>
<item>
<key> <string>title</string> </key>
<value> <string></string> </value>
<key> <string>warnings</string> </key>
<value>
<tuple/>
</value>
</item>
</dictionary>
</pickle>
......
2008-10-20 fabien
* update ERP5Site_getSecurityFromLatestWorkflowHistory to remove workflow hardcoded value
* add a script generateNewLogin to generate new login (remove spaces and accents, add a number at the end if the login already exists, ...)
* send credentials using portal_notification
2008-10-16 fabien
* change css to have all the tabs of the forms (actions) on the right instead of have the first on right and the others in the middle
......
409
\ No newline at end of file
411
\ No newline at end of file
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment