Added support for OpenID identity
Added user roles management Improvement CMS_HOOK_FORM_ALTER design. Factorized code into CMS_WIDGET_COMPOSITE Use general notion of CMS_WIDGET (and CMS_FORM allows CMS_WIDGET, and not just CMS_FORM_ITEM) Fixed various CMS_WIDGET traversal, and fixed related issue for CMS forms Fixed CMS_FORM_CHECKBOX_INPUT when no value was set. Added CMS_FORM_DATA.cached_value .. to pass computed values during validation to submit actions (mainly for optimization) Added support for @include=filename in CMS_CONFIGURATION Added CMS_WIDGET_TABLE as filled version of CMS_WIDGET_AGENT_TABLE (renamed from previous CMS_WIDGET_TABLE) Many improvements to the CMS_FORM design Some improvements to CMS_MODULE ...
This commit is contained in:
@@ -29,6 +29,9 @@ feature -- Execution
|
||||
if has_permission ("administrate blocks") then
|
||||
b.append ("<li>" + link ("Blocks", "/admin/blocks/", Void) + "</li>")
|
||||
end
|
||||
if has_permission ("administrate user-roles") then
|
||||
b.append ("<li>" + link ("User roles", "/admin/roles/", Void) + "</li>")
|
||||
end
|
||||
if has_permission ("administrate users") then
|
||||
b.append ("<li>" + link ("Users", "/admin/users/", Void) + "</li>")
|
||||
end
|
||||
|
||||
@@ -9,6 +9,9 @@ class
|
||||
|
||||
inherit
|
||||
CMS_MODULE
|
||||
redefine
|
||||
permissions
|
||||
end
|
||||
|
||||
CMS_HOOK_MENU_ALTER
|
||||
|
||||
@@ -36,6 +39,7 @@ feature {CMS_SERVICE} -- Registration
|
||||
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/roles/", agent handle_admin_user_roles (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, ?, ?))
|
||||
@@ -55,10 +59,16 @@ feature -- Hooks
|
||||
a_menu_system.management_menu.extend (lnk)
|
||||
end
|
||||
|
||||
links: HASH_TABLE [CMS_MODULE_LINK, STRING]
|
||||
-- Link indexed by path
|
||||
permissions (a_service: CMS_SERVICE): LIST [CMS_PERMISSION]
|
||||
do
|
||||
create Result.make (0)
|
||||
Result := Precursor (a_service)
|
||||
Result.extend ("administer")
|
||||
Result.extend ("administer users")
|
||||
Result.extend ("administer user roles")
|
||||
Result.extend ("administer content")
|
||||
Result.extend ("administer logs")
|
||||
Result.extend ("administer blocks")
|
||||
Result.extend ("administer modules")
|
||||
end
|
||||
|
||||
feature -- Handler
|
||||
@@ -73,6 +83,11 @@ feature -- Handler
|
||||
(create {ADMIN_USERS_CMS_EXECUTION}.make (req, res, cms)).execute
|
||||
end
|
||||
|
||||
handle_admin_user_roles (cms: CMS_SERVICE; req: WSF_REQUEST; res: WSF_RESPONSE)
|
||||
do
|
||||
(create {ADMIN_USER_ROLES_CMS_EXECUTION}.make (req, res, cms)).execute
|
||||
end
|
||||
|
||||
handle_admin_blocks (cms: CMS_SERVICE; req: WSF_REQUEST; res: WSF_RESPONSE)
|
||||
do
|
||||
(create {ADMIN_BLOCKS_CMS_EXECUTION}.make (req, res, cms)).execute
|
||||
|
||||
@@ -0,0 +1,211 @@
|
||||
note
|
||||
description: "Summary description for {ADMIN_USER_ROLES_CMS_EXECUTION}."
|
||||
author: ""
|
||||
date: "$Date$"
|
||||
revision: "$Revision$"
|
||||
|
||||
class
|
||||
ADMIN_USER_ROLES_CMS_EXECUTION
|
||||
|
||||
inherit
|
||||
CMS_EXECUTION
|
||||
|
||||
create
|
||||
make
|
||||
|
||||
feature -- Execution
|
||||
|
||||
process
|
||||
do
|
||||
if request.is_post_request_method then
|
||||
process_post
|
||||
else
|
||||
process_get
|
||||
end
|
||||
end
|
||||
|
||||
process_get
|
||||
-- Computed response message.
|
||||
local
|
||||
b: STRING_8
|
||||
f: CMS_FORM
|
||||
l_roles: LIST [CMS_USER_ROLE]
|
||||
do
|
||||
set_title ("User roles")
|
||||
-- check Permission !!!
|
||||
create b.make_empty
|
||||
if has_permission ("administrate user roles") then
|
||||
l_roles := service.storage.user_roles
|
||||
f := new_edit_form (url (request.path_info, Void), l_roles, True)
|
||||
f.append_to_html (theme, b)
|
||||
else
|
||||
b.append ("<div class=%"denied%">Access denied</div>")
|
||||
end
|
||||
set_main_content (b)
|
||||
end
|
||||
|
||||
process_post
|
||||
-- Computed response message.
|
||||
local
|
||||
b: STRING_8
|
||||
f: CMS_FORM
|
||||
l_roles: LIST [CMS_USER_ROLE]
|
||||
do
|
||||
set_title ("User roles")
|
||||
create b.make_empty
|
||||
|
||||
debug ("cms")
|
||||
across
|
||||
request.form_parameters as c
|
||||
loop
|
||||
b.append ("<li>")
|
||||
b.append (html_encoded (c.item.name))
|
||||
b.append ("=")
|
||||
b.append (html_encoded (c.item.string_representation))
|
||||
b.append ("</li>")
|
||||
end
|
||||
end
|
||||
|
||||
if has_permission ("administer user roles") then
|
||||
l_roles := service.storage.user_roles
|
||||
f := new_edit_form (url (request.path_info, Void), l_roles, False)
|
||||
f.submit_actions.extend (agent edit_form_submit (?, l_roles))
|
||||
f.process (Current)
|
||||
f.append_to_html (theme, b)
|
||||
else
|
||||
b.append ("<div class=%"denied%">Access denied</div>")
|
||||
end
|
||||
|
||||
set_main_content (b)
|
||||
end
|
||||
|
||||
feature -- Forms
|
||||
|
||||
edit_form_submit (fd: CMS_FORM_DATA; a_roles: LIST [CMS_USER_ROLE])
|
||||
local
|
||||
l_role: CMS_USER_ROLE
|
||||
do
|
||||
if fd.item_same_string ("op", "Apply") then
|
||||
across
|
||||
a_roles as r
|
||||
loop
|
||||
if attached fd.table_item (r.item.name) as perms then
|
||||
r.item.permissions.wipe_out
|
||||
across
|
||||
perms as c
|
||||
loop
|
||||
if attached {WSF_STRING} c.item as s then
|
||||
r.item.add_permission (s.value)
|
||||
end
|
||||
end
|
||||
service.storage.save_user_role (r.item)
|
||||
end
|
||||
end
|
||||
elseif fd.item_same_string ("op", "Add role") then
|
||||
if attached fd.string_item ("new-role") as l_new_role then
|
||||
create l_role.make (l_new_role)
|
||||
service.storage.save_user_role (l_role)
|
||||
set_redirection (url (request.path_info, Void))
|
||||
end
|
||||
elseif fd.item_same_string ("op", "Add permission") then
|
||||
if attached fd.string_item ("new-permission") as l_new_permission then
|
||||
l_role := service.storage.authenticated_user_role
|
||||
l_role.add_permission (l_new_permission)
|
||||
service.storage.save_user_role (l_role)
|
||||
set_redirection (url (request.path_info, Void))
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
new_edit_form (a_action: READABLE_STRING_8; a_roles: LIST [CMS_USER_ROLE]; a_use_data: BOOLEAN): CMS_FORM
|
||||
local
|
||||
perms: ARRAYED_SET [READABLE_STRING_8]
|
||||
tb: CMS_WIDGET_AGENT_TABLE [READABLE_STRING_8]
|
||||
i: INTEGER
|
||||
tf: CMS_FORM_TEXT_INPUT
|
||||
do
|
||||
create perms.make (10)
|
||||
perms.compare_objects
|
||||
across
|
||||
service.modules as m
|
||||
loop
|
||||
across
|
||||
m.item.permissions (service) as p
|
||||
loop
|
||||
perms.extend (p.item.name)
|
||||
end
|
||||
end
|
||||
across
|
||||
a_roles as c
|
||||
loop
|
||||
across
|
||||
c.item.permissions as p
|
||||
loop
|
||||
perms.extend (p.item)
|
||||
end
|
||||
end
|
||||
|
||||
create tb.make
|
||||
tb.set_column_count (1 + a_roles.count)
|
||||
i := 1
|
||||
tb.column (i).set_title ("Permissions")
|
||||
across
|
||||
a_roles as r
|
||||
loop
|
||||
i := i + 1
|
||||
tb.column (i).set_title (r.item.name)
|
||||
end
|
||||
|
||||
tb.add_css_style ("border: solid 1px #999;")
|
||||
tb.set_data (perms)
|
||||
tb.set_compute_item_function (agent (p: READABLE_STRING_8; ia_roles: LIST [CMS_USER_ROLE]; ia_use_data: BOOLEAN): CMS_WIDGET_TABLE_ROW
|
||||
local
|
||||
it: CMS_WIDGET_TABLE_ITEM
|
||||
cb: CMS_FORM_CHECKBOX_INPUT
|
||||
do
|
||||
create Result.make (1 + ia_roles.count)
|
||||
create it.make_with_text (p)
|
||||
Result.set_item (it, 1)
|
||||
across
|
||||
ia_roles as r
|
||||
loop
|
||||
create cb.make (r.item.name + "[" + p + "]")
|
||||
cb.set_text_value (p)
|
||||
|
||||
if ia_use_data then
|
||||
if r.item.has_permission (p) then
|
||||
cb.set_checked (True)
|
||||
else
|
||||
cb.set_checked (False)
|
||||
end
|
||||
end
|
||||
create it.make_with_content (cb)
|
||||
Result.add_item (it)
|
||||
end
|
||||
end(?, a_roles, a_use_data)
|
||||
)
|
||||
|
||||
create Result.make (a_action, "edit-user-roles")
|
||||
Result.set_method_post
|
||||
Result.extend (tb.to_computed_table)
|
||||
Result.extend (create {CMS_FORM_SUBMIT_INPUT}.make_with_text ("op", "Apply"))
|
||||
|
||||
create tf.make ("new-role")
|
||||
tf.add_css_class ("horizontal")
|
||||
tf.set_size (24)
|
||||
tf.set_label ("New user role")
|
||||
Result.extend (tf)
|
||||
Result.extend (create {CMS_FORM_SUBMIT_INPUT}.make_with_text ("op", "Add role"))
|
||||
|
||||
create tf.make ("new-permission")
|
||||
tf.add_css_class ("horizontal")
|
||||
tf.set_size (24)
|
||||
tf.set_label ("New permission")
|
||||
Result.extend (tf)
|
||||
Result.extend (create {CMS_FORM_SUBMIT_INPUT}.make_with_text ("op", "Add permission"))
|
||||
|
||||
|
||||
|
||||
end
|
||||
|
||||
end
|
||||
@@ -41,17 +41,18 @@ feature -- Hooks
|
||||
|
||||
help_text (a_path: STRING): STRING
|
||||
do
|
||||
Result := ""
|
||||
create Result.make_empty
|
||||
end
|
||||
|
||||
permissions: LIST [TUPLE [title: detachable STRING; description: detachable STRING]]
|
||||
permissions (a_service: CMS_SERVICE): LIST [CMS_PERMISSION]
|
||||
do
|
||||
create {ARRAYED_LIST [like permissions.item]} Result.make (0)
|
||||
create {ARRAYED_SET [CMS_PERMISSION]} Result.make (0)
|
||||
end
|
||||
|
||||
links: HASH_TABLE [CMS_MODULE_LINK, STRING]
|
||||
-- Link indexed by path
|
||||
deferred
|
||||
do
|
||||
create Result.make (0)
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
36
draft/application/cms/src/modules/cms_permission.e
Normal file
36
draft/application/cms/src/modules/cms_permission.e
Normal file
@@ -0,0 +1,36 @@
|
||||
note
|
||||
description: "Summary description for {CMS_PERMISSION}."
|
||||
author: ""
|
||||
date: "$Date$"
|
||||
revision: "$Revision$"
|
||||
|
||||
class
|
||||
CMS_PERMISSION
|
||||
|
||||
create
|
||||
make
|
||||
|
||||
convert
|
||||
make ({READABLE_STRING_8, STRING_8, IMMUTABLE_STRING_8})
|
||||
|
||||
feature {NONE} -- Initialization
|
||||
|
||||
make (n: like name)
|
||||
do
|
||||
name := n
|
||||
end
|
||||
|
||||
feature -- Access
|
||||
|
||||
name: READABLE_STRING_8
|
||||
|
||||
description: detachable READABLE_STRING_8
|
||||
|
||||
feature -- Change
|
||||
|
||||
set_description (s: like description)
|
||||
do
|
||||
description := s
|
||||
end
|
||||
|
||||
end
|
||||
@@ -36,19 +36,6 @@ feature {CMS_SERVICE} -- Registration
|
||||
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]
|
||||
|
||||
@@ -6,7 +6,7 @@ class
|
||||
NODE_ADD_CMS_EXECUTION
|
||||
|
||||
inherit
|
||||
CMS_EXECUTION
|
||||
NODE_CMS_EXECUTION
|
||||
|
||||
create
|
||||
make
|
||||
@@ -19,71 +19,20 @@ feature -- Execution
|
||||
b: STRING_8
|
||||
f: like edit_form
|
||||
fd: detachable CMS_FORM_DATA
|
||||
l_preview: BOOLEAN
|
||||
l_format: detachable CMS_FORMAT
|
||||
do
|
||||
create b.make_empty
|
||||
if attached non_empty_string_path_parameter ("type") as s_type then
|
||||
if attached service.content_type (s_type) as l_type then
|
||||
f := edit_form (Void, url (request.path_info, Void), "add-" + l_type.name, l_type)
|
||||
if request.is_post_request_method then
|
||||
create fd.make (request, f)
|
||||
l_preview := attached {WSF_STRING} fd.item ("op") as l_op and then l_op.same_string ("Preview")
|
||||
end
|
||||
|
||||
set_title ("Create " + l_type.title)
|
||||
if has_permission ("create " + l_type.name) then
|
||||
|
||||
if fd /= Void and l_preview then
|
||||
b.append ("<strong>Preview</strong><div class=%"preview%">")
|
||||
if attached fd.string_item ("format") as s_format and then attached formats.format (s_format) as f_format then
|
||||
l_format := f_format
|
||||
end
|
||||
if attached fd.string_item ("title") as l_title then
|
||||
b.append ("<strong>Title:</strong><div class=%"title%">" + html_encoded (l_title) + "</div>")
|
||||
end
|
||||
if attached fd.string_item ("body") as l_body then
|
||||
b.append ("<strong>Body:</strong><div class=%"body%">")
|
||||
if l_format /= Void then
|
||||
b.append (l_format.to_html (l_body))
|
||||
else
|
||||
b.append (html_encoded (l_body))
|
||||
end
|
||||
b.append ("</div>")
|
||||
end
|
||||
b.append ("</div>")
|
||||
end
|
||||
|
||||
if fd /= Void and then fd.is_valid and not l_preview then
|
||||
across
|
||||
fd as c
|
||||
loop
|
||||
b.append ("<li>" + html_encoded (c.key) + "=")
|
||||
if attached c.item as v then
|
||||
b.append (html_encoded (v.string_representation))
|
||||
end
|
||||
b.append ("</li>")
|
||||
end
|
||||
if attached l_type.new_node (Current, fd, Void) as l_node then
|
||||
service.storage.save_node (l_node)
|
||||
if attached user as u then
|
||||
service.log ("node", "User %"" + user_link (u) + "%" created node " + link (l_type.name +" #" + l_node.id.out, "/node/" + l_node.id.out , Void), 0, node_local_link (l_node))
|
||||
else
|
||||
service.log ("node", "Anonymous created node "+ l_type.name +" #" + l_node.id.out, 0, node_local_link (l_node))
|
||||
end
|
||||
add_success_message ("Node #" + l_node.id.out + " saved.")
|
||||
set_redirection (node_url (l_node))
|
||||
end
|
||||
-- Creation ...
|
||||
else
|
||||
if fd /= Void then
|
||||
if not fd.is_valid then
|
||||
report_form_errors (fd)
|
||||
end
|
||||
fd.apply_to_associated_form
|
||||
end
|
||||
f.append_to_html (theme, b)
|
||||
if request.is_post_request_method then
|
||||
f.validation_actions.extend (agent edit_form_validate (?, b))
|
||||
f.submit_actions.extend (agent edit_form_submit (?, Void, l_type, b))
|
||||
f.process (Current)
|
||||
fd := f.last_data
|
||||
end
|
||||
f.append_to_html (theme, b)
|
||||
else
|
||||
set_title ("Access denied")
|
||||
end
|
||||
@@ -109,35 +58,4 @@ feature -- Execution
|
||||
set_main_content (b)
|
||||
end
|
||||
|
||||
edit_form (a_node: detachable CMS_NODE; a_url: READABLE_STRING_8; a_name: STRING; a_type: CMS_CONTENT_TYPE): CMS_FORM
|
||||
local
|
||||
f: CMS_FORM
|
||||
ts: CMS_FORM_SUBMIT_INPUT
|
||||
th: CMS_FORM_HIDDEN_INPUT
|
||||
do
|
||||
create f.make (a_url, a_name)
|
||||
|
||||
create th.make ("node-id")
|
||||
if a_node /= Void then
|
||||
th.set_text_value (a_node.id.out)
|
||||
else
|
||||
th.set_text_value ("0")
|
||||
end
|
||||
f.extend (th)
|
||||
|
||||
a_type.fill_edit_form (f, a_node)
|
||||
|
||||
f.extend_text ("<br/>")
|
||||
|
||||
create ts.make ("op")
|
||||
ts.set_default_value ("Save")
|
||||
f.extend (ts)
|
||||
|
||||
create ts.make ("op")
|
||||
ts.set_default_value ("Preview")
|
||||
f.extend (ts)
|
||||
|
||||
Result := f
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
141
draft/application/cms/src/modules/node/node_cms_execution.e
Normal file
141
draft/application/cms/src/modules/node/node_cms_execution.e
Normal file
@@ -0,0 +1,141 @@
|
||||
note
|
||||
description: "Summary description for {NODE_CMS_EXECUTION}."
|
||||
author: ""
|
||||
date: "$Date$"
|
||||
revision: "$Revision$"
|
||||
|
||||
deferred class
|
||||
NODE_CMS_EXECUTION
|
||||
|
||||
inherit
|
||||
CMS_EXECUTION
|
||||
|
||||
feature -- Form
|
||||
|
||||
edit_form_validate (fd: CMS_FORM_DATA; b: STRING)
|
||||
local
|
||||
l_preview: BOOLEAN
|
||||
l_format: detachable CMS_FORMAT
|
||||
do
|
||||
l_preview := attached {WSF_STRING} fd.item ("op") as l_op and then l_op.same_string ("Preview")
|
||||
if l_preview then
|
||||
b.append ("<strong>Preview</strong><div class=%"preview%">")
|
||||
if attached fd.string_item ("format") as s_format and then attached formats.format (s_format) as f_format then
|
||||
l_format := f_format
|
||||
end
|
||||
if attached fd.string_item ("title") as l_title then
|
||||
b.append ("<strong>Title:</strong><div class=%"title%">" + html_encoded (l_title) + "</div>")
|
||||
end
|
||||
if attached fd.string_item ("body") as l_body then
|
||||
b.append ("<strong>Body:</strong><div class=%"body%">")
|
||||
if l_format /= Void then
|
||||
b.append (l_format.to_html (l_body))
|
||||
else
|
||||
b.append (html_encoded (l_body))
|
||||
end
|
||||
b.append ("</div>")
|
||||
end
|
||||
b.append ("</div>")
|
||||
end
|
||||
end
|
||||
|
||||
edit_form_submit (fd: CMS_FORM_DATA; a_node: detachable CMS_NODE; a_type: CMS_CONTENT_TYPE; b: STRING)
|
||||
local
|
||||
l_preview: BOOLEAN
|
||||
l_node: detachable CMS_NODE
|
||||
s: STRING
|
||||
do
|
||||
l_preview := attached {WSF_STRING} fd.item ("op") as l_op and then l_op.same_string ("Preview")
|
||||
if not l_preview then
|
||||
debug ("cms")
|
||||
across
|
||||
fd as c
|
||||
loop
|
||||
b.append ("<li>" + html_encoded (c.key) + "=")
|
||||
if attached c.item as v then
|
||||
b.append (html_encoded (v.string_representation))
|
||||
end
|
||||
b.append ("</li>")
|
||||
end
|
||||
end
|
||||
if a_node /= Void then
|
||||
l_node := a_node
|
||||
a_type.change_node (Current, fd, a_node)
|
||||
s := "modified"
|
||||
else
|
||||
l_node := a_type.new_node (Current, fd, Void)
|
||||
s := "created"
|
||||
end
|
||||
service.storage.save_node (l_node)
|
||||
if attached user as u then
|
||||
service.log ("node", "User %"" + user_link (u) + "%" " + s + " node " + link (a_type.name +" #" + l_node.id.out, "/node/" + l_node.id.out , Void), 0, node_local_link (l_node))
|
||||
else
|
||||
service.log ("node", "Anonymous " + s + " node " + a_type.name +" #" + l_node.id.out, 0, node_local_link (l_node))
|
||||
end
|
||||
add_success_message ("Node #" + l_node.id.out + " saved.")
|
||||
set_redirection (node_url (l_node))
|
||||
end
|
||||
end
|
||||
|
||||
-- edit_form_submit (fd: CMS_FORM_DATA; a_type: CMS_CONTENT_TYPE; b: STRING)
|
||||
-- local
|
||||
-- l_preview: BOOLEAN
|
||||
-- do
|
||||
-- l_preview := attached {WSF_STRING} fd.item ("op") as l_op and then l_op.same_string ("Preview")
|
||||
-- if not l_preview then
|
||||
-- debug ("cms")
|
||||
-- across
|
||||
-- fd as c
|
||||
-- loop
|
||||
-- b.append ("<li>" + html_encoded (c.key) + "=")
|
||||
-- if attached c.item as v then
|
||||
-- b.append (html_encoded (v.string_representation))
|
||||
-- end
|
||||
-- b.append ("</li>")
|
||||
-- end
|
||||
-- end
|
||||
-- if attached a_type.new_node (Current, fd, Void) as l_node then
|
||||
-- service.storage.save_node (l_node)
|
||||
-- if attached user as u then
|
||||
-- service.log ("node", "User %"" + user_link (u) + "%" created node " + link (a_type.name +" #" + l_node.id.out, "/node/" + l_node.id.out , Void), 0, node_local_link (l_node))
|
||||
-- else
|
||||
-- service.log ("node", "Anonymous created node "+ a_type.name +" #" + l_node.id.out, 0, node_local_link (l_node))
|
||||
-- end
|
||||
-- add_success_message ("Node #" + l_node.id.out + " saved.")
|
||||
-- set_redirection (node_url (l_node))
|
||||
-- end
|
||||
-- end
|
||||
-- end
|
||||
|
||||
edit_form (a_node: detachable CMS_NODE; a_url: READABLE_STRING_8; a_name: STRING; a_type: CMS_CONTENT_TYPE): CMS_FORM
|
||||
local
|
||||
f: CMS_FORM
|
||||
ts: CMS_FORM_SUBMIT_INPUT
|
||||
th: CMS_FORM_HIDDEN_INPUT
|
||||
do
|
||||
create f.make (a_url, a_name)
|
||||
|
||||
create th.make ("node-id")
|
||||
if a_node /= Void then
|
||||
th.set_text_value (a_node.id.out)
|
||||
else
|
||||
th.set_text_value ("0")
|
||||
end
|
||||
f.extend (th)
|
||||
|
||||
a_type.fill_edit_form (f, a_node)
|
||||
|
||||
f.extend_text ("<br/>")
|
||||
|
||||
create ts.make ("op")
|
||||
ts.set_default_value ("Save")
|
||||
f.extend (ts)
|
||||
|
||||
create ts.make ("op")
|
||||
ts.set_default_value ("Preview")
|
||||
f.extend (ts)
|
||||
|
||||
Result := f
|
||||
end
|
||||
|
||||
end
|
||||
@@ -6,7 +6,7 @@ class
|
||||
NODE_EDIT_CMS_EXECUTION
|
||||
|
||||
inherit
|
||||
CMS_EXECUTION
|
||||
NODE_CMS_EXECUTION
|
||||
|
||||
create
|
||||
make
|
||||
@@ -19,8 +19,6 @@ feature -- Execution
|
||||
b: STRING_8
|
||||
f: like edit_form
|
||||
fd: detachable CMS_FORM_DATA
|
||||
l_preview: BOOLEAN
|
||||
l_format: detachable CMS_FORMAT
|
||||
do
|
||||
create b.make_empty
|
||||
if
|
||||
@@ -32,8 +30,10 @@ feature -- Execution
|
||||
if has_permission ("edit " + l_type.name) then
|
||||
f := edit_form (l_node, url (request.path_info, Void), "edit-" + l_type.name, l_type)
|
||||
if request.is_post_request_method then
|
||||
create fd.make (request, f)
|
||||
l_preview := attached {WSF_STRING} fd.item ("op") as l_op and then l_op.same_string ("Preview")
|
||||
f.validation_actions.extend (agent edit_form_validate (?, b))
|
||||
f.submit_actions.extend (agent edit_form_submit (?, l_node, l_type, b))
|
||||
f.process (Current)
|
||||
fd := f.last_data
|
||||
end
|
||||
|
||||
set_title ("Edit #" + l_node.id.out)
|
||||
@@ -41,54 +41,7 @@ feature -- Execution
|
||||
add_to_menu (create {CMS_LOCAL_LINK}.make ("View", node_url (l_node)), primary_tabs)
|
||||
add_to_menu (create {CMS_LOCAL_LINK}.make ("Edit", "/node/" + l_node.id.out + "/edit"), primary_tabs)
|
||||
|
||||
if fd /= Void and l_preview then
|
||||
b.append ("<strong>Preview</strong><div class=%"preview%">")
|
||||
if attached fd.string_item ("format") as s_format and then attached formats.format (s_format) as f_format then
|
||||
l_format := f_format
|
||||
end
|
||||
if attached fd.string_item ("title") as l_title then
|
||||
b.append ("<strong>Title:</strong><div class=%"title%">" + html_encoded (l_title) + "</div>")
|
||||
end
|
||||
if attached fd.string_item ("body") as l_body then
|
||||
b.append ("<strong>Body:</strong><div class=%"body%">")
|
||||
if l_format /= Void then
|
||||
b.append (l_format.to_html (l_body))
|
||||
else
|
||||
b.append (html_encoded (l_body))
|
||||
end
|
||||
b.append ("</div>")
|
||||
end
|
||||
b.append ("</div>")
|
||||
end
|
||||
|
||||
if fd /= Void and then fd.is_valid and not l_preview then
|
||||
across
|
||||
fd as c
|
||||
loop
|
||||
b.append ("<li>" + html_encoded (c.key) + "=")
|
||||
if attached c.item as v then
|
||||
b.append (html_encoded (v.string_representation))
|
||||
end
|
||||
b.append ("</li>")
|
||||
end
|
||||
l_type.change_node (Current, fd, l_node)
|
||||
service.storage.save_node (l_node)
|
||||
if attached user as u then
|
||||
service.log ("node", "User %"" + user_link (u) + "%" modified node " + link (l_type.name +" #" + l_node.id.out, "/node/" + l_node.id.out , Void), 0, node_local_link (l_node))
|
||||
else
|
||||
service.log ("node", "Anonymous modified node "+ l_type.name +" #" + l_node.id.out, 0, node_local_link (l_node))
|
||||
end
|
||||
add_success_message ("Node #" + l_node.id.out + " saved.")
|
||||
set_redirection (node_url (l_node))
|
||||
else
|
||||
if fd /= Void then
|
||||
if not fd.is_valid then
|
||||
report_form_errors (fd)
|
||||
end
|
||||
fd.apply_to_associated_form
|
||||
end
|
||||
f.append_to_html (theme, b)
|
||||
end
|
||||
f.append_to_html (theme, b)
|
||||
else
|
||||
b.append ("<h1>Access denied</h1>")
|
||||
end
|
||||
@@ -114,35 +67,100 @@ feature -- Execution
|
||||
set_main_content (b)
|
||||
end
|
||||
|
||||
edit_form (a_node: detachable CMS_NODE; a_url: READABLE_STRING_8; a_name: STRING; a_type: CMS_CONTENT_TYPE): CMS_FORM
|
||||
local
|
||||
f: CMS_FORM
|
||||
ts: CMS_FORM_SUBMIT_INPUT
|
||||
th: CMS_FORM_HIDDEN_INPUT
|
||||
do
|
||||
create f.make (a_url, a_name)
|
||||
-- edit_form_validate (fd: CMS_FORM_DATA; b: STRING)
|
||||
-- local
|
||||
-- l_preview: BOOLEAN
|
||||
-- l_format: detachable CMS_FORMAT
|
||||
-- do
|
||||
-- l_preview := attached {WSF_STRING} fd.item ("op") as l_op and then l_op.same_string ("Preview")
|
||||
-- if l_preview then
|
||||
-- b.append ("<strong>Preview</strong><div class=%"preview%">")
|
||||
-- if attached fd.string_item ("format") as s_format and then attached formats.format (s_format) as f_format then
|
||||
-- l_format := f_format
|
||||
-- end
|
||||
-- if attached fd.string_item ("title") as l_title then
|
||||
-- b.append ("<strong>Title:</strong><div class=%"title%">" + html_encoded (l_title) + "</div>")
|
||||
-- end
|
||||
-- if attached fd.string_item ("body") as l_body then
|
||||
-- b.append ("<strong>Body:</strong><div class=%"body%">")
|
||||
-- if l_format /= Void then
|
||||
-- b.append (l_format.to_html (l_body))
|
||||
-- else
|
||||
-- b.append (html_encoded (l_body))
|
||||
-- end
|
||||
-- b.append ("</div>")
|
||||
-- end
|
||||
-- b.append ("</div>")
|
||||
-- end
|
||||
-- end
|
||||
|
||||
create th.make ("node-id")
|
||||
if a_node /= Void then
|
||||
th.set_text_value (a_node.id.out)
|
||||
else
|
||||
th.set_text_value ("0")
|
||||
end
|
||||
f.extend (th)
|
||||
-- edit_form_submit (fd: CMS_FORM_DATA; a_node: detachable CMS_NODE; a_type: CMS_CONTENT_TYPE; b: STRING)
|
||||
-- local
|
||||
-- l_preview: BOOLEAN
|
||||
-- l_node: detachable CMS_NODE
|
||||
-- s: STRING
|
||||
-- do
|
||||
-- l_preview := attached {WSF_STRING} fd.item ("op") as l_op and then l_op.same_string ("Preview")
|
||||
-- if not l_preview then
|
||||
-- debug ("cms")
|
||||
-- across
|
||||
-- fd as c
|
||||
-- loop
|
||||
-- b.append ("<li>" + html_encoded (c.key) + "=")
|
||||
-- if attached c.item as v then
|
||||
-- b.append (html_encoded (v.string_representation))
|
||||
-- end
|
||||
-- b.append ("</li>")
|
||||
-- end
|
||||
-- end
|
||||
-- if a_node /= Void then
|
||||
-- l_node := a_node
|
||||
-- a_type.change_node (Current, fd, a_node)
|
||||
-- s := "modified"
|
||||
-- else
|
||||
-- l_node := a_type.new_node (Current, fd, Void)
|
||||
-- s := "created"
|
||||
-- end
|
||||
-- service.storage.save_node (l_node)
|
||||
-- if attached user as u then
|
||||
-- service.log ("node", "User %"" + user_link (u) + "%" " + s + " node " + link (a_type.name +" #" + l_node.id.out, "/node/" + l_node.id.out , Void), 0, node_local_link (l_node))
|
||||
-- else
|
||||
-- service.log ("node", "Anonymous " + s + " node " + a_type.name +" #" + l_node.id.out, 0, node_local_link (l_node))
|
||||
-- end
|
||||
-- add_success_message ("Node #" + l_node.id.out + " saved.")
|
||||
-- set_redirection (node_url (l_node))
|
||||
-- end
|
||||
-- end
|
||||
|
||||
a_type.fill_edit_form (f, a_node)
|
||||
-- edit_form (a_node: detachable CMS_NODE; a_url: READABLE_STRING_8; a_name: STRING; a_type: CMS_CONTENT_TYPE): CMS_FORM
|
||||
-- local
|
||||
-- f: CMS_FORM
|
||||
-- ts: CMS_FORM_SUBMIT_INPUT
|
||||
-- th: CMS_FORM_HIDDEN_INPUT
|
||||
-- do
|
||||
-- create f.make (a_url, a_name)
|
||||
|
||||
f.extend_text ("<br/>")
|
||||
-- create th.make ("node-id")
|
||||
-- if a_node /= Void then
|
||||
-- th.set_text_value (a_node.id.out)
|
||||
-- else
|
||||
-- th.set_text_value ("0")
|
||||
-- end
|
||||
-- f.extend (th)
|
||||
|
||||
create ts.make ("op")
|
||||
ts.set_default_value ("Save")
|
||||
f.extend (ts)
|
||||
-- a_type.fill_edit_form (f, a_node)
|
||||
|
||||
create ts.make ("op")
|
||||
ts.set_default_value ("Preview")
|
||||
f.extend (ts)
|
||||
-- f.extend_text ("<br/>")
|
||||
|
||||
Result := f
|
||||
end
|
||||
-- create ts.make ("op")
|
||||
-- ts.set_default_value ("Save")
|
||||
-- f.extend (ts)
|
||||
|
||||
-- create ts.make ("op")
|
||||
-- ts.set_default_value ("Preview")
|
||||
-- f.extend (ts)
|
||||
|
||||
-- Result := f
|
||||
-- end
|
||||
|
||||
end
|
||||
|
||||
@@ -9,6 +9,9 @@ class
|
||||
|
||||
inherit
|
||||
CMS_MODULE
|
||||
redefine
|
||||
permissions
|
||||
end
|
||||
|
||||
CMS_HOOK_MENU_ALTER
|
||||
|
||||
@@ -29,6 +32,20 @@ feature {NONE} -- Initialization
|
||||
enable
|
||||
end
|
||||
|
||||
feature -- Access
|
||||
|
||||
permissions (a_service: CMS_SERVICE): LIST [CMS_PERMISSION]
|
||||
do
|
||||
Result := Precursor (a_service)
|
||||
across
|
||||
a_service.content_types as c
|
||||
loop
|
||||
Result.extend ("create " + c.item.name)
|
||||
Result.extend ("edit " + c.item.name)
|
||||
Result.extend ("delete " + c.item.name)
|
||||
end
|
||||
end
|
||||
|
||||
feature {CMS_SERVICE} -- Registration
|
||||
|
||||
service: detachable CMS_SERVICE
|
||||
@@ -51,6 +68,7 @@ feature {CMS_SERVICE} -- Registration
|
||||
|
||||
a_service.add_menu_alter_hook (Current)
|
||||
a_service.add_block_hook (Current)
|
||||
|
||||
end
|
||||
|
||||
feature -- Hooks
|
||||
@@ -76,18 +94,19 @@ feature -- Hooks
|
||||
menu_alter (a_menu_system: CMS_MENU_SYSTEM; a_execution: CMS_EXECUTION)
|
||||
local
|
||||
lnk: CMS_LOCAL_LINK
|
||||
perms: detachable ARRAYED_LIST [READABLE_STRING_8]
|
||||
do
|
||||
if a_execution.authenticated then
|
||||
create lnk.make ("Add content", "/node/add/")
|
||||
lnk.set_permission_arguments (<<"authenticated">>)
|
||||
a_menu_system.navigation_menu.extend (lnk)
|
||||
if attached a_execution.service.content_types as lst then
|
||||
create perms.make (lst.count)
|
||||
across
|
||||
lst as c
|
||||
loop
|
||||
perms.force ("create " + c.item.name)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
links: HASH_TABLE [CMS_MODULE_LINK, STRING]
|
||||
-- Link indexed by path
|
||||
do
|
||||
create Result.make (0)
|
||||
create lnk.make ("Add content", "/node/add/")
|
||||
lnk.set_permission_arguments (perms)
|
||||
a_menu_system.navigation_menu.extend (lnk)
|
||||
end
|
||||
|
||||
handle_node_view (cms: CMS_SERVICE; req: WSF_REQUEST; res: WSF_RESPONSE)
|
||||
|
||||
@@ -6,7 +6,7 @@ class
|
||||
NODE_VIEW_CMS_EXECUTION
|
||||
|
||||
inherit
|
||||
CMS_EXECUTION
|
||||
NODE_CMS_EXECUTION
|
||||
|
||||
create
|
||||
make
|
||||
|
||||
149
draft/application/cms/src/modules/openid/openid_cms_execution.e
Normal file
149
draft/application/cms/src/modules/openid/openid_cms_execution.e
Normal file
@@ -0,0 +1,149 @@
|
||||
note
|
||||
description: "Summary description for {OPENID_CMS_EXECUTION}."
|
||||
date: "$Date$"
|
||||
revision: "$Revision$"
|
||||
|
||||
class
|
||||
OPENID_CMS_EXECUTION
|
||||
|
||||
inherit
|
||||
CMS_EXECUTION
|
||||
|
||||
create
|
||||
make
|
||||
|
||||
feature -- Execution
|
||||
|
||||
process
|
||||
local
|
||||
b: STRING
|
||||
f: CMS_FORM
|
||||
tf: CMS_FORM_TEXT_INPUT
|
||||
ts: CMS_FORM_SUBMIT_INPUT
|
||||
o: OPENID_CONSUMER
|
||||
v: OPENID_CONSUMER_VALIDATION
|
||||
tb: HASH_TABLE [READABLE_STRING_8, STRING_8]
|
||||
l_uid: INTEGER
|
||||
do
|
||||
create b.make_empty
|
||||
set_title ("OpenID identities")
|
||||
if attached request.string_item ("openid.mode") as l_openid_mode then
|
||||
-- Callback
|
||||
create o.make (request.absolute_script_url ("/openid/login"))
|
||||
o.ask_email (True)
|
||||
o.ask_nickname (False)
|
||||
-- o.ask_all_info (False)
|
||||
|
||||
create v.make_from_items (o, request.items_as_string_items)
|
||||
v.validate
|
||||
if v.is_valid then
|
||||
if attached v.identity as l_identity then
|
||||
if attached user as u then
|
||||
if attached service.storage.custom_value (l_identity, "openid") as obj then
|
||||
l_uid := user_id_from_custom_value (obj)
|
||||
if l_uid > 0 and then l_uid = u.id then
|
||||
-- Authenticated
|
||||
b.append ("OpenID already associated to user %""+ user_link (u) +"%"")
|
||||
else
|
||||
-- Wrong USER !!!
|
||||
b.append ("OpenID already associated to another user !!!")
|
||||
end
|
||||
else
|
||||
-- New OpenID association
|
||||
create tb.make (1)
|
||||
tb.force (l_identity, "openid_identity")
|
||||
tb.force (u.id.out, "uid")
|
||||
service.storage.set_custom_value (l_identity, tb, "openid")
|
||||
|
||||
b.append ("OpenID %""+ l_identity +"%" is now associated with user %""+ user_link (u) +"%"")
|
||||
end
|
||||
else
|
||||
if
|
||||
attached service.storage.custom_value (l_identity, "openid") as obj and then
|
||||
attached user_id_from_custom_value (obj) as obj_uid and then
|
||||
obj_uid > 0 and then
|
||||
attached service.storage.user_by_id (obj_uid.to_integer) as u
|
||||
then
|
||||
-- Authenticated
|
||||
set_user (u)
|
||||
b.append ("Authenticated as %""+ user_link (u) +"%"")
|
||||
set_redirection (user_url (u))
|
||||
else
|
||||
-- Register new account
|
||||
b.append ("Register new account associated with Openid %"" + l_identity + "%"?")
|
||||
across
|
||||
v.attributes as c
|
||||
loop
|
||||
b.append ("<li>" + c.key + "=" + c.item + "</li>")
|
||||
end
|
||||
set_session_item ("openid.identity", l_identity)
|
||||
if attached v.email_attribute as att_email then
|
||||
set_session_item ("openid.email", att_email)
|
||||
end
|
||||
if attached v.nickname_attribute as att_nickname then
|
||||
set_session_item ("openid.nickname", att_nickname)
|
||||
end
|
||||
b.append ("Create new account from your OpenID ")
|
||||
b.append (link ("Register new account", "/user/register", Void))
|
||||
set_redirection (url ("/user/register", Void))
|
||||
end
|
||||
end
|
||||
end
|
||||
else
|
||||
b.append ("User authentication failed!!")
|
||||
end
|
||||
elseif attached request.string_item ("openid") as p_openid then
|
||||
b.append ("Check openID: " + p_openid)
|
||||
create o.make (request.absolute_script_url ("/openid/login"))
|
||||
o.ask_email (True)
|
||||
o.ask_all_info (False)
|
||||
if attached o.auth_url (p_openid) as l_url then
|
||||
set_redirection (l_url)
|
||||
else
|
||||
b.append ("Failure")
|
||||
end
|
||||
else
|
||||
if attached user as u then
|
||||
if attached service.storage.custom_value_names_where ("uid", u.id.out, "openid") as lst then
|
||||
across
|
||||
lst as c
|
||||
loop
|
||||
b.append ("<li>OpenID: " + c.item + "</li>")
|
||||
end
|
||||
else
|
||||
b.append ("No OpenID associated with current account")
|
||||
end
|
||||
end
|
||||
create f.make (url ("/openid/login", Void), "openid-login")
|
||||
create tf.make ("openid")
|
||||
tf.set_size (50)
|
||||
tf.set_text_value ("")
|
||||
tf.set_label ("OpenID identifier")
|
||||
f.extend (tf)
|
||||
create ts.make_with_text ("op", "Validate")
|
||||
f.extend (ts)
|
||||
f.prepare (Current)
|
||||
f.append_to_html (theme, b)
|
||||
end
|
||||
set_main_content (b)
|
||||
end
|
||||
|
||||
user_id_from_custom_value (lst: TABLE_ITERABLE [READABLE_STRING_8, STRING_8]): INTEGER
|
||||
local
|
||||
l_uid: detachable READABLE_STRING_8
|
||||
do
|
||||
across
|
||||
lst as c
|
||||
until
|
||||
l_uid /= Void
|
||||
loop
|
||||
if c.key.same_string ("uid") then
|
||||
l_uid := c.item
|
||||
end
|
||||
end
|
||||
if l_uid /= Void and then l_uid.is_integer then
|
||||
Result := l_uid.to_integer
|
||||
end
|
||||
end
|
||||
|
||||
end
|
||||
141
draft/application/cms/src/modules/openid/openid_module.e
Normal file
141
draft/application/cms/src/modules/openid/openid_module.e
Normal file
@@ -0,0 +1,141 @@
|
||||
note
|
||||
description: "Summary description for {OPENID_MODULE}."
|
||||
author: ""
|
||||
date: "$Date$"
|
||||
revision: "$Revision$"
|
||||
|
||||
class
|
||||
OPENID_MODULE
|
||||
|
||||
inherit
|
||||
CMS_MODULE
|
||||
|
||||
CMS_HOOK_MENU_ALTER
|
||||
|
||||
CMS_HOOK_FORM_ALTER
|
||||
|
||||
CMS_HOOK_AUTO_REGISTER
|
||||
|
||||
create
|
||||
make
|
||||
|
||||
feature {NONE} -- Initialization
|
||||
|
||||
make
|
||||
do
|
||||
name := "openid"
|
||||
version := "1.0"
|
||||
description := "OpenID login support"
|
||||
package := "server"
|
||||
end
|
||||
|
||||
feature {CMS_SERVICE} -- Registration
|
||||
|
||||
service: detachable CMS_SERVICE
|
||||
|
||||
register (a_service: CMS_SERVICE)
|
||||
do
|
||||
a_service.map_uri ("/openid/login", agent handle_login)
|
||||
|
||||
a_service.add_menu_alter_hook (Current)
|
||||
service := a_service
|
||||
end
|
||||
|
||||
feature -- Hooks
|
||||
|
||||
menu_alter (a_menu_system: CMS_MENU_SYSTEM; a_execution: CMS_EXECUTION)
|
||||
local
|
||||
lnk: CMS_LOCAL_LINK
|
||||
req: WSF_REQUEST
|
||||
do
|
||||
req := a_execution.request
|
||||
if req.path_info.starts_with ("/user") then
|
||||
if a_execution.authenticated then
|
||||
create lnk.make ("Openid identities", "/openid/login")
|
||||
else
|
||||
create lnk.make ("Login with Openid", "/openid/login")
|
||||
end
|
||||
-- a_menu_system.management_menu.extend (lnk)
|
||||
a_menu_system.primary_tabs.extend (lnk)
|
||||
end
|
||||
end
|
||||
|
||||
form_alter (a_form: CMS_FORM; a_form_data: detachable CMS_FORM_DATA; a_execution: CMS_EXECUTION)
|
||||
local
|
||||
i: CMS_FORM_DIV
|
||||
fh: CMS_FORM_HIDDEN_INPUT
|
||||
do
|
||||
if a_form.id.same_string ("openid-login") then
|
||||
create i.make_with_text_and_css_id (
|
||||
"Login with " + a_execution.link ("OpenID", "/openid/login", Void)
|
||||
+ " , " + a_execution.link ("Google", "/openid/login?openid=https://www.google.com/accounts/o8/id", Void)
|
||||
+ " , " + a_execution.link ("Yahoo", "/openid/login?openid=https://me.yahoo.com/", Void)
|
||||
,
|
||||
"openid"
|
||||
)
|
||||
a_form.extend (i)
|
||||
elseif a_form.id.same_string ("user-login") then
|
||||
create i.make_with_text_and_css_id (
|
||||
"Login with " + a_execution.link ("OpenID", "/openid/login", Void)
|
||||
+ " , " + a_execution.link ("Google", "/openid/login?openid=https://www.google.com/accounts/o8/id", Void)
|
||||
+ " , " + a_execution.link ("Yahoo", "/openid/login?openid=https://me.yahoo.com/", Void)
|
||||
,
|
||||
"openid"
|
||||
)
|
||||
if attached a_form.items_by_type ({CMS_WIDGET_TEXT}) as lst and then not lst.is_empty then
|
||||
a_form.insert_before (i, lst.last)
|
||||
else
|
||||
a_form.extend (i)
|
||||
end
|
||||
elseif a_form.id.same_string ("user-register") then
|
||||
if attached {READABLE_STRING_GENERAL} a_execution.session_item ("openid.identity") as l_openid_identity then
|
||||
create fh.make_with_text ("openid-identity", l_openid_identity.to_string_32)
|
||||
a_execution.remove_session_item ("openid.identity")
|
||||
a_form.extend (fh)
|
||||
a_form.extend_text ("The new account will be associated with OpenID %""+ l_openid_identity +"%"")
|
||||
if attached {READABLE_STRING_GENERAL} a_execution.session_item ("openid.nickname") as l_openid_nickname then
|
||||
if attached a_form.fields_by_name ("username") as f_lst then
|
||||
across
|
||||
f_lst as c
|
||||
loop
|
||||
if attached {CMS_FORM_TEXT_INPUT} c.item as txt then
|
||||
txt.set_text_value (l_openid_nickname.to_string_32)
|
||||
end
|
||||
end
|
||||
end
|
||||
a_execution.remove_session_item ("openid.nickname")
|
||||
end
|
||||
if attached {READABLE_STRING_GENERAL} a_execution.session_item ("openid.email") as l_openid_email then
|
||||
if attached a_form.fields_by_name ("email") as f_lst then
|
||||
across
|
||||
f_lst as c
|
||||
loop
|
||||
if attached {CMS_FORM_TEXT_INPUT} c.item as txt then
|
||||
txt.set_text_value (l_openid_email.to_string_32)
|
||||
end
|
||||
end
|
||||
end
|
||||
a_execution.remove_session_item ("openid.email")
|
||||
end
|
||||
a_form.submit_actions.extend (agent openid_user_register_submitted)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
openid_user_register_submitted (a_form_data: CMS_FORM_DATA)
|
||||
do
|
||||
|
||||
end
|
||||
|
||||
feature -- Access
|
||||
|
||||
handle_login (req: WSF_REQUEST; res: WSF_RESPONSE)
|
||||
do
|
||||
if attached service as l_service then
|
||||
(create {OPENID_CMS_EXECUTION}.make (req, res, l_service)).execute
|
||||
else
|
||||
res.set_status_code ({HTTP_STATUS_CODE}.expectation_failed)
|
||||
end
|
||||
end
|
||||
|
||||
end
|
||||
@@ -20,6 +20,7 @@ feature -- Execution
|
||||
local
|
||||
b: STRING_8
|
||||
u: detachable CMS_USER
|
||||
l_first: BOOLEAN
|
||||
do
|
||||
if attached {WSF_STRING} request.path_parameter ("uid") as p_uid then
|
||||
if p_uid.is_integer then
|
||||
@@ -43,6 +44,25 @@ feature -- Execution
|
||||
if attached u.email as l_email then
|
||||
b.append ("<li>Email: <a mailto=%""+ l_email +"%">"+ l_email +"</a></li>")
|
||||
end
|
||||
if has_permission ("administer users") and attached u.roles as u_roles then
|
||||
b.append ("<li>Roles:")
|
||||
l_first := True
|
||||
across
|
||||
u_roles as r
|
||||
loop
|
||||
if l_first then
|
||||
l_first := False
|
||||
else
|
||||
b.append (", ")
|
||||
end
|
||||
if attached service.storage.user_role_by_id (r.item) as ur then
|
||||
b.append (ur.name)
|
||||
else
|
||||
b.append (r.item.out)
|
||||
end
|
||||
end
|
||||
b.append ("</li>")
|
||||
end
|
||||
b.append ("<li>Created: "+ u.creation_date.out +"</li>%N")
|
||||
if attached u.last_login_date as dt then
|
||||
b.append ("<li>Last signed: "+ dt.out +"</li>%N")
|
||||
@@ -84,20 +104,23 @@ feature -- Execution
|
||||
if l_url = Void then
|
||||
l_url := request.script_url ("/user")
|
||||
end
|
||||
f := login_form (url ("/user", Void), "login-form", l_url)
|
||||
service.call_form_alter_hooks (f, Current)
|
||||
|
||||
f := login_form (url ("/user", Void), "user-login", l_url)
|
||||
if request.is_request_method ("post") then
|
||||
create fd.make (request, f)
|
||||
if fd.is_valid then
|
||||
on_form_submitted (fd)
|
||||
if attached {WSF_STRING} fd.integer_item ("form-destination") as s_dest then
|
||||
l_url := request.script_url (s_dest.value)
|
||||
end
|
||||
end
|
||||
f.submit_actions.extend (agent on_form_submitted)
|
||||
f.process (Current)
|
||||
fd := f.last_data
|
||||
else
|
||||
f.prepare (Current)
|
||||
end
|
||||
|
||||
if authenticated then
|
||||
if
|
||||
fd /= Void and then fd.is_valid and then
|
||||
attached {WSF_STRING} fd.integer_item ("form-destination") as s_dest
|
||||
then
|
||||
l_url := request.script_url (s_dest.value)
|
||||
end
|
||||
|
||||
set_redirection (l_url)
|
||||
set_title ("Login")
|
||||
create b.make_empty
|
||||
@@ -106,12 +129,6 @@ feature -- Execution
|
||||
else
|
||||
set_title ("Login")
|
||||
create b.make_empty
|
||||
if fd /= Void then
|
||||
if not fd.is_valid then
|
||||
report_form_errors (fd)
|
||||
end
|
||||
fd.apply_to_associated_form
|
||||
end
|
||||
f.append_to_html (theme, b)
|
||||
set_main_content (b)
|
||||
end
|
||||
@@ -146,6 +163,8 @@ feature -- Execution
|
||||
ti: CMS_FORM_TEXT_INPUT
|
||||
tp: CMS_FORM_PASSWORD_INPUT
|
||||
ts: CMS_FORM_SUBMIT_INPUT
|
||||
l_logo: CMS_FORM_RAW_TEXT
|
||||
d: CMS_FORM_DIV
|
||||
do
|
||||
create Result.make (a_action, a_form_name)
|
||||
|
||||
@@ -153,27 +172,32 @@ feature -- Execution
|
||||
th.set_default_value (a_destination)
|
||||
Result.extend (th)
|
||||
|
||||
create l_logo.make ("[
|
||||
<img class="logo" 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=="
|
||||
/>
|
||||
]"
|
||||
)
|
||||
create ti.make (form_username_or_email_name)
|
||||
ti.set_label ("Username or email")
|
||||
ti.set_is_required (True)
|
||||
Result.extend (ti)
|
||||
|
||||
create tp.make (form_password_name)
|
||||
tp.set_label ("Password")
|
||||
tp.set_is_required (True)
|
||||
tp.set_description (link ("Reset password", "/user/password", Void))
|
||||
Result.extend (tp)
|
||||
|
||||
Result.extend_text ("[
|
||||
<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;"/>
|
||||
]")
|
||||
|
||||
create ts.make ("op")
|
||||
ts.set_default_value ("Log in")
|
||||
|
||||
create d.make_with_item (ti)
|
||||
d.add_css_class ("input")
|
||||
d.extend (tp)
|
||||
Result.extend (l_logo)
|
||||
Result.extend (d)
|
||||
Result.extend (ts)
|
||||
|
||||
Result.extend_text ("<p>Need an account?<br/>" + link ("Sign up now!", "/user/register", Void) + "</p>")
|
||||
Result.extend_text ("<div>Need an account?<br/>" + link ("Sign up now!", "/user/register", Void) + "</div>")
|
||||
end
|
||||
|
||||
form_username_or_email_name: STRING = "name"
|
||||
|
||||
@@ -21,8 +21,7 @@ feature -- Execution
|
||||
b: STRING_8
|
||||
f: CMS_FORM
|
||||
fd: detachable CMS_FORM_DATA
|
||||
u, fu: detachable CMS_USER
|
||||
up: detachable CMS_USER_PROFILE
|
||||
u: detachable CMS_USER
|
||||
l_is_editing_current_user: BOOLEAN
|
||||
do
|
||||
if attached {WSF_STRING} request.path_parameter ("uid") as p_uid and then p_uid.is_integer then
|
||||
@@ -50,67 +49,92 @@ feature -- Execution
|
||||
f := edit_form (u, url (request.path_info, Void), "user-edit")
|
||||
|
||||
if request.is_post_request_method then
|
||||
create fd.make (request, f)
|
||||
if attached {WSF_STRING} fd.item ("username") as s_username then
|
||||
fu := service.storage.user_by_name (s_username.value)
|
||||
if fu = Void then
|
||||
fd.report_invalid_field ("username", "User does not exist!")
|
||||
end
|
||||
end
|
||||
if attached {WSF_STRING} fd.item ("email") as s_email then
|
||||
fu := service.storage.user_by_email (s_email.value)
|
||||
if fu /= Void and then fu.id /= u.id then
|
||||
fd.report_invalid_field ("email", "Email is already used by another user!")
|
||||
end
|
||||
end
|
||||
fu := Void
|
||||
end
|
||||
if fd /= Void and then fd.is_valid then
|
||||
across
|
||||
fd as c
|
||||
loop
|
||||
b.append ("<li>" + html_encoded (c.key) + "=")
|
||||
if attached c.item as v then
|
||||
b.append (html_encoded (v.string_representation))
|
||||
end
|
||||
b.append ("</li>")
|
||||
end
|
||||
|
||||
if attached {WSF_STRING} fd.item ("password") as s_password and then not s_password.is_empty then
|
||||
u.set_password (s_password.value)
|
||||
end
|
||||
if attached {WSF_STRING} fd.item ("email") as s_email then
|
||||
u.set_email (s_email.value)
|
||||
end
|
||||
|
||||
if attached {WSF_STRING} fd.item ("note") as s_note then
|
||||
up := u.profile
|
||||
if up = Void then
|
||||
create up.make
|
||||
end
|
||||
up.force (s_note.value, "note")
|
||||
u.set_profile (up)
|
||||
end
|
||||
|
||||
service.storage.save_user (u)
|
||||
if l_is_editing_current_user and u /= user then
|
||||
set_user (u)
|
||||
end
|
||||
set_redirection (url ("/user", Void))
|
||||
set_main_content (b)
|
||||
f.validation_actions.extend (agent edit_form_validate (?, u))
|
||||
f.submit_actions.extend (agent edit_form_submit (?, u, l_is_editing_current_user, b))
|
||||
f.process (Current)
|
||||
fd := f.last_data
|
||||
else
|
||||
if fd /= Void then
|
||||
if not fd.is_valid then
|
||||
report_form_errors (fd)
|
||||
end
|
||||
fd.apply_to_associated_form
|
||||
end
|
||||
f.append_to_html (theme, b)
|
||||
f.prepare (Current)
|
||||
end
|
||||
|
||||
f.append_to_html (theme, b)
|
||||
|
||||
end
|
||||
set_main_content (b)
|
||||
end
|
||||
|
||||
edit_form_validate (fd: CMS_FORM_DATA; u: CMS_USER)
|
||||
local
|
||||
fu: detachable CMS_USER
|
||||
do
|
||||
if attached {WSF_STRING} fd.item ("username") as s_username then
|
||||
fu := service.storage.user_by_name (s_username.value)
|
||||
if fu = Void then
|
||||
fd.report_invalid_field ("username", "User does not exist!")
|
||||
end
|
||||
end
|
||||
if attached {WSF_STRING} fd.item ("email") as s_email then
|
||||
fu := service.storage.user_by_email (s_email.value)
|
||||
if fu /= Void and then fu.id /= u.id then
|
||||
fd.report_invalid_field ("email", "Email is already used by another user!")
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
edit_form_submit (fd: CMS_FORM_DATA; u: CMS_USER; a_is_editing_current_user: BOOLEAN; b: STRING)
|
||||
local
|
||||
up: detachable CMS_USER_PROFILE
|
||||
l_roles: like {CMS_USER}.roles
|
||||
do
|
||||
debug
|
||||
across
|
||||
fd as c
|
||||
loop
|
||||
b.append ("<li>" + html_encoded (c.key) + "=")
|
||||
if attached c.item as v then
|
||||
b.append (html_encoded (v.string_representation))
|
||||
end
|
||||
b.append ("</li>")
|
||||
end
|
||||
end
|
||||
|
||||
if attached {WSF_STRING} fd.item ("password") as s_password and then not s_password.is_empty then
|
||||
u.set_password (s_password.value)
|
||||
end
|
||||
if attached {WSF_STRING} fd.item ("email") as s_email then
|
||||
u.set_email (s_email.value)
|
||||
end
|
||||
|
||||
if attached {WSF_STRING} fd.item ("note") as s_note then
|
||||
up := u.profile
|
||||
if up = Void then
|
||||
create up.make
|
||||
end
|
||||
up.force (s_note.value, "note")
|
||||
u.set_profile (up)
|
||||
end
|
||||
if has_permission ("administer users") then
|
||||
l_roles := u.roles
|
||||
u.clear_roles
|
||||
if attached fd.table_item ("roles") as f_roles and then not f_roles.is_empty then
|
||||
create {ARRAYED_LIST [INTEGER]} l_roles.make (f_roles.count)
|
||||
across
|
||||
f_roles as r
|
||||
loop
|
||||
if attached {WSF_STRING} r.item as s and then attached s.is_integer then
|
||||
u.add_role_by_id (s.integer_value)
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
service.storage.save_user (u)
|
||||
if a_is_editing_current_user and u /= user then
|
||||
set_user (u)
|
||||
end
|
||||
set_redirection (user_url (u))
|
||||
end
|
||||
|
||||
edit_form (u: CMS_USER; a_url: READABLE_STRING_8; a_name: STRING): CMS_FORM
|
||||
local
|
||||
f: CMS_FORM
|
||||
@@ -118,6 +142,8 @@ feature -- Execution
|
||||
tp: CMS_FORM_PASSWORD_INPUT
|
||||
ta: CMS_FORM_TEXTAREA
|
||||
ts: CMS_FORM_SUBMIT_INPUT
|
||||
tset: CMS_FORM_FIELD_SET
|
||||
cb: CMS_FORM_CHECKBOX_INPUT
|
||||
do
|
||||
create f.make (a_url, a_name)
|
||||
|
||||
@@ -156,6 +182,27 @@ feature -- Execution
|
||||
ta.set_is_required (False)
|
||||
f.extend (ta)
|
||||
|
||||
if has_permission ("administer users") then
|
||||
create tset.make
|
||||
tset.set_legend ("User roles")
|
||||
tset.set_collapsible (True)
|
||||
f.extend (tset)
|
||||
across
|
||||
service.storage.user_roles as r
|
||||
loop
|
||||
if
|
||||
r.item ~ service.storage.anonymous_user_role or
|
||||
r.item ~ service.storage.authenticated_user_role
|
||||
then
|
||||
-- Skip
|
||||
else
|
||||
create cb.make_with_text ("roles[]", r.item.id.out)
|
||||
cb.set_text (r.item.name)
|
||||
cb.set_checked (u /= Void and then u.has_role (r.item))
|
||||
tset.extend (cb)
|
||||
end
|
||||
end
|
||||
end
|
||||
f.extend_text ("<br/>")
|
||||
|
||||
create ts.make ("op")
|
||||
|
||||
@@ -9,6 +9,9 @@ class
|
||||
|
||||
inherit
|
||||
CMS_MODULE
|
||||
redefine
|
||||
permissions
|
||||
end
|
||||
|
||||
CMS_HOOK_MENU_ALTER
|
||||
|
||||
@@ -55,6 +58,13 @@ feature {CMS_SERVICE} -- Registration
|
||||
|
||||
feature -- Hooks
|
||||
|
||||
permissions (a_service: CMS_SERVICE): LIST [CMS_PERMISSION]
|
||||
do
|
||||
Result := Precursor (a_service)
|
||||
Result.extend ("register account")
|
||||
Result.extend ("change username")
|
||||
end
|
||||
|
||||
block_list: ITERABLE [like {CMS_BLOCK}.name]
|
||||
do
|
||||
Result := <<"user-info">>
|
||||
@@ -106,12 +116,6 @@ feature -- Hooks
|
||||
end
|
||||
end
|
||||
|
||||
links: HASH_TABLE [CMS_MODULE_LINK, STRING]
|
||||
-- Link indexed by path
|
||||
do
|
||||
create Result.make (0)
|
||||
end
|
||||
|
||||
feature -- Handlers
|
||||
|
||||
handle_logout (cms: CMS_SERVICE; req: WSF_REQUEST; res: WSF_RESPONSE)
|
||||
|
||||
@@ -22,8 +22,6 @@ feature -- Execution
|
||||
f: CMS_FORM
|
||||
u: detachable CMS_USER
|
||||
fd: detachable CMS_FORM_DATA
|
||||
e: detachable CMS_EMAIL
|
||||
l_uuid: UUID
|
||||
do
|
||||
set_title ("Request new password")
|
||||
create b.make_empty
|
||||
@@ -45,54 +43,70 @@ feature -- Execution
|
||||
else
|
||||
f := new_password_form (url (request.path_info, Void), "new-password")
|
||||
if request.is_post_request_method then
|
||||
create fd.make (request, f)
|
||||
if attached {WSF_STRING} fd.item ("name") as s_name then
|
||||
u := service.storage.user_by_name (s_name.value)
|
||||
if u = Void then
|
||||
u := service.storage.user_by_email (s_name.value)
|
||||
if u = Void then
|
||||
fd.report_invalid_field ("name", "Sorry, " + html_encoded (s_name.value)+ " is not recognized as a user name or an e-mail address.")
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
initialize_primary_tabs (u)
|
||||
if fd /= Void and then fd.is_valid and then u /= Void then
|
||||
across
|
||||
fd as c
|
||||
loop
|
||||
b.append ("<li>" + html_encoded (c.key) + "=")
|
||||
if attached c.item as v then
|
||||
b.append (html_encoded (v.string_representation))
|
||||
end
|
||||
b.append ("</li>")
|
||||
end
|
||||
if attached u.email as l_mail_address then
|
||||
l_uuid := (create {UUID_GENERATOR}).generate_uuid
|
||||
e := new_password_email (u, l_mail_address, l_uuid.out)
|
||||
u.set_data_item ("new_password_extra", l_uuid.out)
|
||||
service.storage.save_user (u)
|
||||
service.mailer.safe_process_email (e)
|
||||
add_success_message ("Further instructions have been sent to your e-mail address.")
|
||||
set_redirection (url ("/user", Void))
|
||||
else
|
||||
add_success_message ("No email is associated with the requested account. Please contact the webmaster for help.")
|
||||
set_redirection (url ("/user", Void))
|
||||
end
|
||||
set_main_content (b)
|
||||
f.validation_actions.extend (agent password_form_validate)
|
||||
f.submit_actions.extend (agent password_form_submit (?, b))
|
||||
f.process (Current)
|
||||
fd := f.last_data
|
||||
else
|
||||
if fd /= Void then
|
||||
if not fd.is_valid then
|
||||
report_form_errors (fd)
|
||||
end
|
||||
fd.apply_to_associated_form
|
||||
end
|
||||
f.append_to_html (theme, b)
|
||||
initialize_primary_tabs (Void)
|
||||
end
|
||||
|
||||
f.append_to_html (theme, b)
|
||||
end
|
||||
set_main_content (b)
|
||||
end
|
||||
|
||||
password_form_validate (fd: CMS_FORM_DATA)
|
||||
local
|
||||
u: detachable CMS_USER
|
||||
do
|
||||
if attached {WSF_STRING} fd.item ("name") as s_name then
|
||||
u := service.storage.user_by_name (s_name.value)
|
||||
if u = Void then
|
||||
u := service.storage.user_by_email (s_name.value)
|
||||
if u = Void then
|
||||
fd.report_invalid_field ("name", "Sorry, " + html_encoded (s_name.value)+ " is not recognized as a user name or an e-mail address.")
|
||||
end
|
||||
end
|
||||
end
|
||||
fd.add_cached_value ("user", u)
|
||||
initialize_primary_tabs (u)
|
||||
end
|
||||
|
||||
password_form_submit (fd: CMS_FORM_DATA; b: STRING)
|
||||
local
|
||||
e: detachable CMS_EMAIL
|
||||
l_uuid: UUID
|
||||
do
|
||||
debug
|
||||
across
|
||||
fd as c
|
||||
loop
|
||||
b.append ("<li>" + html_encoded (c.key) + "=")
|
||||
if attached c.item as v then
|
||||
b.append (html_encoded (v.string_representation))
|
||||
end
|
||||
b.append ("</li>")
|
||||
end
|
||||
end
|
||||
if attached {CMS_USER} fd.cached_value ("user") as u then
|
||||
if attached u.email as l_mail_address then
|
||||
l_uuid := (create {UUID_GENERATOR}).generate_uuid
|
||||
e := new_password_email (u, l_mail_address, l_uuid.out)
|
||||
u.set_data_item ("new_password_extra", l_uuid.out)
|
||||
service.storage.save_user (u)
|
||||
service.mailer.safe_process_email (e)
|
||||
add_success_message ("Further instructions have been sent to your e-mail address.")
|
||||
set_redirection (url ("/user", Void))
|
||||
else
|
||||
add_error_message ("No email is associated with the requested account. Please contact the webmaster for help.")
|
||||
set_redirection (url ("/user", Void))
|
||||
end
|
||||
else
|
||||
add_error_message ("User not defined!")
|
||||
end
|
||||
end
|
||||
|
||||
new_password_form (a_url: READABLE_STRING_8; a_name: STRING): CMS_FORM
|
||||
require
|
||||
attached user as l_auth_user implies l_auth_user.has_email
|
||||
|
||||
@@ -21,11 +21,6 @@ feature -- Execution
|
||||
b: STRING_8
|
||||
f: CMS_FORM
|
||||
fd: detachable CMS_FORM_DATA
|
||||
u: detachable CMS_USER
|
||||
up: detachable CMS_USER_PROFILE
|
||||
e: detachable CMS_EMAIL
|
||||
l_pass: detachable READABLE_STRING_32
|
||||
l_uuid: UUID
|
||||
do
|
||||
set_title ("Create new account")
|
||||
create b.make_empty
|
||||
@@ -34,81 +29,98 @@ feature -- Execution
|
||||
b.append ("You are already " + link ("signed in", "/user", Void) + ", please " + link ("signout", "/user/logout", Void) + " before trying to " + link ("register a new account", "/account/register", Void) + ".")
|
||||
set_redirection (url ("/user", Void))
|
||||
else
|
||||
f := registration_form (url (request.path_info, Void), "reg")
|
||||
f := registration_form (url (request.path_info, Void), "user-register")
|
||||
|
||||
if request.is_post_request_method then
|
||||
create fd.make (request, f)
|
||||
if attached {WSF_STRING} fd.item ("username") as s_username then
|
||||
u := service.storage.user_by_name (s_username.value)
|
||||
if u /= Void then
|
||||
fd.report_invalid_field ("username", "User already exists!")
|
||||
end
|
||||
end
|
||||
if attached {WSF_STRING} fd.item ("email") as s_email then
|
||||
u := service.storage.user_by_email (s_email.value)
|
||||
if u /= Void then
|
||||
fd.report_invalid_field ("email", "Email is already used!")
|
||||
end
|
||||
end
|
||||
u := Void
|
||||
f.validation_actions.extend (agent registration_form_validate)
|
||||
f.submit_actions.extend (agent registration_form_submitted (?, b))
|
||||
|
||||
f.process (Current)
|
||||
fd := f.last_data
|
||||
else
|
||||
f.prepare (Current)
|
||||
end
|
||||
if fd /= Void and then fd.is_valid then
|
||||
across
|
||||
fd as c
|
||||
loop
|
||||
b.append ("<li>" + html_encoded (c.key) + "=")
|
||||
if attached c.item as v then
|
||||
b.append (html_encoded (v.string_representation))
|
||||
end
|
||||
b.append ("</li>")
|
||||
end
|
||||
if attached {WSF_STRING} fd.item ("username") as s_username then
|
||||
u := service.storage.user_by_name (s_username.value)
|
||||
|
||||
create u.make_new (s_username.value)
|
||||
if attached {WSF_STRING} fd.item ("password") as s_password then
|
||||
u.set_password (s_password.value)
|
||||
l_pass := u.password
|
||||
end
|
||||
if attached {WSF_STRING} fd.item ("email") as s_email then
|
||||
u.set_email (s_email.value)
|
||||
end
|
||||
|
||||
if attached {WSF_STRING} fd.item ("note") as s_note then
|
||||
create up.make
|
||||
up.force (s_note.value, "note")
|
||||
u.set_profile (up)
|
||||
end
|
||||
|
||||
l_uuid := (create {UUID_GENERATOR}).generate_uuid
|
||||
u.set_data_item ("new_password_extra", l_uuid.out)
|
||||
|
||||
service.storage.save_user (u)
|
||||
if attached u.email as l_mail_address then
|
||||
e := new_registration_email (l_mail_address, u, l_pass, l_uuid.out)
|
||||
service.mailer.safe_process_email (e)
|
||||
end
|
||||
e := new_user_account_email (service.site_email, u)
|
||||
service.mailer.safe_process_email (e)
|
||||
|
||||
login (u, request)
|
||||
set_redirection (url ("/user", Void))
|
||||
end
|
||||
set_main_content (b)
|
||||
else
|
||||
initialize_primary_tabs (user)
|
||||
if fd /= Void then
|
||||
if not fd.is_valid then
|
||||
report_form_errors (fd)
|
||||
end
|
||||
fd.apply_to_associated_form
|
||||
end
|
||||
f.append_to_html (theme, b)
|
||||
end
|
||||
end
|
||||
set_main_content (b)
|
||||
end
|
||||
|
||||
registration_form_validate (fd: CMS_FORM_DATA)
|
||||
local
|
||||
u: detachable CMS_USER
|
||||
do
|
||||
if attached {WSF_STRING} fd.item ("username") as s_username then
|
||||
u := service.storage.user_by_name (s_username.value)
|
||||
if u /= Void then
|
||||
fd.report_invalid_field ("username", "User already exists!")
|
||||
end
|
||||
end
|
||||
if attached {WSF_STRING} fd.item ("email") as s_email then
|
||||
u := service.storage.user_by_email (s_email.value)
|
||||
if u /= Void then
|
||||
fd.report_invalid_field ("email", "Email is already used!")
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
registration_form_submitted (fd: CMS_FORM_DATA; buf: STRING)
|
||||
local
|
||||
b: STRING
|
||||
u: detachable CMS_USER
|
||||
up: detachable CMS_USER_PROFILE
|
||||
e: detachable CMS_EMAIL
|
||||
l_pass: detachable READABLE_STRING_32
|
||||
l_uuid: UUID
|
||||
do
|
||||
b := buf
|
||||
across
|
||||
fd as c
|
||||
loop
|
||||
b.append ("<li>" + html_encoded (c.key) + "=")
|
||||
if attached c.item as v then
|
||||
b.append (html_encoded (v.string_representation))
|
||||
end
|
||||
b.append ("</li>")
|
||||
end
|
||||
if attached {WSF_STRING} fd.item ("username") as s_username then
|
||||
u := service.storage.user_by_name (s_username.value)
|
||||
|
||||
create u.make_new (s_username.value)
|
||||
if attached {WSF_STRING} fd.item ("password") as s_password then
|
||||
u.set_password (s_password.value)
|
||||
l_pass := u.password
|
||||
end
|
||||
if attached {WSF_STRING} fd.item ("email") as s_email then
|
||||
u.set_email (s_email.value)
|
||||
end
|
||||
|
||||
if attached {WSF_STRING} fd.item ("note") as s_note then
|
||||
create up.make
|
||||
up.force (s_note.value, "note")
|
||||
u.set_profile (up)
|
||||
end
|
||||
|
||||
l_uuid := (create {UUID_GENERATOR}).generate_uuid
|
||||
u.set_data_item ("new_password_extra", l_uuid.out)
|
||||
|
||||
service.storage.save_user (u)
|
||||
if attached u.email as l_mail_address then
|
||||
e := new_registration_email (l_mail_address, u, l_pass, l_uuid.out)
|
||||
service.mailer.safe_process_email (e)
|
||||
end
|
||||
e := new_user_account_email (service.site_email, u)
|
||||
service.mailer.safe_process_email (e)
|
||||
|
||||
login (u, request)
|
||||
set_redirection (url ("/user", Void))
|
||||
end
|
||||
end
|
||||
|
||||
registration_form (a_url: READABLE_STRING_8; a_name: STRING): CMS_FORM
|
||||
local
|
||||
f: CMS_FORM
|
||||
|
||||
Reference in New Issue
Block a user