Refactorying the CMS component, to have an effective CMS_SERVICE, and setup as CMS_SETUP.
This way the application is much simpler, no need to implement deferred feature of CMS_SERVICE.
This commit is contained in:
@@ -1,112 +0,0 @@
|
||||
note
|
||||
description: "[
|
||||
]"
|
||||
|
||||
class
|
||||
USER_LOGIN_CMS_EXECUTION
|
||||
|
||||
inherit
|
||||
CMS_EXECUTION
|
||||
|
||||
CMS_AUTH_ENGINE
|
||||
|
||||
create
|
||||
make
|
||||
|
||||
feature -- Status
|
||||
|
||||
valid_credential (u,p: READABLE_STRING_32): BOOLEAN
|
||||
do
|
||||
Result := service.storage.is_valid_credential (u, p)
|
||||
end
|
||||
|
||||
feature -- Execution
|
||||
|
||||
process
|
||||
-- Computed response message.
|
||||
local
|
||||
auth_engine: CMS_AUTH_ENGINE
|
||||
l_url: detachable READABLE_STRING_8
|
||||
err: detachable STRING_8
|
||||
b: STRING_8
|
||||
u: detachable STRING_32
|
||||
do
|
||||
if request.is_request_method ("post") then
|
||||
if
|
||||
attached {WSF_STRING} request.form_parameter (form_login_name) as s_login and then not s_login.is_empty and
|
||||
attached {WSF_STRING} request.form_parameter (form_password_name) as s_passwd and then not s_passwd.is_empty
|
||||
then
|
||||
auth_engine := Current
|
||||
u := s_login.value
|
||||
if attached service.storage.user_by_name (u) as l_user and auth_engine.valid_credential (u, s_passwd.value) then
|
||||
login (l_user, request)
|
||||
else
|
||||
err := "Authentication failed for [" + html_encoded (u) + "]"
|
||||
end
|
||||
if attached {WSF_STRING} request.form_parameter ("form-destination") as s_dest then
|
||||
l_url := request.script_url (s_dest.value)
|
||||
end
|
||||
end
|
||||
else
|
||||
if
|
||||
attached {WSF_STRING} request.item ("destination") as s_dest
|
||||
then
|
||||
l_url := request.script_url (s_dest.value)
|
||||
end
|
||||
end
|
||||
|
||||
if l_url = Void then
|
||||
l_url := request.script_url ("/user")
|
||||
end
|
||||
|
||||
if authenticated then
|
||||
set_redirection (l_url)
|
||||
set_title ("Login")
|
||||
create b.make_empty
|
||||
b.append ("<h1>Login</h1>%N")
|
||||
set_main_content (b)
|
||||
else
|
||||
set_title ("Login")
|
||||
create b.make_empty
|
||||
b.append ("<h1>Login</h1>%N")
|
||||
|
||||
if err /= Void then
|
||||
b.append ("<div id=%"error-box%" style=%"background-color: #fcc; color:#f00;%">" + err + "</div>")
|
||||
end
|
||||
|
||||
b.append ("<form action=%"" + request.path_info + "%" method=%"POST%" id=%"form-login%" style=%"border: dotted 1px #099; display: inline-block; padding: 10px; margin: 10px;%">%N")
|
||||
-- b.append ("<div style=%"display:none%"><input type=%"hidden%" name=%"form-login-token%" value=%""+ cms.session.uuid +"%"></div>")
|
||||
b.append ("<div style=%"display:none%"><input type=%"hidden%" name=%"form-destination%" value=%""+ l_url +"%"></div>")
|
||||
b.append ("<div class=%"required username%">")
|
||||
b.append ("<strong><label for=%"id_username%">Username or email</label></strong> <em>(required)</em><br/>")
|
||||
b.append ("<input type=%"text%" id=%"id_username%" autofocus=%"autofocus%" name=%"" + form_login_name + "%" ")
|
||||
if u /= Void then
|
||||
b.append (" value=%""+ html_encoded (u) +"%" ")
|
||||
end
|
||||
b.append ("/>")
|
||||
b.append ("</div>")
|
||||
b.append ("<div class=%"required password%">")
|
||||
b.append ("<strong><label for=%"id_password%">Password</label></strong> <em>(required)</em><br/>")
|
||||
b.append ("<input type=%"password%" id=%"id_password%" name=%"" + form_password_name + "%" />")
|
||||
b.append ("</div>")
|
||||
|
||||
b.append ("<p class=%"description%"><a href=%"" + url ("/user/password", Void) + "%" tabindex=%"-1%">Reset password</a></p>%N")
|
||||
|
||||
b.append ("<div class=%"submit%">")
|
||||
b.append ("<input type=%"submit%" value=%"Log in%" name=%"submit%" >%N")
|
||||
b.append ("[
|
||||
<img alt="login" src="data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAADIAAAAyCAYAAAAeP4ixAAAABHNCSVQICAgIfAhkiAAAAAlwSFlzAAAHiQAAB4kB+XNYvQAAABl0RVh0U29mdHdhcmUAd3d3Lmlua3NjYXBlLm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S0/w4SWbfM5+OfZKIokZrWjJHqQDVfRE+xpWmbt3ILMwUM68B1PBpeNUaQ49EhP02AaL+eXrN/A0RxuSZ5uW0fFXqlW2F2UIj2zMJqEMlPuMJnEyCaB2HZyBSSZLnVOIf5WGRPUXpwkfoqA1cQzcDKuNYEkil6BZvPSjw5x3BsyJGaeHLOyWUK0ZpJ0eUGseuB34B7SrVUpiB2movAQ2Sl5nJnvzeAt4Fpz9R5zzSicUV+Md80fghJFc/6IMous4i2VeM4N4id5i3gASTRE8h3woGN769JoqcISWDM1LaKUqm3MSSXnteMjySRV207BVJvxVaIC+aFpynvMJs1NRQ0AaWTnAtISHIAuOaZNOtcM/veSRETgK0NA91KqUvKvw0Dl8w+Pd0wkC71SqkjSqnYGpqImX3U29HmdFNNCPgUmTGH8GZTzRTwK/A6DpYVbrc53YXkJ55FouJh7G1zmjTLd8CXwF9Ohbg1ks1twPPAM8i/FCT/xrM4csd/QNYSnrwR/wfI5AekDWyX2QAAAABJRU5ErkJggg=="
|
||||
style="float:right; margin: 5px;"/>
|
||||
]")
|
||||
b.append ("</div>")
|
||||
b.append ("<p>Need an account? <a href=%"" + url ("/user/register", Void) + "%">Sign up now!</a></p>%N")
|
||||
b.append ("</form>%N")
|
||||
|
||||
set_main_content (b)
|
||||
end
|
||||
end
|
||||
|
||||
form_login_name: STRING = "login"
|
||||
form_password_name: STRING = "password"
|
||||
|
||||
end
|
||||
@@ -19,9 +19,8 @@ create
|
||||
|
||||
feature {NONE} -- Initialization
|
||||
|
||||
make (a_service: like service)
|
||||
make
|
||||
do
|
||||
service := a_service
|
||||
name := "user"
|
||||
version := "1.0"
|
||||
description := "Users management"
|
||||
@@ -32,22 +31,23 @@ feature {NONE} -- Initialization
|
||||
|
||||
feature {CMS_SERVICE} -- Registration
|
||||
|
||||
service: CMS_SERVICE
|
||||
service: detachable CMS_SERVICE
|
||||
|
||||
register (a_service: CMS_SERVICE)
|
||||
local
|
||||
h: CMS_HANDLER
|
||||
do
|
||||
-- a_service.map_uri ("/user", agent handle_login)
|
||||
a_service.map_uri ("/user/logout", agent handle_logout)
|
||||
a_service.map_uri ("/user/register", agent handle_register)
|
||||
a_service.map_uri ("/user/password", agent handle_request_new_password)
|
||||
service := a_service
|
||||
|
||||
create {CMS_HANDLER} h.make (agent handle_user)
|
||||
a_service.map_uri ("/user/logout", agent handle_logout (a_service, ?, ?))
|
||||
a_service.map_uri ("/user/register", agent handle_register (a_service, ?, ?))
|
||||
a_service.map_uri ("/user/password", agent handle_request_new_password (a_service, ?, ?))
|
||||
|
||||
create {CMS_HANDLER} h.make (agent handle_user (a_service, ?, ?))
|
||||
a_service.router.map (create {WSF_URI_TEMPLATE_MAPPING}.make ("/user/{uid}", h))
|
||||
a_service.router.map (create {WSF_URI_MAPPING}.make_trailing_slash_ignored ("/user", h))
|
||||
a_service.map_uri_template ("/user/{uid}/edit", agent handle_edit)
|
||||
a_service.map_uri_template ("/user/reset/{uid}/{last-signed}/{extra}", agent handle_reset_password)
|
||||
a_service.map_uri_template ("/user/{uid}/edit", agent handle_edit (a_service, ?, ?))
|
||||
a_service.map_uri_template ("/user/reset/{uid}/{last-signed}/{extra}", agent handle_reset_password (a_service, ?, ?))
|
||||
|
||||
a_service.add_menu_alter_hook (Current)
|
||||
a_service.add_block_hook (Current)
|
||||
@@ -104,53 +104,40 @@ feature -- Hooks
|
||||
|
||||
links: HASH_TABLE [CMS_MODULE_LINK, STRING]
|
||||
-- Link indexed by path
|
||||
local
|
||||
-- lnk: CMS_MODULE_LINK
|
||||
do
|
||||
create Result.make (3)
|
||||
-- create lnk.make ("Date/time demo")
|
||||
-- lnk.set_callback (agent process_date_time_demo, <<"arg">>)
|
||||
-- Result["/demo/date/{arg}"] := lnk
|
||||
create Result.make (0)
|
||||
end
|
||||
|
||||
-- handle_login (req: WSF_REQUEST; res: WSF_RESPONSE)
|
||||
-- do
|
||||
-- (create {USER_LOGIN_CMS_EXECUTION}.make (req, res, service)).execute
|
||||
-- end
|
||||
feature -- Handlers
|
||||
|
||||
handle_logout (req: WSF_REQUEST; res: WSF_RESPONSE)
|
||||
handle_logout (cms: CMS_SERVICE; req: WSF_REQUEST; res: WSF_RESPONSE)
|
||||
do
|
||||
(create {USER_LOGOUT_CMS_EXECUTION}.make (req, res, service)).execute
|
||||
(create {USER_LOGOUT_CMS_EXECUTION}.make (req, res, cms)).execute
|
||||
end
|
||||
|
||||
handle_user (req: WSF_REQUEST; res: WSF_RESPONSE)
|
||||
handle_user (cms: CMS_SERVICE; req: WSF_REQUEST; res: WSF_RESPONSE)
|
||||
do
|
||||
(create {USER_CMS_EXECUTION}.make (req, res, service)).execute
|
||||
(create {USER_CMS_EXECUTION}.make (req, res, cms)).execute
|
||||
end
|
||||
|
||||
handle_edit (req: WSF_REQUEST; res: WSF_RESPONSE)
|
||||
handle_edit (cms: CMS_SERVICE; req: WSF_REQUEST; res: WSF_RESPONSE)
|
||||
do
|
||||
(create {USER_EDIT_CMS_EXECUTION}.make (req, res, service)).execute
|
||||
(create {USER_EDIT_CMS_EXECUTION}.make (req, res, cms)).execute
|
||||
end
|
||||
|
||||
-- handle_account (req: WSF_REQUEST; res: WSF_RESPONSE)
|
||||
-- do
|
||||
-- (create {USER_ACCOUNT_CMS_EXECUTION}.make (req, res, service)).execute
|
||||
-- end
|
||||
|
||||
handle_register (req: WSF_REQUEST; res: WSF_RESPONSE)
|
||||
handle_register (cms: CMS_SERVICE; req: WSF_REQUEST; res: WSF_RESPONSE)
|
||||
do
|
||||
(create {USER_REGISTER_CMS_EXECUTION}.make (req, res, service)).execute
|
||||
(create {USER_REGISTER_CMS_EXECUTION}.make (req, res, cms)).execute
|
||||
end
|
||||
|
||||
handle_request_new_password (req: WSF_REQUEST; res: WSF_RESPONSE)
|
||||
handle_request_new_password (cms: CMS_SERVICE; req: WSF_REQUEST; res: WSF_RESPONSE)
|
||||
do
|
||||
(create {USER_NEW_PASSWORD_CMS_EXECUTION}.make (req, res, service)).execute
|
||||
(create {USER_NEW_PASSWORD_CMS_EXECUTION}.make (req, res, cms)).execute
|
||||
end
|
||||
|
||||
handle_reset_password (req: WSF_REQUEST; res: WSF_RESPONSE)
|
||||
handle_reset_password (cms: CMS_SERVICE; req: WSF_REQUEST; res: WSF_RESPONSE)
|
||||
do
|
||||
(create {USER_RESET_PASSWORD_CMS_EXECUTION}.make (req, res, service)).execute
|
||||
(create {USER_RESET_PASSWORD_CMS_EXECUTION}.make (req, res, cms)).execute
|
||||
end
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user