Commit ebdeaffa authored by Rafael Monnerat's avatar Rafael Monnerat

slapos_subscription_request: Make creation of the user more resilient

   ...to failures on password generation
parent 56149d16
Pipeline #32956 passed with stage
in 0 seconds
from zExceptions import Unauthorized from zExceptions import Unauthorized
from erp5.component.module.Log import log
import random, string import random, string
if REQUEST is not None: if REQUEST is not None:
...@@ -30,11 +31,20 @@ for role in ['member', 'subscriber']: ...@@ -30,11 +31,20 @@ for role in ['member', 'subscriber']:
login = person.newContent( login = person.newContent(
portal_type="ERP5 Login", portal_type="ERP5 Login",
reference="%s-FIRST-SUBSCRIBER-LOGIN" % person.getUserId(), reference="%s-FIRST-SUBSCRIBER-LOGIN" % person.getUserId())
password=context.Person_generatePassword())
login.validate() for _ in range(5):
try:
login.setPassword(person.Person_generatePassword())
break
except ValueError:
# Skip the generated password wasnt acceptable let it try again.
log("Set password failed, try few more times")
if not login.getPassword():
raise ValueError("We could not set a proper password.")
login.validate()
# The rest of the information will be used later. # The rest of the information will be used later.
person.SubscriptionRequest_saveTransactionalUser(person) person.SubscriptionRequest_saveTransactionalUser(person)
......
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