Skip to content

Commit ac9d29b

Browse files
committed
Added basic webapi system to ROC CMS system.
Added sql_delete routine to replace sql_modify with "DELETE FROM .." sql statement. Fixed filter setup when a module has more than one filter. Fixed filter setup for site,admin and webapi modes. Added CMS_AUTH_FILTER, and check if user is already authenticated, then skip following auth filters. Added specific webapi handler classes for root, user, access token, ... Added user profile system to the core module. Moved /user/{uid} from auth module to core module. Added possibility to add html before and after a cms form. (useful to add a form before or after, as nested form are forbidden). Now theme can be installed using roc install command.
1 parent 34f0aa5 commit ac9d29b

File tree

88 files changed

+3552
-553
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

88 files changed

+3552
-553
lines changed

cms-safe.ecf

+8-3
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,18 @@
11
<?xml version="1.0" encoding="ISO-8859-1"?>
2-
<system xmlns="http://www.eiffel.com/developers/xml/configuration-1-15-0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.eiffel.com/developers/xml/configuration-1-15-0 http://www.eiffel.com/developers/xml/configuration-1-15-0.xsd" name="cms" uuid="8CC0D052-57D1-4CAA-AFF1-448FA290734B" library_target="cms">
2+
<system xmlns="http://www.eiffel.com/developers/xml/configuration-1-17-0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.eiffel.com/developers/xml/configuration-1-17-0 http://www.eiffel.com/developers/xml/configuration-1-17-0.xsd" name="cms" uuid="8CC0D052-57D1-4CAA-AFF1-448FA290734B" library_target="cms">
33
<target name="cms">
44
<root all_classes="true"/>
55
<file_rule>
66
<exclude>/.svn$</exclude>
77
<exclude>/CVS$</exclude>
88
<exclude>/EIFGENs$</exclude>
99
</file_rule>
10-
<option warning="true" void_safety="all">
10+
<option warning="true">
1111
</option>
12-
<setting name="concurrency" value="scoop"/>
12+
<capability>
13+
<concurrency support="scoop" use="scoop"/>
14+
<void_safety support="all" use="all"/>
15+
</capability>
1316
<mapping old_name="CMS_LAYOUT" new_name="CMS_ENVIRONMENT"/>
1417
<library name="base" location="$ISE_LIBRARY\library\base\base-safe.ecf"/>
1518
<library name="base_extension" location="$ISE_LIBRARY\library\base_extension\base_extension-safe.ecf"/>
@@ -20,9 +23,11 @@
2023
<library name="encoder" location="$ISE_LIBRARY\contrib\library\web\framework\ewf\text\encoder\encoder-safe.ecf" readonly="false"/>
2124
<library name="error" location="$ISE_LIBRARY\contrib\library\utility\general\error\error-safe.ecf"/>
2225
<library name="http" location="$ISE_LIBRARY\contrib\library\network\protocol\http\http-safe.ecf"/>
26+
<library name="http_authorization" location="$ISE_LIBRARY\contrib\library\web\authentication\http_authorization\http_authorization-safe.ecf"/>
2327
<library name="i18n" location="$ISE_LIBRARY\library\i18n\i18n-safe.ecf"/>
2428
<library name="json" location="$ISE_LIBRARY\contrib\library\text\parser\json\library\json-safe.ecf" readonly="false"/>
2529
<library name="kmp_matcher" location="$ISE_LIBRARY\library\text\regexp\kmp_matcher\kmp_matcher-safe.ecf"/>
30+
<library name="microdata" location="$ISE_LIBRARY\contrib\library\text\parser\microdata\microdata.ecf"/>
2631
<library name="net" location="$ISE_LIBRARY\library\net\net-safe.ecf"/>
2732
<library name="notification_mailer" location="$ISE_LIBRARY\contrib\library\runtime\process\notification_email\notification_email-safe.ecf"/>
2833
<library name="smarty" location="$ISE_LIBRARY\contrib\library\text\template\smarty\smarty-safe.ecf" readonly="false"/>

cms.ecf

