Fixed "destination" support when login.

(i.e when visitor click on signin from page A, one he is signed, he will be redirected to the initial page A.)
This commit is contained in:
2016-04-13 10:56:28 +02:00
parent 0c7d8af9d7
commit bd3fe63976
6 changed files with 33 additions and 12 deletions

View File

@@ -69,8 +69,8 @@ feature -- Hooks
lnk: CMS_LOCAL_LINK
l_destination: READABLE_STRING_8
do
if attached {WSF_STRING} a_response.request.query_parameter ("destination") as p_destination then
l_destination := p_destination.value
if attached {WSF_STRING} a_response.request.item ("destination") as p_destination then
l_destination := p_destination.url_encoded_value
else
l_destination := a_response.location
end
@@ -88,4 +88,23 @@ feature -- Hooks
end
end
feature {NONE} -- Template
smarty_template_login_block (a_request: WSF_REQUEST; a_module: CMS_MODULE; a_block_id: READABLE_STRING_8; a_cms_api: CMS_API): like smarty_template_block
local
l_destination: detachable READABLE_STRING_32
do
Result := smarty_template_block (a_module, a_block_id, a_cms_api)
if Result /= Void then
if attached {WSF_STRING} a_request.query_parameter ("destination") as p_destination then
l_destination := p_destination.value
elseif attached {WSF_STRING} a_request.form_parameter ("destination") as p_destination then
l_destination := p_destination.value
end
if l_destination /= Void then
Result.set_value (l_destination, "site_destination")
end
end
end
end

View File

@@ -139,7 +139,7 @@ feature -- Hooks configuration
l_url: STRING
l_url_name: READABLE_STRING_GENERAL
do
if attached {WSF_STRING} a_response.request.query_parameter ("destination") as p_destination then
if attached {WSF_STRING} a_response.request.item ("destination") as p_destination then
l_destination := p_destination.value
else
l_destination := a_response.location
@@ -289,7 +289,7 @@ feature -- Handler
elseif attached api.module_by_name ("session_auth") then
-- FIXME: find better solution to support a default login system.
create {GENERIC_VIEW_CMS_RESPONSE} r.make (req, res, api)
if attached {WSF_STRING} req.query_parameter ("destination") as l_destination then
if attached {WSF_STRING} req.item ("destination") as l_destination then
r.set_redirection ("account/auth/roc-session-login?destination=" + l_destination.url_encoded_value)
else
r.set_redirection ("account/auth/roc-session-login")
@@ -300,7 +300,7 @@ feature -- Handler
elseif attached api.module_by_name ("basic_auth") then
-- FIXME: find better solution to support a default login system.
create {GENERIC_VIEW_CMS_RESPONSE} r.make (req, res, api)
if attached {WSF_STRING} req.query_parameter ("destination") as l_destination then
if attached {WSF_STRING} req.item ("destination") as l_destination then
r.set_redirection ("account/auth/roc-basic-login?destination=" + l_destination.url_encoded_value)
else
r.set_redirection ("account/auth/roc-basic-login")

View File

@@ -118,7 +118,7 @@ feature {NONE} -- Implementation: routes
r.add_error_message ("You are already signed in!")
r.set_main_content (r.link ("Logout", "account/roc-logout", Void))
else
if attached smarty_template_block (Current, "login", api) as l_tpl_block then
if attached smarty_template_login_block (req, Current, "login", api) as l_tpl_block then
r.add_javascript_url (r.url ("module/" + name + "/files/js/roc_basic_auth.js", Void))
create vals.make (1)
@@ -170,7 +170,7 @@ feature {NONE} -- Block views
local
vals: CMS_VALUE_TABLE
do
if attached smarty_template_block (Current, a_block_id, a_response.api) as l_tpl_block then
if attached smarty_template_login_block (a_response.request, Current, a_block_id, a_response.api) as l_tpl_block then
create vals.make (1)
-- add the variable to the block
a_response.api.hooks.invoke_value_table_alter (vals, a_response)

View File

@@ -4,6 +4,7 @@
<h3>Login or <a href="{$site_url/}account/roc-register">Register</a></h3>
<div>
<form name="cms_basic_auth" action="{$site_url/}roc-basic-login" method="POST">
{unless isempty="$site_destination"}<input type="hidden" name="destination" value="{$site_destination/}">{/unless}
<input type="hidden" name="host" id="host" value="{$site_url/}">
<div>
<input type="text" name="username" id="username" required>

View File

@@ -141,7 +141,7 @@ feature {NONE} -- Implementation: routes
if api.user_is_authenticated then
r.add_error_message ("You are already signed in!")
else
if attached smarty_template_block (Current, "login", api) as l_tpl_block then
if attached smarty_template_login_block (req, Current, "login", api) as l_tpl_block then
create vals.make (1)
-- add the variable to the block
l_tpl_block.set_value (api.user, "user")
@@ -216,14 +216,14 @@ feature {NONE} -- Implementation: routes
api.record_user_login (l_user)
create {GENERIC_VIEW_CMS_RESPONSE} r.make (req, res, api)
if attached {WSF_STRING} req.query_parameter ("destination") as p_destination then
if attached {WSF_STRING} req.item ("destination") as p_destination then
r.set_redirection (p_destination.url_encoded_value)
else
r.set_redirection ("")
end
else
create {GENERIC_VIEW_CMS_RESPONSE} r.make (req, res, api)
if attached smarty_template_block (Current, "login", api) as l_tpl_block then
if attached smarty_template_login_block (req, Current, "login", api) as l_tpl_block then
l_tpl_block.set_value (l_username.value, "username")
l_tpl_block.set_value ("Wrong: Username or password ", "error")
r.add_block (l_tpl_block, "content")
@@ -232,7 +232,7 @@ feature {NONE} -- Implementation: routes
r.execute
else
create {BAD_REQUEST_ERROR_CMS_RESPONSE} r.make (req, res, api)
if attached smarty_template_block (Current, "login", api) as l_tpl_block then
if attached smarty_template_login_block (req, Current, "login", api) as l_tpl_block then
if attached {WSF_STRING} req.form_parameter ("username") as l_username then
l_tpl_block.set_value (l_username.value, "username")
end
@@ -272,7 +272,7 @@ feature {NONE} -- Block views
local
vals: CMS_VALUE_TABLE
do
if attached smarty_template_block (Current, a_block_id, a_response.api) as l_tpl_block then
if attached smarty_template_login_block (a_response.request, Current, a_block_id, a_response.api) as l_tpl_block then
create vals.make (1)
-- add the variable to the block
a_response.api.hooks.invoke_value_table_alter (vals, a_response)

View File

@@ -4,6 +4,7 @@
<h3>Login or <a href="{$site_url/}account/roc-register">Register</a></h3>
<div>
<form name="cms_session_auth" action="{$site_url/}account/auth/roc-session-login" method="POST">
{unless isempty="$site_destination"}<input type="hidden" name="destination" value="{$site_destination/}">{/unless}
<div>
<input type="text" name="username" id="username" required value="{$username/}">
<label>Username</label>