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 from Products.ERP5Type.TransactionalVariable import getTransactionalVariable
def SubscriptionRequest_saveTransactionalUser(self, person): def SubscriptionRequest_saveTransactionalUser(self, person=None):
if person.getPortalType() == "Person": if person.getPortalType() == "Person":
getTransactionalVariable()["transactional_user"] = person getTransactionalVariable()["transactional_user"] = person
return person return person
......
...@@ -19,4 +19,6 @@ user_input_dict = { ...@@ -19,4 +19,6 @@ user_input_dict = {
"amount" : amount} "amount" : amount}
return context.SubscriptionRequestModule_requestSubscritptionProxy( 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 @@ ...@@ -50,7 +50,7 @@
</item> </item>
<item> <item>
<key> <string>_params</string> </key> <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>
<item> <item>
<key> <string>id</string> </key> <key> <string>id</string> </key>
......
...@@ -4,8 +4,20 @@ if REQUEST is not None: ...@@ -4,8 +4,20 @@ if REQUEST is not None:
raise Unauthorized raise Unauthorized
# You always needs a user here # 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( subscription_request = context.subscription_request_module.newContent(
portal_type="Subscription Request", portal_type="Subscription Request",
...@@ -17,6 +29,7 @@ subscription_request.setDefaultEmailText(email) ...@@ -17,6 +29,7 @@ subscription_request.setDefaultEmailText(email)
def wrapWithShadow(subscription_request, amount, subscription_reference): def wrapWithShadow(subscription_request, amount, subscription_reference):
subscription_request.activate(tag="subscription_condition_%s" % subscription_request.getId() subscription_request.activate(tag="subscription_condition_%s" % subscription_request.getId()
).SubscriptionRequest_applyCondition(subscription_reference) ).SubscriptionRequest_applyCondition(subscription_reference)
return subscription_request.SubscriptionRequest_requestPaymentTransaction(amount=amount, return subscription_request.SubscriptionRequest_requestPaymentTransaction(amount=amount,
tag="subscription_%s" % subscription_request.getId()) tag="subscription_%s" % subscription_request.getId())
...@@ -31,8 +44,7 @@ if batch_mode: ...@@ -31,8 +44,7 @@ if batch_mode:
def wrapRedirectWithShadow(payment_transaction, web_site): def wrapRedirectWithShadow(payment_transaction, web_site):
return payment_transaction.PaymentTransaction_redirectToManualPayzenPayment(web_site) return payment_transaction.PaymentTransaction_redirectToManualPayzenPayment(web_site)
return person.Person_restrictMethodAsShadowUser( return person.Person_restrictMethodAsShadowUser(
shadow_document=person, shadow_document=person,
callable_object=wrapRedirectWithShadow, callable_object=wrapRedirectWithShadow,
argument_list=[payment, context.getWebSiteValue()]) argument_list=[payment, web_site])
...@@ -50,7 +50,7 @@ ...@@ -50,7 +50,7 @@
</item> </item>
<item> <item>
<key> <string>_params</string> </key> <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>
<item> <item>
<key> <string>_proxy_roles</string> </key> <key> <string>_proxy_roles</string> </key>
......
from zExceptions import Unauthorized from zExceptions import Unauthorized
import random, string
if REQUEST is not None: if REQUEST is not None:
raise Unauthorized raise Unauthorized
portal = context.getPortalObject()
portal = context.getPortalObject()
person = portal.portal_membership.getAuthenticatedMember().getUserValue() person = portal.portal_membership.getAuthenticatedMember().getUserValue()
if person is None: if person is not None:
# Create a Person document in order to generate the invoice. # Person already existed
person = portal.person_module.newContent( 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", portal_type="Person",
default_email_text=email, 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", login.validate()
reference=email,
# Please generate a LAAARGE random password.
password=email)
login.validate() # The rest of the information will be used later.
person.validate() person.SubscriptionRequest_saveTransactionalUser(person)
person.SubscriptionRequest_saveTransactionalUser(person) # New user is created
return person 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