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:
@@ -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+XNYvQAAABl0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qx+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+iT1VEUYRgaEGqsa2FGtu8xNtD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PuMJnEyCaB2HZyBSSZLnVOIf5WGRPUXpwkfoqA1cQzcDKuNYEkil6BZvPSjw5x3BsyJGaeHLOyWUK0ZpJ0eUGseuB34B7SrVUpiB2movAQ2Sl5nJnvzeAt4Fpz9R5zzSicUV+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