From 0164c6ec6de68b613228561469a1417604885443 Mon Sep 17 00:00:00 2001 From: jvelilla Date: Mon, 13 Jul 2015 10:25:18 -0300 Subject: [PATCH] Updated Account Info based on review. Updated Account info with change password form. --- .../auth/templates/block_account_info.tpl | 2 + .../auth/templates/block_change_password.tpl | 21 ++++++++ .../auth/templates/block_post_change.tpl | 3 ++ modules/auth/cms_authentication_module.e | 48 ++++++++++++++++++- .../site/templates/block_account_info.tpl | 2 + .../site/templates/block_change_password.tpl | 21 ++++++++ .../auth/site/templates/block_post_change.tpl | 3 ++ 7 files changed, 99 insertions(+), 1 deletion(-) create mode 100644 examples/demo/site/modules/auth/templates/block_change_password.tpl create mode 100644 examples/demo/site/modules/auth/templates/block_post_change.tpl create mode 100644 modules/auth/site/templates/block_change_password.tpl create mode 100644 modules/auth/site/templates/block_post_change.tpl diff --git a/examples/demo/site/modules/auth/templates/block_account_info.tpl b/examples/demo/site/modules/auth/templates/block_account_info.tpl index e61a012..debcd47 100644 --- a/examples/demo/site/modules/auth/templates/block_account_info.tpl +++ b/examples/demo/site/modules/auth/templates/block_account_info.tpl @@ -23,6 +23,8 @@
+ {include file="block_change_password.tpl" /} +

Roles

{foreach item="ic" from="$roles"} diff --git a/examples/demo/site/modules/auth/templates/block_change_password.tpl b/examples/demo/site/modules/auth/templates/block_change_password.tpl new file mode 100644 index 0000000..dcbe4de --- /dev/null +++ b/examples/demo/site/modules/auth/templates/block_change_password.tpl @@ -0,0 +1,21 @@ +
+
+
+ Change Password Form +
+ + +
+
+ + +
+ + + {if isset="$error_password"} + {$error_password/}
+ {/if} + +
+
+
diff --git a/examples/demo/site/modules/auth/templates/block_post_change.tpl b/examples/demo/site/modules/auth/templates/block_post_change.tpl new file mode 100644 index 0000000..bd80bf3 --- /dev/null +++ b/examples/demo/site/modules/auth/templates/block_post_change.tpl @@ -0,0 +1,3 @@ +
+

You new password has been saved!, Login again

+
diff --git a/modules/auth/cms_authentication_module.e b/modules/auth/cms_authentication_module.e index 348c0f7..feec514 100644 --- a/modules/auth/cms_authentication_module.e +++ b/modules/auth/cms_authentication_module.e @@ -85,7 +85,8 @@ feature -- Router a_router.handle ("/account/reactivate", create {WSF_URI_AGENT_HANDLER}.make (agent handle_reactivation (a_api, ?, ?)), a_router.methods_get_post) a_router.handle ("/account/new-password", create {WSF_URI_AGENT_HANDLER}.make (agent handle_new_password (a_api, ?, ?)), a_router.methods_get_post) a_router.handle ("/account/reset-password", create {WSF_URI_AGENT_HANDLER}.make (agent handle_reset_password (a_api, ?, ?)), a_router.methods_get_post) - + a_router.handle ("/account/change-password", create {WSF_URI_AGENT_HANDLER}.make (agent handle_change_password (a_api, ?, ?)), a_router.methods_get_post) + a_router.handle ("/account/post-change-password", create {WSF_URI_AGENT_HANDLER}.make (agent handle_post_change_password (a_api, ?, ?)), a_router.methods_get) end feature -- Hooks configuration @@ -388,6 +389,51 @@ feature -- Handler r.execute end + handle_change_password (api: CMS_API; req: WSF_REQUEST; res: WSF_RESPONSE) + local + r: CMS_RESPONSE + l_user_api: CMS_USER_API + do + create {GENERIC_VIEW_CMS_RESPONSE} r.make (req, res, api) + l_user_api := api.user_api + + if req.is_post_request_method then + if attached current_user (req) as l_user then + r.set_value (api.user_api.user_roles (l_user), "roles") + if + attached {WSF_STRING} req.form_parameter ("password") as l_password and then + attached {WSF_STRING} req.form_parameter ("confirm_password") as l_confirm_password and then + l_password.value.same_string (l_confirm_password.value) + then + -- Does the passwords match? + l_user.set_password (l_password.value) + l_user_api.update_user (l_user) + r.set_redirection (req.absolute_script_url ("/account/post-change-password")) + else + if attached template_block ("account_info", r) as l_tpl_block then + r.set_value (l_user, "user") + r.values.force ("Passwords Don't Match", "error_password") + r.set_status_code ({HTTP_CONSTANTS}.bad_request) + r.add_block (l_tpl_block, "content") + end + end + end + end + r.execute + end + + handle_post_change_password (api: CMS_API; req: WSF_REQUEST; res: WSF_RESPONSE) + local + r: CMS_RESPONSE + l_user_api: CMS_USER_API + do + create {GENERIC_VIEW_CMS_RESPONSE} r.make (req, res, api) + if attached template_block ("post_change", r) as l_tpl_block then + r.add_block (l_tpl_block, "content") + end + r.execute + end + block_list: ITERABLE [like {CMS_BLOCK}.name] local l_string: STRING diff --git a/modules/auth/site/templates/block_account_info.tpl b/modules/auth/site/templates/block_account_info.tpl index e61a012..debcd47 100644 --- a/modules/auth/site/templates/block_account_info.tpl +++ b/modules/auth/site/templates/block_account_info.tpl @@ -23,6 +23,8 @@

+ {include file="block_change_password.tpl" /} +

Roles

{foreach item="ic" from="$roles"} diff --git a/modules/auth/site/templates/block_change_password.tpl b/modules/auth/site/templates/block_change_password.tpl new file mode 100644 index 0000000..dcbe4de --- /dev/null +++ b/modules/auth/site/templates/block_change_password.tpl @@ -0,0 +1,21 @@ +
+
+
+ Change Password Form +
+ + +
+
+ + +
+ + + {if isset="$error_password"} + {$error_password/}
+ {/if} + +
+
+
diff --git a/modules/auth/site/templates/block_post_change.tpl b/modules/auth/site/templates/block_post_change.tpl new file mode 100644 index 0000000..bd80bf3 --- /dev/null +++ b/modules/auth/site/templates/block_post_change.tpl @@ -0,0 +1,3 @@ +
+

You new password has been saved!, Login again

+