note description: "Summary description for {ES_CLOUD_LICENSES_HANDLER}." date: "$Date$" revision: "$Revision$" class ES_CLOUD_LICENSES_HANDLER inherit CMS_HANDLER rename make as make_with_cms_api end WSF_URI_TEMPLATE_HANDLER create make feature {NONE} -- Initialization make (a_mod: ES_CLOUD_MODULE; a_mod_api: ES_CLOUD_API) do es_cloud_module := a_mod make_with_cms_api (a_mod_api.cms_api) es_cloud_api := a_mod_api end feature -- API es_cloud_module: ES_CLOUD_MODULE es_cloud_api: ES_CLOUD_API feature -- Execution execute (req: WSF_REQUEST; res: WSF_RESPONSE) -- Execute handler for `req' and respond in `res'. do if req.is_get_request_method then if attached req.path_parameter ("license_key") as l_lic_key then if req.path_info.ends_with_general ("/billing/") then process_license_billing_get (l_lic_key.string_representation, req, res) else process_license_get (l_lic_key.string_representation, req, res) end elseif attached {WSF_STRING} req.query_parameter ("op") as p_op and then p_op.is_case_insensitive_equal ("buy") then res.redirect_now (api.absolute_url (req.percent_encoded_path_info + "_/buy/", Void)) elseif attached {WSF_STRING} req.path_parameter ("action") as p_action and then p_action.is_case_insensitive_equal ("buy") then process_post (req, res) else process_get (req, res) end elseif req.is_post_request_method then process_post (req, res) else send_bad_request (req, res) end end process_post (req: WSF_REQUEST; res: WSF_RESPONSE) local r: like new_generic_response s: STRING_8 -- l_plan: ES_CLOUD_PLAN do r := new_generic_response (req, res) create s.make_empty if attached api.user as u and then attached {WSF_STRING} req.query_parameter ("request") as s_request and then s_request.is_case_insensitive_equal ("trial") then if es_cloud_api.config.auto_trial_enabled then if not attached es_cloud_api.user_licenses (u) as lics or else lics.is_empty then s.append ("

Trial period requested

") es_cloud_api.auto_assign_trial_to (u) r.set_redirection (api.absolute_url (req.percent_encoded_path_info, Void)) else s.append ("

You can not request for a new trial.

") end else s.append ("

No trial period available for now!

") end else r.add_style (r.module_name_resource_url ({ES_CLOUD_MODULE}.name, "/files/css/es_cloud.css", Void), Void) s.append ("

Buy a license

