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:
Jocelyn Fiat
2013-02-15 12:33:58 +01:00
parent 9be87e8e15
commit 61c8388eba
13 changed files with 531 additions and 334 deletions

View File

@@ -1,8 +1,8 @@
site.name=EWF Web CMS
#site.base_url=/demo
site.email=your@email.com
root-dir=www
root-dir=../www
var-dir=var
files-dir=www/files
themes-dir=www/themes
files-dir=files
themes-dir=../www/themes
theme=test

View File

@@ -15,9 +15,8 @@ create
feature {NONE} -- Initialization
make (a_service: like service)
make
do
service := a_service
name := "demo"
version := "1.0"
description := "demo"
@@ -26,12 +25,13 @@ feature {NONE} -- Initialization
feature {CMS_SERVICE} -- Registration
service: CMS_SERVICE
service: detachable CMS_SERVICE
register (a_service: CMS_SERVICE)
do
a_service.map_uri_template ("/demo/date/{arg}", agent handle_date_time_demo)
a_service.map_uri_template ("/demo/format/{arg}", agent handle_format_demo)
service := a_service
a_service.map_uri_template ("/demo/date/{arg}", agent handle_date_time_demo (a_service, ?, ?))
a_service.map_uri_template ("/demo/format/{arg}", agent handle_format_demo (a_service, ?, ?))
end
feature -- Hooks
@@ -41,20 +41,20 @@ feature -- Hooks
local
-- lnk: CMS_MODULE_LINK
do
create Result.make (3)
create Result.make (0)
-- create lnk.make ("Date/time demo")
-- lnk.set_callback (agent process_date_time_demo, <<"arg">>)
-- Result["/demo/date/{arg}"] := lnk
end
handle_date_time_demo (req: WSF_REQUEST; res: WSF_RESPONSE)
handle_date_time_demo (cms: CMS_SERVICE; req: WSF_REQUEST; res: WSF_RESPONSE)
do
(create {ANY_CMS_EXECUTION}.make_with_text (req, res, service, "<h1>Demo::date/time</h1>")).execute
(create {ANY_CMS_EXECUTION}.make_with_text (req, res, cms, "<h1>Demo::date/time</h1>")).execute
end
handle_format_demo (req: WSF_REQUEST; res: WSF_RESPONSE)
handle_format_demo (cms: CMS_SERVICE; req: WSF_REQUEST; res: WSF_RESPONSE)
do
(create {ANY_CMS_EXECUTION}.make_with_text (req, res, service, "<h1>Demo::format</h1>")).execute
(create {ANY_CMS_EXECUTION}.make_with_text (req, res, cms, "<h1>Demo::format</h1>")).execute
end
end

View File