+1
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
<library name="encoder" location="$ISE_LIBRARY\contrib\library\web\framework\ewf\text\encoder\encoder.ecf" readonly="false"/>
2121
<library name="error" location="$ISE_LIBRARY\contrib\library\utility\general\error\error.ecf"/>
2222
<library name="http" location="$ISE_LIBRARY\contrib\library\network\protocol\http\http.ecf"/>
23+
<library name="http_authorization" location="$ISE_LIBRARY\contrib\library\web\authentication\http_authorization\http_authorization.ecf"/>
2324
<library name="i18n" location="$ISE_LIBRARY\library\i18n\i18n.ecf"/>
2425
<library name="json" location="$ISE_LIBRARY\contrib\library\text\parser\json\library\json.ecf" readonly="false"/>
2526
<library name="kmp_matcher" location="$ISE_LIBRARY\library\text\regexp\kmp_matcher\kmp_matcher.ecf"/>

examples/demo/roc.cfg

+4
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,11 @@
33
"project": "demo-safe.ecf",
44
"location": ".",
55
"site_directory": "site",
6+
"themes": {
7+
"admin": { "location": "../../themes/admin", "mode": "link" }
8+
},
69
"modules": {
10+
"demo": { "location": "modules/demo" },
711
"core": { "location": "../../modules/core" },
812
"admin": { "location": "../../modules/admin" },
913
"auth": { "location": "../../modules/auth" },

examples/demo/site/config/cms.ini

+4-2
Original file line numberDiff line numberDiff line change
@@ -57,13 +57,15 @@ output=site\db\mails
5757
#openid.token=
5858
#oauth.token=
5959

60+
[webapi]
61+
mode=on
6062

6163
[administration]
6264
base_path=/roc-admin
63-
#theme=admin
65+
theme=admin
6466
# CMS Installation, are accessible by "all", "none" or uppon "permission". (default is none)
6567
installation_access=all
6668

6769
[dev]
6870
# masquerade: all, none, permission. Default is none.
69-
masquerade=none
71+
masquerade=all

library/model/src/user/cms_user.e

-36
Original file line numberDiff line numberDiff line change
@@ -98,19 +98,6 @@ feature -- Roles
9898
roles: detachable LIST [CMS_USER_ROLE]
9999
-- If set, list of roles for current user.
100100

101-
feature -- Access: data
102-
103-
item (k: READABLE_STRING_GENERAL): detachable ANY assign put
104-
-- Additional item data associated with key `k'.
105-
do
106-
if attached items as tb then
107-
Result := tb.item (k)
108-
end
109-
end
110-
111-
items: detachable STRING_TABLE [detachable ANY]
112-
-- Additional data.
113-
114101
feature -- Status report
115102

116103
has_id: BOOLEAN
@@ -223,29 +210,6 @@ feature -- Element change: roles
223210
roles := lst
224211
end
225212

226-
feature -- Change element: data
227-
228-
put (d: like item; k: READABLE_STRING_GENERAL)
229-
-- Associate data item `d' with key `k'.
230-
local
231-
tb: like items
232-
do
233-
tb := items
234-
if tb = Void then
235-
create tb.make (1)
236-
items := tb
237-
end
238-
tb.force (d, k)
239-
end
240-
241-
remove (k: READABLE_STRING_GENERAL)
242-
-- Remove data item associated with key `k'.
243-
do
244-
if attached items as tb then
245-
tb.remove (k)
246-
end
247-
end
248-
249213
feature -- Status change
250214

251215
mark_not_active
+72
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
note
2+
description: "[
3+
User profile used to extend information associated with a {CMS_USER}.
4+
]"
5+
date: "$Date$"
6+
revision: "$Revision$"
7+
8+
class
9+
CMS_USER_PROFILE
10+
11+
inherit
12+
TABLE_ITERABLE [READABLE_STRING_32, READABLE_STRING_GENERAL]
13+
14+
create
15+
make
16+
17+
feature {NONE} -- Initialization
18+
19+
make
20+
-- Create Current profile.
21+
do
22+
create items.make (0)
23+
end
24+
25+
feature -- Access
26+
27+
item alias "[]" (k: READABLE_STRING_GENERAL): detachable READABLE_STRING_32
28+
-- Profile item associated with key `k`.
29+
do
30+
Result := items.item (k)
31+
end
32+
33+
has_key (k: READABLE_STRING_GENERAL): BOOLEAN
34+
-- Has a profile item associated with key `k`?
35+
do
36+
Result := items.has (k)
37+
end
38+
39+
count: INTEGER
40+
do
41+
Result := items.count
42+
end
43+
44+
is_empty: BOOLEAN
45+
do
46+
Result := items.is_empty
47+
end
48+
49+
feature -- Change
50+
51+
force (v: READABLE_STRING_GENERAL; k: READABLE_STRING_GENERAL)
52+
-- Associated value `v` with key `k`.
53+
do
54+
items.force (v.to_string_32, k)
55+
end
56+
57+
feature -- Access
58+
59+
new_cursor: TABLE_ITERATION_CURSOR [READABLE_STRING_32, READABLE_STRING_GENERAL]
60+
-- Fresh cursor associated with current structure
61+
do
62+
Result := items.new_cursor
63+
end
64+
65+
feature {NONE} -- Implementation
66+
67+
items: STRING_TABLE [READABLE_STRING_32]
68+
69+
;note
70+
copyright: "2011-2014, Javier Velilla, Jocelyn Fiat, Eiffel Software and others"
71+
license: "Eiffel Forum License v2 (see http://www.eiffel.com/licensing/forum.txt)"
72+
end

library/persistence/implementation/store/cms_storage_store_sql.e

+6
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,12 @@ feature -- Query
110110
sql_post_execution
111111
end
112112

113+
sql_delete (a_sql_statement: STRING; a_params: detachable STRING_TABLE [detachable ANY])
114+
-- <Precursor>
115+
do
116+
sql_modify (a_sql_statement, a_params)
117+
end
118+
113119
sql_rows_count: INTEGER
114120
-- Number of rows for last sql execution.
115121
do

library/persistence/sqlite3/src/cms_storage_sqlite3.e

+6
Original file line numberDiff line numberDiff line change
@@ -230,6 +230,12 @@ feature -- Operation
230230
end
231231
end
232232

233+
sql_delete (a_sql_statement: STRING; a_params: detachable STRING_TABLE [detachable ANY])
234+
-- <Precursor>
235+
do
236+
sql_modify (a_sql_statement, a_params)
237+
end
238+
233239
sqlite_arguments (a_params: STRING_TABLE [detachable ANY]): ARRAYED_LIST [SQLITE_BIND_ARG [ANY]]
234240
local
235241
k: READABLE_STRING_GENERAL
+29
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
note
2+
description: "Summary description for {CMS_AUTH_FILTER_WITH_LOGOUT}."
3+
author: ""
4+
date: "$Date$"
5+
revision: "$Revision$"
6+
7+
deferred class
8+
CMS_AUTH_STRATEGY_FILTER
9+
10+
inherit
11+
CMS_AUTH_FILTER
12+
redefine
13+
set_current_user
14+
end
15+
16+
feature -- Basic operations
17+
18+
auth_strategy: STRING
19+
deferred
20+
end
21+
22+
set_current_user (u: CMS_USER)
23+
do
24+
Precursor (u)
25+
-- Record auth strategy:
26+
api.set_execution_variable ({CMS_AUTHENTICATION_MODULE}.auth_strategy_execution_variable_name, auth_strategy)
27+
end
28+
29+
end

modules/auth/cms_authentication_module.e

+53-3
Original file line numberDiff line numberDiff line change
@@ -124,8 +124,6 @@ feature -- Router
124124
a_router.handle ("/account/new-password", create {WSF_URI_AGENT_HANDLER}.make (agent handle_new_password(a_api, ?, ?)), a_router.methods_get_post)
125125
a_router.handle ("/account/reset-password", create {WSF_URI_AGENT_HANDLER}.make (agent handle_reset_password(a_api, ?, ?)), a_router.methods_get_post)
126126
a_router.handle ("/account/change/{field}", create {WSF_URI_TEMPLATE_AGENT_HANDLER}.make (agent handle_change_field (a_api, ?, ?)), a_router.methods_get_post)
127-
128-
a_router.handle ("/user/{uid}", create {CMS_USER_HANDLER}.make (a_api), a_router.methods_get)
129127
end
130128

131129
feature -- Hooks configuration
@@ -206,6 +204,23 @@ feature -- Hooks configuration
206204
end
207205
end
208206

207+
feature -- Handler / Constants
208+
209+
auth_strategy_execution_variable_name: STRING = "auth_strategy"
210+
-- Exevc
211+
212+
auth_strategy (req: WSF_REQUEST): detachable READABLE_STRING_8
213+
-- Strategy used by current authentication.
214+
-- note: if user is authenticated..
215+
do
216+
if
217+
attached {READABLE_STRING_GENERAL} req.execution_variable (auth_strategy_execution_variable_name) as s and then
218+
s.is_valid_as_string_8
219+
then
220+
Result := s.to_string_8
221+
end
222+
end
223+
209224
feature -- Handler
210225

211226
handle_account (api: CMS_API; req: WSF_REQUEST; res: WSF_RESPONSE)
@@ -214,17 +229,44 @@ feature -- Handler
214229
l_user: detachable CMS_USER
215230
b: STRING
216231
lnk: CMS_LOCAL_LINK
232+
f: CMS_FORM
233+
tf: WSF_FORM_TEXT_INPUT
217234
do
218235
create {GENERIC_VIEW_CMS_RESPONSE} r.make (req, res, api)
219236
create b.make_empty
220237
l_user := r.user
238+
create f.make (r.location, "roccms-user-view")
221239
if attached smarty_template_block (Current, "account_info", api) as l_tpl_block then
222240
l_tpl_block.set_weight (-10)
223241
r.add_block (l_tpl_block, "content")
224242
else
225243
debug ("cms")
226244
r.add_warning_message ("Error with block [resources_page]")
227245
end
246+
if l_user /= Void then
247+
create tf.make_with_text ("username", l_user.name)
248+
tf.set_label ("Username")
249+
f.extend (tf)
250+
if attached l_user.email as l_email then
251+
create tf.make_with_text ("email", l_email.to_string_32)
252+
tf.set_label ("Email")
253+
f.extend (tf)
254+
end
255+
if attached l_user.profile_name as l_prof_name then
256+
create tf.make_with_text ("profile_name", l_prof_name)
257+
tf.set_label ("Profile name")
258+
f.extend (tf)
259+
end
260+
create tf.make_with_text ("creation", api.formatted_date_time_yyyy_mm_dd (l_user.creation_date))
261+
tf.set_label ("Creation date")
262+
f.extend (tf)
263+
264+
if attached l_user.last_login_date as dt then
265+
create tf.make_with_text ("last_login", api.formatted_date_time_ago (dt))
266+
tf.set_label ("Last login")
267+
f.extend (tf)
268+
end
269+
end
228270
end
229271

230272
if r.is_authenticated then
@@ -237,6 +279,9 @@ feature -- Handler
237279
r.add_to_primary_tabs (lnk)
238280
end
239281

282+
api.hooks.invoke_form_alter (f, Void, r)
283+
f.append_to_html (r.wsf_theme, b)
284+
240285
r.set_main_content (b)
241286

242287
if l_user = Void then
@@ -251,17 +296,20 @@ feature -- Handler
251296
l_user: detachable CMS_USER
252297
b: STRING
253298
lnk: CMS_LOCAL_LINK
299+
l_form: CMS_FORM
254300
do
255301
create {GENERIC_VIEW_CMS_RESPONSE} r.make (req, res, api)
256302
create b.make_empty
257303
l_user := r.user
304+
create l_form.make (r.location, "roccms-user-edit")
258305
if attached smarty_template_block (Current, "account_edit", api) as l_tpl_block then
259306
l_tpl_block.set_weight (-10)
260307
r.add_block (l_tpl_block, "content")
261308
else
262309
debug ("cms")
263310
r.add_warning_message ("Error with block [resources_page]")
264311
end
312+
-- Build CMS form...
265313
end
266314
create lnk.make ("View", "account/")
267315
lnk.set_weight (1)
@@ -287,6 +335,8 @@ feature -- Handler
287335
f.append_to_html (r.wsf_theme, b)
288336
end
289337

338+
l_form.append_to_html (r.wsf_theme, b)
339+
290340
r.set_main_content (b)
291341

292342
if l_user = Void then
@@ -336,7 +386,7 @@ feature -- Handler
336386
loc: STRING
337387
do
338388
create {GENERIC_VIEW_CMS_RESPONSE} r.make (req, res, api)
339-
if attached {READABLE_STRING_8} api.execution_variable ("auth_strategy") as l_auth_strategy then
389+
if attached auth_strategy (req) as l_auth_strategy then
340390
loc := l_auth_strategy
341391
else
342392
loc := ""

0 commit comments

Comments
 (0)