") if attached es_cloud_module.new_store_block (es_cloud_api, r) as bl then r.add_block (bl, "content") r.add_style (r.module_resource_url (es_cloud_module, "/files/css/pricing.css", Void), Void) end end r.set_main_content (s) r.execute end process_license_get (a_lic_key: READABLE_STRING_GENERAL; req: WSF_REQUEST; res: WSF_RESPONSE) local l_lic_user, l_user: ES_CLOUD_USER r: like new_generic_response s: STRING do if attached api.user as u then l_user := u end if attached es_cloud_api.license_by_key (a_lic_key) as lic then l_lic_user := es_cloud_api.user_for_license (lic) if api.has_permissions (<<{ES_CLOUD_MODULE}.perm_manage_es_licenses, {ES_CLOUD_MODULE}.perm_view_es_licenses>>) or else (l_lic_user /= Void and then l_user /= Void and then l_user.same_as (l_lic_user)) then r := new_generic_response (req, res) r.add_javascript_url (r.module_name_resource_url ({ES_CLOUD_MODULE}.name, "/files/js/es_cloud.js", Void)) r.add_style (r.module_name_resource_url ({ES_CLOUD_MODULE}.name, "/files/css/es_cloud.css", Void), Void) r.set_title ("License " + html_encoded (a_lic_key)) s := "" s.append ("
") append_license_to_html (lic, l_lic_user, s) s.append ("
") s.append ("
Billing...
") s.append ("
For any operation on this license, please contact us.
") s.append ("
All licenses...
") if api.has_permission ({ES_CLOUD_MODULE}.perm_manage_es_licenses) then s.append ("
EDIT license
") end s.append ("
") -- info s.append ("
") -- es-licenses r.set_main_content (s) r.execute else send_access_denied (req, res) -- s.append ("
This page is restricted to authorized person!
") end else send_not_found (req, res) end end process_license_billing_get (a_lic_key: READABLE_STRING_GENERAL; req: WSF_REQUEST; res: WSF_RESPONSE) local l_lic_user, l_user: ES_CLOUD_USER r: like new_generic_response s: STRING do if attached api.user as u then l_user := u end if attached es_cloud_api.license_by_key (a_lic_key) as lic then l_lic_user := es_cloud_api.user_for_license (lic) if api.has_permissions (<<{ES_CLOUD_MODULE}.perm_manage_es_licenses, {ES_CLOUD_MODULE}.perm_view_es_licenses>>) or else (l_lic_user /= Void and then l_user /= Void and then l_user.same_as (l_lic_user)) then r := new_generic_response (req, res) r.add_javascript_url (r.module_name_resource_url ({ES_CLOUD_MODULE}.name, "/files/js/es_cloud.js", Void)) r.add_style (r.module_name_resource_url ({ES_CLOUD_MODULE}.name, "/files/css/es_cloud.css", Void), Void) r.set_title ("License " + html_encoded (a_lic_key)) s := "" s.append ("
") append_license_to_html (lic, l_lic_user, s) if attached es_cloud_api.license_billings (lic) as l_billings then s.append ("
") s.append ("
") s.append ("%N") across l_billings as ic loop if attached ic.item as l_bill then s.append ("") s.append ("") s.append ("") s.append ("") s.append ("") s.append ("") s.append ("%N") end end s.append ("
DateItemOrder-idTotalInvoice/Receipt
"+ date_time_to_iso8601_string (l_bill.date) + "") if attached l_bill.title as l_title then s.append (html_encoded (l_title)) end s.append ("") if attached l_bill.order as l_order then s.append (html_encoded (l_order.name)) end s.append ("") if attached l_bill.total_price_as_string as l_total then s.append (html_encoded (l_total)) end s.append ("") if attached l_bill.external_invoice_url as l_url then s.append ("invoice") elseif attached l_bill.external_receipt_url as l_url then s.append ("receipt") end s.append ("
%N") s.append ("
") s.append ("
For any operation on this license, please contact us.
") s.append ("
To cancel your subscription, please contact us.
") s.append ("
") else s.append ("
") s.append ("
No billing information
") s.append ("
For any operation on this license, please contact us.
") s.append ("
") s.append ("%N") end s.append ("
") if api.has_permission ({ES_CLOUD_MODULE}.perm_manage_es_licenses) then s.append ("
EDIT license
") end r.set_main_content (s) r.execute else send_access_denied (req, res) -- s.append ("
This page is restricted to authorized person!
") end else send_not_found (req, res) end end process_get (req: WSF_REQUEST; res: WSF_RESPONSE) local l_user: ES_CLOUD_USER r: like new_generic_response s: STRING l_plan: detachable ES_CLOUD_PLAN l_org: detachable ES_CLOUD_ORGANIZATION ago: DATE_TIME_AGO_CONVERTER l_user_has_no_license: BOOLEAN do r := new_generic_response (req, res) r.add_javascript_url (r.module_name_resource_url ({ES_CLOUD_MODULE}.name, "/files/js/es_cloud.js", Void)) r.add_style (r.module_name_resource_url ({ES_CLOUD_MODULE}.name, "/files/css/es_cloud.css", Void), Void) r.set_title ("EiffelStudio Licenses") s := "" create ago.make if attached api.user as u then create l_user.make (u) s.append ("
Account: "+ api.html_encoded (api.real_user_display_name (u)) +"
") -- Organisations s.append ("
") if attached es_cloud_api.user_organizations (l_user) as l_orgs then across l_orgs as o_ic loop l_org := o_ic.item if es_cloud_api.is_organization_manager (l_user, l_org) then s.append ("

Manager of organization: ") s.append ("") s.append (html_encoded (l_org.title_or_name)) s.append ("

") else s.append ("

Member of organization: ") s.append (html_encoded (l_org.title_or_name)) s.append ("

") end end end s.append ("
") -- Buy new license button -- FIXME: remove when licensing is live ! if api.has_permission ({ES_CLOUD_MODULE}.perm_buy_es_license) then s.append ("
") end if attached l_user.cms_user.email as l_email and then attached es_cloud_api.email_licenses (l_email) as lst and then not lst.is_empty then across lst as ic loop es_cloud_api.move_email_license_to_user (ic.item, l_user) s.append ("
Retrieving license " + html_encoded (ic.item.license.key)) s.append (" ...
") end end -- List of licenses s.append ("
") if attached es_cloud_api.user_licenses (l_user) as lics and then not lics.is_empty then across lics as ic loop if attached ic.item as l_user_lic and then attached l_user_lic.license as lic then append_license_to_html (lic, l_user, s) end end else s.append ("Please subscribe to a license ...") l_user_has_no_license := True if es_cloud_api.config.auto_trial_enabled then s.append ("
Or request a trial period ...") s.append ("
") end end s.append ("
") if l_user_has_no_license and then attached es_cloud_api.user_subscription (l_user) as sub then s.append ("
") l_plan := sub.plan s.append ("

You are subscribed to plan: ") s.append (html_encoded (l_plan.title_or_name)) s.append ("") s.append ("

") s.append ("
") if sub /= Void then if attached {ES_CLOUD_LICENSE} es_cloud_api.converted_license_from_user_subscription (sub, Void) as lic then s.append ("
Subscription converted to license " + html_encoded (lic.key)) s.append ("
") end end end else s.append ("

Please Login or Register...

") end r.set_main_content (s) r.execute end append_license_to_html (lic: ES_CLOUD_LICENSE; u: detachable ES_CLOUD_USER; s: STRING_8) do es_cloud_api.append_license_to_html (lic, u, es_cloud_module, s) end note copyright: "2011-2020, Jocelyn Fiat, Javier Velilla, Eiffel Software and others" license: "Eiffel Forum License v2 (see http://www.eiffel.com/licensing/forum.txt)" end