@@ -8,10 +8,10 @@ class
WEB_CMS
inherit
CMS_SERVICE
redefine
modules
end
-- CMS_SERVICE
-- redefine
-- modules
-- end
WSF_DEFAULT_SERVICE
redefine
@@ -21,37 +21,6 @@ inherit
create
make_and_launch
feature -- Initialization
base_url: detachable READABLE_STRING_8
server_base_url: detachable READABLE_STRING_8
-- Base url (related to absolute path).
--| Mainly pertinent when run from a standalone server.
do
Result := base_url
end
modules: ARRAYED_LIST [CMS_MODULE]
local
m: CMS_MODULE
once
Result := Precursor
-- Others
create {DEMO_MODULE} m.make (Current)
m.enable
Result.extend (m)
create {SHUTDOWN_MODULE} m.make
m.enable
Result.extend (m)
-- create {EIFFEL_LOGIN_MODULE} m.make
-- m.enable
-- Result.extend (m)
end
feature {NONE} -- Initialization
initialize
@@ -59,9 +28,8 @@ feature {NONE} -- Initialization
args: ARGUMENTS
cfg: detachable STRING
i,n: INTEGER
cms_config: CMS_CONFIGURATION
opts: WSF_SERVICE_LAUNCHER_OPTIONS_FROM_INI
do
--| Arguments
create args
from
i := 1
@@ -83,35 +51,80 @@ feature {NONE} -- Initialization
cfg := "cms.ini"
end
end
if cfg /= Void then
create cms_config.make_from_file (cfg)
-- (create {EXECUTION_ENVIRONMENT}).change_working_directory (dir)
else
create cms_config.make
end
--| EWF settings
create opts.make_from_file ("ewf.ini")
service_options := opts
service_options := create {WSF_SERVICE_LAUNCHER_OPTIONS_FROM_INI}.make_from_file ("ewf.ini")
Precursor
--| CMS settings
base_url := cms_config.site_base_url (base_url)
initialize_cms (cms_config)
site_email := cms_config.site_email (site_email)
site_name := cms_config.site_name (site_name)
on_launched
--| CMS initialization
launch_cms (cms_setup (cfg))
end
on_launched
cms_setup (a_cfg_fn: detachable READABLE_STRING_8): CMS_CUSTOM_SETUP
do
if a_cfg_fn /= Void then
create Result.make_from_file (a_cfg_fn)
else
create Result -- Default
end
setup_modules (Result)
setup_storage (Result)
end
launch_cms (a_setup: CMS_SETUP)
local
cms: CMS_SERVICE
do
create cms.make (a_setup)
on_launched (cms)
cms_service := cms
end
feature -- Execution
cms_service: CMS_SERVICE
execute (req: WSF_REQUEST; res: WSF_RESPONSE)
do
cms_service.execute (req, res)
end
feature -- Access
setup_modules (a_setup: CMS_SETUP)
local
m: CMS_MODULE
do
create {DEMO_MODULE} m.make
m.enable
a_setup.add_module (m)
create {SHUTDOWN_MODULE} m.make
m.enable
a_setup.add_module (m)
create {DEBUG_MODULE} m.make
m.enable
a_setup.add_module (m)
end
setup_storage (a_setup: CMS_SETUP)
do
end
feature -- Event
on_launched (cms: CMS_SERVICE)
local
e: CMS_EMAIL
do
create e.make (site_email, site_email, "[" + site_name + "] launched...", "The site [" + site_name + "] was launched at " + (create {DATE_TIME}.make_now_utc).out + " UTC.")
mailer.safe_process_email (e)
create e.make (cms.site_email, cms.site_email, "[" + cms.site_name + "] launched...", "The site [" + cms.site_name + "] was launched at " + (create {DATE_TIME}.make_now_utc).out + " UTC.")
cms.mailer.safe_process_email (e)
end
feature -- Helper
file_exists (fn: STRING): BOOLEAN
local
f: RAW_FILE

View File

