Commit 75c745c4 authored by Rafael Monnerat's avatar Rafael Monnerat

slapos_subscription_request: Rework subscription to consider that it is a...

slapos_subscription_request: Rework subscription to consider that it is a second subscription of a user

Don't set email as login too soon, this is a task for later.
parent dd4510e3
from Products.ERP5Type.TransactionalVariable import getTransactionalVariable
def SubscriptionRequest_saveTransactionalUser(self, person):
def SubscriptionRequest_saveTransactionalUser(self, person=None):
if person.getPortalType() == "Person":
getTransactionalVariable()["transactional_user"] = person
return person
......
......@@ -19,4 +19,6 @@ user_input_dict = {
"amount" : amount}
return context.SubscriptionRequestModule_requestSubscritptionProxy(
default_email_text, subscription_reference, user_input_dict=user_input_dict, batch_mode=0)
default_email_text, subscription_reference,
confirmation_required=bool(confirmation_required),
user_input_dict=user_input_dict, batch_mode=0)
......@@ -50,7 +50,7 @@
</item>
<item>
<key> <string>_params</string> </key>
<value> <string>name=None, default_email_text=None, subscription_reference=None, amount=0, REQUEST=None, **kw</string> </value>
<value> <string>name=None, default_email_text=None, subscription_reference=None, amount=0, confirmation_required=True, REQUEST=None, **kw</string> </value>
</item>
<item>
<key> <string>id</string> </key>
......
......@@ -4,8 +4,20 @@ if REQUEST is not None:
raise Unauthorized
# You always needs a user here
person = context.SubscriptionRequest_createUser(email, user_input_dict['name'])
person, person_is_new = context.SubscriptionRequest_createUser(email, user_input_dict['name'])
web_site = context.getWebSiteValue()
# Check if user is already exist, otherwise redirect to ask confirmation
if confirmation_required and not person_is_new:
base_url = web_site.absolute_url()
return context.REQUEST.RESPONSE.redirect(
"%s/#order_confirmation?name=%s&email=%s&amount=%s&subscription_reference=%s" % (
base_url,
person.getTitle(),
person.getDefaultEmailText(),
user_input_dict["amount"],
subscription_reference))
subscription_request = context.subscription_request_module.newContent(
portal_type="Subscription Request",
......@@ -17,6 +29,7 @@ subscription_request.setDefaultEmailText(email)
def wrapWithShadow(subscription_request, amount, subscription_reference):
subscription_request.activate(tag="subscription_condition_%s" % subscription_request.getId()
).SubscriptionRequest_applyCondition(subscription_reference)
return subscription_request.SubscriptionRequest_requestPaymentTransaction(amount=amount,
tag="subscription_%s" % subscription_request.getId())
......@@ -31,8 +44,7 @@ if batch_mode:
def wrapRedirectWithShadow(payment_transaction, web_site):
return payment_transaction.PaymentTransaction_redirectToManualPayzenPayment(web_site)
return person.Person_restrictMethodAsShadowUser(
shadow_document=person,
callable_object=wrapRedirectWithShadow,
argument_list=[payment, context.getWebSiteValue()])
argument_list=[payment, web_site])
......@@ -50,7 +50,7 @@
</item>
<item>
<key> <string>_params</string> </key>
<value> <string>email, subscription_reference, user_input_dict={}, batch_mode=True, REQUEST=None</string> </value>
<value> <string>email, subscription_reference, confirmation_required=False, user_input_dict={}, batch_mode=True, REQUEST=None</string> </value>
</item>
<item>
<key> <string>_proxy_roles</string> </key>
......
from zExceptions import Unauthorized
import random, string
if REQUEST is not None:
raise Unauthorized
portal = context.getPortalObject()
portal = context.getPortalObject()
person = portal.portal_membership.getAuthenticatedMember().getUserValue()
if person is None:
# Create a Person document in order to generate the invoice.
person = portal.person_module.newContent(
if person is not None:
# Person already existed
return person, False
# Already has login with this.
erp5_login = portal.portal_catalog.getResultValue(portal_type="ERP5 Login",
reference=email, validation_state="validated")
if erp5_login is not None:
return erp5_login.getParentValue(), False
# Already has login with this.
person = portal.portal_catalog.getResultValue(
portal_type="Person",
default_email_text=email,
first_name=name)
validation_state="validated")
if person is not None:
return person, False
# Create a Person document in order to generate the invoice.
person = portal.person_module.newContent(
portal_type="Person",
first_name=name)
chars = string.ascii_letters + string.digits + '!@#$%^&*()'
login = person.newContent(
portal_type="ERP5 Login",
reference=person.getUserId(),
# Please generate a LAAARGE random password.
password=''.join(random.choice(chars) for i in range(13)))
login = person.newContent(portal_type="ERP5 Login",
reference=email,
# Please generate a LAAARGE random password.
password=email)
login.validate()
login.validate()
person.validate()
# The rest of the information will be used later.
person.SubscriptionRequest_saveTransactionalUser(person)
person.SubscriptionRequest_saveTransactionalUser(person)
return person
# New user is created
return person, True
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