From 892f2331deaab36f1bb2c41b850939cc4eeb8ce3 Mon Sep 17 00:00:00 2001 From: Jocelyn Fiat Date: Wed, 3 Feb 2016 23:16:05 +0100 Subject: [PATCH] Do not set destination query parameter to any account/auth url. Set "site_sign_in_url" and "site_sign_out_url" as variables (so it could be used by template). --- modules/auth/cms_auth_module_i.e | 4 +- modules/auth/cms_authentication_module.e | 49 +++++++++++++++++++----- 2 files changed, 42 insertions(+), 11 deletions(-) diff --git a/modules/auth/cms_auth_module_i.e b/modules/auth/cms_auth_module_i.e index 8ca01ba..d3fdee3 100644 --- a/modules/auth/cms_auth_module_i.e +++ b/modules/auth/cms_auth_module_i.e @@ -68,9 +68,9 @@ feature -- Hooks l_destination: READABLE_STRING_8 do if attached {WSF_STRING} a_response.request.query_parameter ("destination") as p_destination then - l_destination := p_destination.url_encoded_value + l_destination := p_destination.value else - l_destination := percent_encoded (a_response.location) + l_destination := a_response.location end if is_authenticating (a_response) then diff --git a/modules/auth/cms_authentication_module.e b/modules/auth/cms_authentication_module.e index 41b1591..0fac49a 100644 --- a/modules/auth/cms_authentication_module.e +++ b/modules/auth/cms_authentication_module.e @@ -1,7 +1,7 @@ note description: "Module Auth" - date: "$Date: 2015-05-20 06:50:50 -0300 (mi. 20 de may. de 2015) $" - revision: "$Revision: 97328 $" + date: "$Date$" + revision: "$Revision$" class CMS_AUTHENTICATION_MODULE @@ -79,6 +79,10 @@ feature -- Access: docs feature -- Router + roc_login_location: STRING = "account/roc-login" + + roc_logout_location: STRING = "account/roc-logout" + setup_router (a_router: WSF_ROUTER; a_api: CMS_API) -- do @@ -97,8 +101,8 @@ feature -- Router a_router.map (m, a_router.methods_head_get) - a_router.handle ("/account/roc-login", create {WSF_URI_AGENT_HANDLER}.make (agent handle_login(a_api, ?, ?)), a_router.methods_head_get) - a_router.handle ("/account/roc-logout", create {WSF_URI_AGENT_HANDLER}.make (agent handle_logout(a_api, ?, ?)), a_router.methods_head_get) + a_router.handle ("/" + roc_login_location, create {WSF_URI_AGENT_HANDLER}.make (agent handle_login(a_api, ?, ?)), a_router.methods_head_get) + a_router.handle ("/" + roc_logout_location, create {WSF_URI_AGENT_HANDLER}.make (agent handle_logout(a_api, ?, ?)), a_router.methods_head_get) a_router.handle ("/account/roc-register", create {WSF_URI_AGENT_HANDLER}.make (agent handle_register(a_api, ?, ?)), a_router.methods_get_post) a_router.handle ("/account/activate/{token}", create {WSF_URI_TEMPLATE_AGENT_HANDLER}.make (agent handle_activation(a_api, ?, ?)), a_router.methods_head_get) a_router.handle ("/account/reject/{token}", create {WSF_URI_TEMPLATE_AGENT_HANDLER}.make (agent handle_reject(a_api, ?, ?)), a_router.methods_head_get) @@ -128,8 +132,35 @@ feature -- Hooks configuration value_table_alter (a_value: CMS_VALUE_TABLE; a_response: CMS_RESPONSE) -- + local + l_destination: detachable READABLE_STRING_GENERAL + l_url: STRING + l_url_name: READABLE_STRING_GENERAL do - a_value.force (a_response.user, "user") + if attached {WSF_STRING} a_response.request.query_parameter ("destination") as p_destination then + l_destination := p_destination.value + else + l_destination := a_response.location + end + if l_destination.starts_with ("account/auth/") then + l_destination := Void + end + + if attached a_response.user as u then + a_value.force (u, "user") + + l_url_name := "site_sign_out_url" + l_url := a_response.url (roc_logout_location, Void) + else + a_value.force (Void, "user") + + l_url_name := "site_sign_in_url" + l_url := a_response.url (roc_login_location, Void) + end + if l_destination /= Void then + l_url.append ("?destination=" + percent_encoded (l_destination)) + end + a_value.force (l_url, l_url_name) end menu_system_alter (a_menu_system: CMS_MENU_SYSTEM; a_response: CMS_RESPONSE) @@ -143,14 +174,14 @@ feature -- Hooks configuration lnk.set_weight (97) a_menu_system.primary_menu.extend (lnk) - create lnk.make ("Logout", "account/roc-logout") + create lnk.make ("Logout", roc_logout_location) else - create lnk.make ("Login", "account/roc-login") + create lnk.make ("Login", roc_login_location) end lnk.set_weight (98) if a_response.location.starts_with_general ("account/auth/") - or a_response.location.starts_with_general ("account/roc-log") + or a_response.location.starts_with_general ("account/roc-log") -- in ou out then -- ignore destination else @@ -199,7 +230,7 @@ feature -- Handler r.set_main_content (b) if l_user = Void then - r.set_redirection ("account/roc-login") + r.set_redirection (roc_login_location) end r.execute end