@@ -7,9 +7,6 @@ note
class
CMS_CONFIGURATION
--inherit
-- SHARED_EXECUTION_ENVIRONMENT
create
make,
make_from_file
@@ -26,6 +23,7 @@ feature {NONE} -- Initialization
-- Initialize `Current'.
do
make
configuration_location := a_filename
import (a_filename)
analyze
end
@@ -40,6 +38,8 @@ feature {NONE} -- Initialization
feature -- Access
configuration_location: detachable READABLE_STRING_8
option (a_name: READABLE_STRING_GENERAL): detachable ANY
do
Result := options.item (a_name.as_string_8)
@@ -161,7 +161,6 @@ feature -- Change
var_location := res
end
get_root_location
local
res: STRING_32

View File

@@ -0,0 +1,18 @@
note
description: "Summary description for {CMS_CUSTOM_SETUP}."
author: ""
date: "$Date$"
revision: "$Revision$"
class
CMS_CUSTOM_SETUP
inherit
CMS_DEFAULT_SETUP
create
default_create,
make,
make_from_file
end

View File

@@ -0,0 +1,134 @@
note
description: "Summary description for {CMS_DEFAULT_SETUP}."
author: ""
date: "$Date$"
revision: "$Revision$"
class
CMS_DEFAULT_SETUP
inherit
CMS_SETUP
redefine
default_create
end
create
default_create,
make,
make_from_file
feature {NONE} -- Initialization
make (a_cfg: CMS_CONFIGURATION)
do
configuration := a_cfg
default_create
end
make_from_file (fn: READABLE_STRING_8)
local
cfg: CMS_CONFIGURATION
do
create cfg.make_from_file (fn)
make (cfg)
end
default_create
do
Precursor
build_modules
build_storage
build_session_manager
build_auth_engine
build_mailer
end
feature -- Access
modules: ARRAYED_LIST [CMS_MODULE]
storage: CMS_STORAGE
-- CMS persistent layer
session_manager: WSF_SESSION_MANAGER
-- CMS Session manager
auth_engine: CMS_AUTH_ENGINE
-- CMS Authentication engine
mailer: CMS_MAILER
feature {NONE} -- Initialization
build_modules
local
m: CMS_MODULE
do
create modules.make (3)
-- Core
create {USER_MODULE} m.make
m.enable
modules.extend (m)
create {ADMIN_MODULE} m.make
m.enable
modules.extend (m)
create {NODE_MODULE} m.make
m.enable
modules.extend (m)
end
build_storage
local
dn: DIRECTORY_NAME
do
if attached configuration as cfg and then attached cfg.var_location as l_site_var_dir then
create dn.make_from_string (l_site_var_dir)
else
create dn.make
end
dn.extend ("_storage_")
create {CMS_SED_STORAGE} storage.make (dn.string)
end
build_session_manager
local
dn: DIRECTORY_NAME
do
if attached configuration as cfg and then attached cfg.var_location as l_site_var_dir then
create dn.make_from_string (l_site_var_dir)
else
create dn.make
end
dn.extend ("_storage_")
dn.extend ("_sessions_")
create {WSF_FS_SESSION_MANAGER} session_manager.make_with_folder (dn.string)
end
build_auth_engine
do
create {CMS_STORAGE_AUTH_ENGINE} auth_engine.make (storage)
end
build_mailer
local
ch_mailer: CMS_CHAIN_MAILER
st_mailer: CMS_STORAGE_MAILER
do
create st_mailer.make (storage)
create ch_mailer.make (st_mailer)
ch_mailer.set_next (create {CMS_SENDMAIL_MAILER})
mailer := ch_mailer
end
feature -- Change
add_module (m: CMS_MODULE)
do
modules.force (m)
end
end

View File

@@ -6,25 +6,28 @@ note
even for a specific handler.
]"
deferred class
class
CMS_SERVICE
feature -- Initialization
inherit
WSF_SERVICE
initialize_cms (a_base_url: like base_url; a_cfg: detachable CMS_CONFIGURATION)
create
make
feature {NONE} -- Initialization
make (a_setup: CMS_SETUP)
local
cfg: detachable CMS_CONFIGURATION
do
cfg := a_cfg
cfg := a_setup.configuration
if cfg = Void then
create cfg.make
end
if a_base_url /= Void and then not a_base_url.is_empty then
base_url := a_base_url
else
base_url := Void
end
configuration := cfg
base_url := a_setup.base_url
site_url := cfg.site_url ("")
site_name := cfg.site_name ("EWF::CMS")
@@ -39,8 +42,14 @@ feature -- Initialization
compute_theme_resource_location
create content_types.make (3)
modules := a_setup.modules
storage := a_setup.storage
session_manager := a_setup.session_manager
auth_engine := a_setup.auth_engine
mailer := a_setup.mailer
initialize_storage
initialize_auth_engine
initialize_session_manager
@@ -50,23 +59,17 @@ feature -- Initialization
end
initialize_session_manager
local
dn: DIRECTORY_NAME
-- local
-- dn: DIRECTORY_NAME
do
create dn.make_from_string (site_var_dir)
dn.extend ("_storage_")
dn.extend ("_sessions_")
create {WSF_FS_SESSION_MANAGER} session_manager.make_with_folder (dn.string)
-- create dn.make_from_string (site_var_dir)
-- dn.extend ("_storage_")
-- dn.extend ("_sessions_")
-- create {WSF_FS_SESSION_MANAGER} session_manager.make_with_folder (dn.string)
end
initialize_storage
local
dn: DIRECTORY_NAME
-- u: CMS_USER
do
create dn.make_from_string (site_var_dir)
dn.extend ("_storage_")
create {CMS_SED_STORAGE} storage.make (dn.string)
if not storage.has_user then
initialize_users
end
@@ -85,13 +88,13 @@ feature -- Initialization
initialize_mailer
local
ch_mailer: CMS_CHAIN_MAILER
st_mailer: CMS_STORAGE_MAILER
-- ch_mailer: CMS_CHAIN_MAILER
-- st_mailer: CMS_STORAGE_MAILER
do
create st_mailer.make (storage)
create ch_mailer.make (st_mailer)
ch_mailer.set_next (create {CMS_SENDMAIL_MAILER})
mailer := ch_mailer
-- create st_mailer.make (storage)
-- create ch_mailer.make (st_mailer)
-- ch_mailer.set_next (create {CMS_SENDMAIL_MAILER})
-- mailer := ch_mailer
end
initialize_router
@@ -133,31 +136,16 @@ feature -- Initialization
initialize_auth_engine
do
create {CMS_STORAGE_AUTH_ENGINE} auth_engine.make (storage)
-- create {CMS_STORAGE_AUTH_ENGINE} auth_engine.make (storage)
end
feature -- Access
configuration: CMS_CONFIGURATION
auth_engine: CMS_AUTH_ENGINE
modules: ARRAYED_LIST [CMS_MODULE]
local
m: CMS_MODULE
once
create Result.make (10)
-- Core
create {USER_MODULE} m.make (Current)
m.enable
Result.extend (m)
create {ADMIN_MODULE} m.make (Current)
m.enable
Result.extend (m)
create {NODE_MODULE} m.make (Current)
m.enable
Result.extend (m)
end
modules: LIST [CMS_MODULE]
feature -- Hook: menu_alter
@@ -313,18 +301,6 @@ feature -- URL related
base_url: detachable READABLE_STRING_8
-- Base url (related to the script path).
-- deferred
-- ensure
-- valid_base_url: (Result /= Void and then Result.is_empty) implies (Result.starts_with ("/") and not Result.ends_with ("/"))
-- end
-- server_base_url: detachable READABLE_STRING_8
-- -- Base url (related to absolute path).
-- deferred
-- ensure
-- valid_base_url: (Result /= Void and then Result.is_empty) implies (Result.starts_with ("/") and not Result.ends_with ("/"))
-- end
script_url: detachable READABLE_STRING_8
set_script_url (a_url: like script_url)
@@ -435,16 +411,10 @@ feature -- Core Execution
(create {HOME_CMS_EXECUTION}.make (req, res, Current)).execute
end
-- handle_theme (req: WSF_REQUEST; res: WSF_RESPONSE)
-- do
-- (create {THEME_CMS_EXECUTION}.make (req, res, Current)).execute
-- end
execute (req: WSF_REQUEST; res: WSF_RESPONSE)
-- Default request handler if no other are relevant
local
e: CMS_EXECUTION
-- not_found: WSF_NOT_FOUND_RESPONSE
do
initialize_urls (req)
if attached router.dispatch_and_return_handler (req, res) as p then
@@ -452,8 +422,6 @@ feature -- Core Execution
else
create {NOT_FOUND_CMS_EXECUTION} e.make (req, res, Current)
e.execute
-- create not_found.make
-- res.send (not_found)
end
end

View File

@@ -0,0 +1,62 @@
note
description: "Summary description for {CMS_SETUP}."
author: ""
date: "$Date$"
revision: "$Revision$"
deferred class
CMS_SETUP
feature -- Initialization
initialize_storage (a_cms: CMS_SERVICE)
do
end
feature -- Access
configuration: detachable CMS_CONFIGURATION
base_url: detachable READABLE_STRING_8
modules: LIST [CMS_MODULE]
deferred
end
storage: CMS_STORAGE
-- CMS persistent layer
deferred
end
session_manager: WSF_SESSION_MANAGER
-- CMS Session manager
deferred
end
auth_engine: CMS_AUTH_ENGINE
-- CMS Authentication engine
deferred
end
mailer: CMS_MAILER
-- CMS email engine
deferred
end
feature -- Change
set_base_url (a_base_url: like base_url)
do
if a_base_url /= Void and then not a_base_url.is_empty then
base_url := a_base_url
else
base_url := Void
end
end
add_module (m: CMS_MODULE)
deferred
end
end

View File

@@ -17,9 +17,8 @@ create
feature {NONE} -- Initialization
make (a_service: like service)
make
do
service := a_service
name := "admin"
version := "1.0"
description := "Set of service to administrate the site"
@@ -30,16 +29,17 @@ feature {NONE} -- Initialization
feature {CMS_SERVICE} -- Registration
service: CMS_SERVICE
service: detachable CMS_SERVICE
register (a_service: CMS_SERVICE)
do
a_service.map_uri ("/admin/", agent handle_admin)
a_service.map_uri ("/admin/users/", agent handle_admin_users)
a_service.map_uri ("/admin/blocks/", agent handle_admin_blocks)
a_service.map_uri ("/admin/modules/", agent handle_admin_modules)
a_service.map_uri ("/admin/logs/", agent handle_admin_logs)
a_service.map_uri_template ("/admin/log/{log-id}", agent handle_admin_log_view)
service := a_service
a_service.map_uri ("/admin/", agent handle_admin (a_service, ?, ?))
a_service.map_uri ("/admin/users/", agent handle_admin_users (a_service, ?, ?))
a_service.map_uri ("/admin/blocks/", agent handle_admin_blocks (a_service, ?, ?))
a_service.map_uri ("/admin/modules/", agent handle_admin_modules (a_service, ?, ?))
a_service.map_uri ("/admin/logs/", agent handle_admin_logs (a_service, ?, ?))
a_service.map_uri_template ("/admin/log/{log-id}", agent handle_admin_log_view (a_service, ?, ?))
a_service.add_menu_alter_hook (Current)
end
@@ -57,43 +57,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_admin (req: WSF_REQUEST; res: WSF_RESPONSE)
feature -- Handler
handle_admin (cms: CMS_SERVICE; req: WSF_REQUEST; res: WSF_RESPONSE)
do
(create {ADMIN_CMS_EXECUTION}.make (req, res, service)).execute
(create {ADMIN_CMS_EXECUTION}.make (req, res, cms)).execute
end
handle_admin_users (req: WSF_REQUEST; res: WSF_RESPONSE)
handle_admin_users (cms: CMS_SERVICE; req: WSF_REQUEST; res: WSF_RESPONSE)
do
(create {ADMIN_USERS_CMS_EXECUTION}.make (req, res, service)).execute
(create {ADMIN_USERS_CMS_EXECUTION}.make (req, res, cms)).execute
end
handle_admin_blocks (req: WSF_REQUEST; res: WSF_RESPONSE)
handle_admin_blocks (cms: CMS_SERVICE; req: WSF_REQUEST; res: WSF_RESPONSE)
do
(create {ADMIN_BLOCKS_CMS_EXECUTION}.make (req, res, service)).execute
(create {ADMIN_BLOCKS_CMS_EXECUTION}.make (req, res, cms)).execute
end
handle_admin_modules (req: WSF_REQUEST; res: WSF_RESPONSE)
handle_admin_modules (cms: CMS_SERVICE; req: WSF_REQUEST; res: WSF_RESPONSE)
do
(create {ADMIN_MODULES_CMS_EXECUTION}.make (req, res, service)).execute
(create {ADMIN_MODULES_CMS_EXECUTION}.make (req, res, cms)).execute
end
handle_admin_logs (req: WSF_REQUEST; res: WSF_RESPONSE)
handle_admin_logs (cms: CMS_SERVICE; req: WSF_REQUEST; res: WSF_RESPONSE)
do
(create {ADMIN_LOGS_CMS_EXECUTION}.make (req, res, service)).execute
(create {ADMIN_LOGS_CMS_EXECUTION}.make (req, res, cms)).execute
end
handle_admin_log_view (req: WSF_REQUEST; res: WSF_RESPONSE)
handle_admin_log_view (cms: CMS_SERVICE; req: WSF_REQUEST; res: WSF_RESPONSE)
do
(create {LOG_VIEW_CMS_EXECUTION}.make (req, res, service)).execute
(create {LOG_VIEW_CMS_EXECUTION}.make (req, res, cms)).execute
end

View File

@@ -0,0 +1,136 @@
note
description: "Summary description for {DEBUG_MODULE}."
date: "$Date$"
revision: "$Revision$"
class
DEBUG_MODULE
inherit
CMS_MODULE
-- CMS_HOOK_BLOCK
CMS_HOOK_AUTO_REGISTER
create
make
feature {NONE} -- Initialization
make
do
name := "debug"
version := "1.0"
description := "Debug"
package := "cms"
end
feature {CMS_SERVICE} -- Registration
service: detachable CMS_SERVICE
register (a_service: CMS_SERVICE)
do
service := a_service
a_service.map_uri_template ("/debug/", agent handle_debug (a_service, ?, ?))
end
feature -- Hooks
links: HASH_TABLE [CMS_MODULE_LINK, STRING]
-- Link indexed by path
local
-- lnk: CMS_MODULE_LINK
do
create Result.make (0)
-- create lnk.make ("Date/time demo")
-- lnk.set_callback (agent process_date_time_demo, <<"arg">>)
-- Result["/demo/date/{arg}"] := lnk
end
feature -- Hooks
-- block_list: ITERABLE [like {CMS_BLOCK}.name]
-- do
-- Result := <<"debug-info">>
-- end
-- get_block_view (a_block_id: detachable READABLE_STRING_8; a_execution: CMS_EXECUTION)
-- local
-- b: CMS_CONTENT_BLOCK
-- do
-- create b.make ("debug-info", "Debug", "... ", a_execution.formats.plain_text)
-- a_execution.add_block (b, Void)
-- end
feature -- Handler
handle_debug (cms: CMS_SERVICE; req: WSF_REQUEST; res: WSF_RESPONSE)
local
e: CMS_EXECUTION
s: STRING
do
if req.is_get_request_method then
create {ANY_CMS_EXECUTION} e.make (req, res, cms)
e.set_title ("DEBUG")
create s.make_empty
append_info_to ("Name", cms.site_name, e, s)
append_info_to ("Url", cms.site_url, e, s)
if attached cms.configuration as cfg and then attached cfg.configuration_location as l_loc then
s.append ("<hr/>")
append_info_to ("Configuration file", l_loc, e, s)
end
s.append ("<hr/>")
append_info_to ("Current dir", (create {EXECUTION_ENVIRONMENT}).current_working_path.name, e, s)
append_info_to ("Base url", cms.base_url, e, s)
append_info_to ("Script url", cms.script_url, e, s)
s.append ("<hr/>")
append_info_to ("Dir", cms.site_dir, e, s)
append_info_to ("Var dir", cms.site_var_dir, e, s)
s.append ("<hr/>")
append_info_to ("Theme", cms.theme_name, e, s)
append_info_to ("Theme location", cms.theme_resource_location, e, s)
s.append ("<hr/>")
append_info_to ("Files location", cms.files_location, e, s)
s.append ("<hr/>")
append_info_to ("Url", e.url ("/", Void), e, s)
if attached e.user as u then
append_info_to ("User", u.name, e, s)
append_info_to ("User url", e.user_url (u), e, s)
end
e.set_main_content (s)
else
create {NOT_FOUND_CMS_EXECUTION} e.make (req, res, cms)
end
e.execute
end
append_info_to (n: READABLE_STRING_8; v: detachable READABLE_STRING_GENERAL; e: CMS_EXECUTION; t: STRING)
do
t.append ("<li>")
t.append ("<strong>" + n + "</strong>: ")
if v /= Void then
t.append (e.html_encoded (v))
end
t.append ("</li>")
end
note
copyright: "Copyright (c) 1984-2013, Eiffel Software and others"
license: "Eiffel Forum License v2 (see http://www.eiffel.com/licensing/forum.txt)"
source: "[
Eiffel Software
5949 Hollister Ave., Goleta, CA 93117 USA
Telephone 805-685-1006, Fax 805-685-6869
Website http://www.eiffel.com
Customer support http://support.eiffel.com
]"
end

View File

@@ -19,9 +19,8 @@ create
feature {NONE} -- Initialization
make (a_service: like service)
make
do
service := a_service
name := "node"
version := "1.0"
description := "Service to manage content based on 'node'"
@@ -32,20 +31,21 @@ 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 ("/node/add", agent handle_node_add)
a_service.map_uri_template ("/node/add/{type}", agent handle_node_add)
service := a_service
a_service.map_uri ("/node/add", agent handle_node_add (a_service, ?, ?))
a_service.map_uri_template ("/node/add/{type}", agent handle_node_add (a_service, ?, ?))
create {CMS_HANDLER} h.make (agent handle_node_view)
create {CMS_HANDLER} h.make (agent handle_node_view (a_service, ?, ?))
a_service.router.map (create {WSF_URI_TEMPLATE_MAPPING}.make ("/node/{nid}", h))
a_service.router.map (create {WSF_URI_TEMPLATE_MAPPING}.make ("/node/{nid}/view", h))
a_service.map_uri_template ("/node/{nid}/edit", agent handle_node_edit)
a_service.map_uri_template ("/node/{nid}/edit", agent handle_node_edit (a_service, ?, ?))
a_service.add_content_type (create {CMS_PAGE_CONTENT_TYPE}.make)
@@ -86,28 +86,23 @@ 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_node_view (req: WSF_REQUEST; res: WSF_RESPONSE)
handle_node_view (cms: CMS_SERVICE; req: WSF_REQUEST; res: WSF_RESPONSE)
do
(create {NODE_VIEW_CMS_EXECUTION}.make (req, res, service)).execute
(create {NODE_VIEW_CMS_EXECUTION}.make (req, res, cms)).execute
end
handle_node_edit (req: WSF_REQUEST; res: WSF_RESPONSE)
handle_node_edit (cms: CMS_SERVICE; req: WSF_REQUEST; res: WSF_RESPONSE)
do
(create {NODE_EDIT_CMS_EXECUTION}.make (req, res, service)).execute
(create {NODE_EDIT_CMS_EXECUTION}.make (req, res, cms)).execute
end
handle_node_add (req: WSF_REQUEST; res: WSF_RESPONSE)
handle_node_add (cms: CMS_SERVICE; req: WSF_REQUEST; res: WSF_RESPONSE)
do
(create {NODE_ADD_CMS_EXECUTION}.make (req, res, service)).execute
(create {NODE_ADD_CMS_EXECUTION}.make (req, res, cms)).execute
end
end

View File

@@ -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+XNYvQAAABl0RVh0U29mdHdhcmUAd3d3Lmlua3NjYXBlLm9yZ5vuPBoAAASmSURBVGiB1ZpbaBxVGMd/Mzu5bSRJY6LubmKJl4J9qShdwdpGGxGlharJSwpVVFrUUF+iT1VEUYRgaEGqsa2FGtu8xNtDsBQi5EFBS8UnsYWUtpsmaqppIdkkm+4eH77ZzWazl7lllv7gPOycmXP+/9kzM+d839GUUnjEOqAL2A7cCdSYJWjWx4F5s/wN/AgMAzNedK65NHI38CKwAwiZpcLitUvAlFlGgBPAFadCnBppAQ4DDwNhQHMqwEQBk8A5oAeYsNuAXSP1QD/wFNBqtzOLxIAzQC9ww/JVSimrZbdSalwplVJrT8rsa7dVfVZNHFRKTftgIJdps++SGksNrSDwLbAFqHUxXNwwB/wEPIe8+fJSzEi12cCDgO61OpukgN+RG7qQ74RiRkaApylg4sj4YZLqpgcalwloBvvu7SlUnQJOI6/6VRQy8jHwKkWG04aRMIlUwp7SElTqlVzYMVnslDlgAHgztyLf3e5GPnLleiaKUYto686tyDXSCHwANPkgyilNiMbG7INGzkn9QJvdltdVNnJg43uOVH34x7vMJP6ze1kbovWl9IFsI+uBJ3Ew3QgGaulqXfVvW+Lg+T5msG1EQ7SuBy7DyqH1GTKHulVoQTQDy0YiwKayyHHHJkR7xsgLyBTcFYupRbdN2CWEaM8Y2Yn7qTjHLw4w9s+o22bsoCHa0YEGZE3hmsXkInvP7vHbTBhoMJDlacTu1fs39JJMJQGoq6jLHE+kEuw9u4ejmwdpv6PDI61FiQBdBtCB9eVphv339xas89lMBdCh48FDno+0GZ+GWchAIh0F+f7q15y6fMJSaxPx2IrfPv4zNQbL4Zq8TM5P8Mu/PzvuwSczQZ0SRrzAh2EW9G3lp6Ghaa4/VQXRKbIO9ooqvYqj0UG2NW9fqy7iBiWMhGtaeOT2Ry21NhGPcXV+5QNfpVdxLPoVW5ufcKzSAnEDicUWZFekk12RTkutHTrfx6ELfZnfYuIkW5sfdyPSCvMGEnv1nOpANcc2n+Sx5va1aD6XKQMYBTqx+XXv//MjbqolAOoqGnjtvjcydT6bWAJGDSS0/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

View File

@@ -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