Commit 3b98ce30 authored by Gabriel Monnerat's avatar Gabriel Monnerat

refactor script to allow create Credential Recoveries when question and answer are None.

parent 6996139b
...@@ -55,11 +55,18 @@ ...@@ -55,11 +55,18 @@
Proxy : Manager proxy role is required to make possible for \n Proxy : Manager proxy role is required to make possible for \n
anonymous to create a new Credential Recovery\n anonymous to create a new Credential Recovery\n
\'\'\'\n \'\'\'\n
def createCredentialRecovery(**kw):\n
module = portal.getDefaultModule(portal_type=\'Credential Recovery\')\n
credential_recovery = module.newContent(\n
\t\tportal_type="Credential Recovery",\n
**kw)\n
credential_recovery.submit()\n
\n
portal = context.getPortalObject()\n portal = context.getPortalObject()\n
person_module = portal.getDefaultModule(\'Person\')\n person_module = portal.getDefaultModule(\'Person\')\n
result = person_module.searchFolder(reference=reference)\n result = person_module.searchFolder(reference=reference)\n
if len(result) != 1:\n if len(result) != 1:\n
portal_status_message = portal.Base_translateString("Can\'t find corresponding person, it\'s not possible to update your credentials.")\n portal_status_message = portal.Base_translateString("Can\'t find corresponding person, it\'s not possible to recovery your credentials.")\n
return context.Base_redirect(\'\', keep_items = dict(portal_status_message=portal_status_message ))\n return context.Base_redirect(\'\', keep_items = dict(portal_status_message=portal_status_message ))\n
\n \n
person = result[0].getObject()\n person = result[0].getObject()\n
...@@ -67,22 +74,23 @@ person = result[0].getObject()\n ...@@ -67,22 +74,23 @@ person = result[0].getObject()\n
# Check the response\n # Check the response\n
question_free_text = person.getDefaultCredentialQuestionQuestionFreeText()\n question_free_text = person.getDefaultCredentialQuestionQuestionFreeText()\n
question_title = person.getDefaultCredentialQuestionQuestionTitle()\n question_title = person.getDefaultCredentialQuestionQuestionTitle()\n
question_answer = person.getDefaultCredentialQuestionAnswer().lower()\n question_answer = person.getDefaultCredentialQuestionAnswer()\n
question_answer = question_answer and question_answer.lower()\n
answer = default_credential_question_answer and default_credential_question_answer.lower() or \'\'\n answer = default_credential_question_answer and default_credential_question_answer.lower() or \'\'\n
\n \n
if (question_title or question_title) and (answer == question_answer):\n keep_items = {}\n
# create the credential recovery\n message = "Credential Recovery Created."\n
module = portal.getDefaultModule(portal_type=\'Credential Recovery\')\n dialog_id = dialog_id or "login_form"\n
credential_recovery = module.newContent(\n \n
\t\tportal_type="Credential Recovery",\n if question_title and (answer == question_answer):\n
reference=reference,\n createCredentialRecovery(reference=reference,\n
default_credential_question_answer=default_credential_question_answer,\n default_credential_question_answer=default_credential_question_answer,\n
destination_decision=person.getRelativeUrl(),\n destination_decision=person.getRelativeUrl(),\n
language=portal.Localizer.get_selected_language())\n language=portal.Localizer.get_selected_language())\n
credential_recovery.submit()\n elif question_free_text is None and question_answer is None:\n
message = "Credential Recovery Created."\n createCredentialRecovery(reference=reference,\n
keep_items = {}\n destination_decision=person.getRelativeUrl(),\n
dialog_id = \'login_form\'\n language=portal.Localizer.get_selected_language())\n
else:\n else:\n
message = "You didn\'t enter the correct answer."\n message = "You didn\'t enter the correct answer."\n
keep_items = {\'default_credential_question_question_free_text\': question_free_text,\n keep_items = {\'default_credential_question_question_free_text\': question_free_text,\n
...@@ -90,7 +98,7 @@ else:\n ...@@ -90,7 +98,7 @@ else:\n
\'reference\': reference}\n \'reference\': reference}\n
\n \n
keep_items[\'portal_status_message\'] = portal.Base_translateString(message)\n keep_items[\'portal_status_message\'] = portal.Base_translateString(message)\n
return context.Base_redirect(dialog_id, keep_items = keep_items)\n return context.Base_redirect(dialog_id, keep_items=keep_items)\n
</string> </value> </string> </value>
</item> </item>
<item> <item>
......
353 354
\ No newline at end of file \ 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