Your account "+ l_user.name +" has been activated
") - else - -- the token does not exist, or it was already used. - r.set_status_code ({HTTP_CONSTANTS}.bad_request) - r.set_main_content ("The token " + l_token.value +" is not valid " + r.link ("Reactivate Account", "account/reactivate", Void) + "
") - end - r.execute - else - create l_ir.make (req, res, api) - l_ir.execute - end - end - - - handle_reactivation (api: CMS_API; req: WSF_REQUEST; res: WSF_RESPONSE) - local - r: CMS_RESPONSE - es: CMS_AUTHENTICATON_EMAIL_SERVICE - l_user_api: CMS_USER_API - l_token: STRING - l_url: STRING - do - create {GENERIC_VIEW_CMS_RESPONSE} r.make (req, res, api) - if req.is_post_request_method then - if - attached {WSF_STRING} req.form_parameter ("email") as l_email - then - l_user_api := api.user_api - if attached {CMS_USER} l_user_api.user_by_email (l_email.value) as l_user then - -- User exist create a new token and send a new email. - if l_user.is_active then - r.set_value ("The asociated user to the given email " + l_email.value + " , is already active", "is_active") - r.set_status_code ({HTTP_CONSTANTS}.bad_request) - else - l_token := new_token - l_user_api.new_activation (l_token, l_user.id) - l_url := req.absolute_script_url ("/account/activate/" + l_token) - - -- Send Email - create es.make (create {CMS_AUTHENTICATION_EMAIL_SERVICE_PARAMETERS}.make (api)) - write_debug_log (generator + ".handle register: send_contact_activation_email") - es.send_contact_activation_email (l_email.value, l_url) - end - else - r.set_value ("The email does not exist or !", "error_email") - r.set_value (l_email.value, "email") - r.set_status_code ({HTTP_CONSTANTS}.bad_request) - end - end - end - - r.execute - end - - handle_new_password (api: CMS_API; req: WSF_REQUEST; res: WSF_RESPONSE) - local - r: CMS_RESPONSE - es: CMS_AUTHENTICATON_EMAIL_SERVICE - l_user_api: CMS_USER_API - l_token: STRING - l_url: STRING - do - create {GENERIC_VIEW_CMS_RESPONSE} r.make (req, res, api) - if req.is_post_request_method then - l_user_api := api.user_api - if attached {WSF_STRING} req.form_parameter ("email") as l_email then - if attached {CMS_USER} l_user_api.user_by_email (l_email.value) as l_user then - -- User exist create a new token and send a new email. - l_token := new_token - l_user_api.new_password (l_token, l_user.id) - l_url := req.absolute_script_url ("/account/reset-password?token=" + l_token) - - -- Send Email - create es.make (create {CMS_AUTHENTICATION_EMAIL_SERVICE_PARAMETERS}.make (api)) - write_debug_log (generator + ".handle register: send_contact_password_email") - es.send_contact_password_email (l_email.value, l_url) - else - r.set_value ("The email does not exist !", "error_email") - r.set_value (l_email.value, "email") - r.set_status_code ({HTTP_CONSTANTS}.bad_request) - end - elseif attached {WSF_STRING} req.form_parameter ("username") as l_username then - if attached {CMS_USER} l_user_api.user_by_name (l_username) as l_user and then - attached l_user.email as l_email - then - -- User exist create a new token and send a new email. - l_token := new_token - l_user_api.new_password (l_token, l_user.id) - l_url := req.absolute_script_url ("/account/reset-password?token=" + l_token) - - -- Send Email - create es.make (create {CMS_AUTHENTICATION_EMAIL_SERVICE_PARAMETERS}.make (api)) - write_debug_log (generator + ".handle register: send_contact_password_email") - es.send_contact_password_email (l_email, l_url) - else - r.set_value ("The username does not exist !", "error_username") - r.set_value (l_username.value, "username") - r.set_status_code ({HTTP_CONSTANTS}.bad_request) - end - end - end - r.execute - end - - - handle_reset_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 attached {WSF_STRING} req.query_parameter ("token") as l_token then - r.set_value (l_token.value, "token") - if l_user_api.user_by_password_token (l_token.value) = Void then - r.set_value ("The token " + l_token.value + " is not valid, " + r.link ("click here" , "account/new-password", Void) + " to generate a new token.", "error_token") - r.set_status_code ({HTTP_CONSTANTS}.bad_request) - end - end - - if req.is_post_request_method then - - if - attached {WSF_STRING} req.form_parameter ("token") as l_token and then - attached {WSF_STRING} req.form_parameter ("password") as l_password and then - attached {WSF_STRING} req.form_parameter ("confirm_password") as l_confirm_password - then - -- Does the passwords match? - if l_password.value.same_string (l_confirm_password.value) then - -- is the token valid? - if attached {CMS_USER} l_user_api.user_by_password_token (l_token.value) as l_user then - l_user.set_password (l_password.value) - l_user_api.update_user (l_user) - l_user_api.remove_password (l_token.value) - end - else - r.set_value ("Passwords Don't Match", "error_password") - r.set_value (l_token.value, "token") - r.set_status_code ({HTTP_CONSTANTS}.bad_request) - end - end - end - 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.set_value ("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 - 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 - do - Result := <<"register", "reactivate", "new_password", "reset_password">> - debug ("roc") - create l_string.make_empty - across - Result as ic - loop - l_string.append (ic.item) - l_string.append_character (' ') - end - write_debug_log (generator + ".block_list:" + l_string ) - end - end - - get_block_view (a_block_id: READABLE_STRING_8; a_response: CMS_RESPONSE) - do - if - a_block_id.is_case_insensitive_equal_general ("register") and then - a_response.location.starts_with ("account/roc-register") - then - get_block_view_register (a_block_id, a_response) - elseif - a_block_id.is_case_insensitive_equal_general ("reactivate") and then - a_response.location.starts_with ("account/reactivate") - then - get_block_view_reactivate (a_block_id, a_response) - elseif - a_block_id.is_case_insensitive_equal_general ("new_password") and then - a_response.location.starts_with ("account/new-password") - then - get_block_view_new_password (a_block_id, a_response) - elseif - a_block_id.is_case_insensitive_equal_general ("reset_password") and then - a_response.location.starts_with ("account/reset-password") - then - get_block_view_reset_password (a_block_id, a_response) - end - end - - -feature {NONE} -- Token Generation - - new_token: STRING - -- Generate a new token activation token - local - l_token: STRING - l_security: SECURITY_PROVIDER - l_encode: URL_ENCODER - do - create l_security - l_token := l_security.token - create l_encode - from until l_token.same_string (l_encode.encoded_string (l_token)) loop - -- Loop ensure that we have a security token that does not contain characters that need encoding. - -- We cannot simply to an encode-decode because the email sent to the user will contain an encoded token - -- but the user will need to use an unencoded token if activation has to be done manually. - l_token := l_security.token - end - Result := l_token - end - -feature {NONE} -- Helpers - - template_block (a_block_id: READABLE_STRING_8; a_response: CMS_RESPONSE): detachable CMS_SMARTY_TEMPLATE_BLOCK - -- Smarty content block for `a_block_id' - local - p: detachable PATH - do - create p.make_from_string ("templates") - p := p.extended ("block_").appended (a_block_id).appended_with_extension ("tpl") - - p := a_response.api.module_theme_resource_location (Current, p) - if p /= Void then - if attached p.entry as e then - create Result.make (a_block_id, Void, p.parent, e) - else - create Result.make (a_block_id, Void, p.parent, p) - end - end - end - -feature {NONE} -- Block views - - get_block_view_login (a_block_id: READABLE_STRING_8; a_response: CMS_RESPONSE) - local --- vals: CMS_VALUE_TABLE - do - if attached template_block (a_block_id, a_response) as l_tpl_block then --- create vals.make (1) --- -- add the variable to the block --- value_table_alter (vals, a_response) --- across --- vals as ic --- loop --- l_tpl_block.set_value (ic.item, ic.key) --- end - a_response.add_block (l_tpl_block, "content") - else - debug ("cms") - a_response.add_warning_message ("Error with block [" + a_block_id + "]") - end - end - end - - get_block_view_register (a_block_id: READABLE_STRING_8; a_response: CMS_RESPONSE) - do - if a_response.request.is_get_request_method then - if attached template_block (a_block_id, a_response) as l_tpl_block then - a_response.add_block (l_tpl_block, "content") - else - debug ("cms") - a_response.add_warning_message ("Error with block [" + a_block_id + "]") - end - end - elseif a_response.request.is_post_request_method then - if a_response.values.has ("error_name") or else a_response.values.has ("error_email") then - if attached template_block (a_block_id, a_response) as l_tpl_block then --- l_tpl_block.set_value (a_response.values.item ("error_name"), "error_name") --- l_tpl_block.set_value (a_response.values.item ("error_email"), "error_email") --- l_tpl_block.set_value (a_response.values.item ("email"), "email") --- l_tpl_block.set_value (a_response.values.item ("name"), "name") - a_response.add_block (l_tpl_block, "content") - else - debug ("cms") - a_response.add_warning_message ("Error with block [" + a_block_id + "]") - end - end - else - if attached template_block ("post_register", a_response) as l_tpl_block then - a_response.add_block (l_tpl_block, "content") - else - debug ("cms") - a_response.add_warning_message ("Error with block [" + a_block_id + "]") - end - end - end - end - end - - - get_block_view_reactivate (a_block_id: READABLE_STRING_8; a_response: CMS_RESPONSE) - do - if a_response.request.is_get_request_method then - if attached template_block (a_block_id, a_response) as l_tpl_block then - a_response.add_block (l_tpl_block, "content") - else - debug ("cms") - a_response.add_warning_message ("Error with block [" + a_block_id + "]") - end - end - elseif a_response.request.is_post_request_method then - if a_response.values.has ("error_email") or else a_response.values.has ("is_active") then - if attached template_block (a_block_id, a_response) as l_tpl_block then --- l_tpl_block.set_value (a_response.values.item ("error_email"), "error_email") --- l_tpl_block.set_value (a_response.values.item ("email"), "email") --- l_tpl_block.set_value (a_response.values.item ("is_active"), "is_active") - a_response.add_block (l_tpl_block, "content") - else - debug ("cms") - a_response.add_warning_message ("Error with block [" + a_block_id + "]") - end - end - else - if attached template_block ("post_reactivate", a_response) as l_tpl_block then - a_response.add_block (l_tpl_block, "content") - else - debug ("cms") - a_response.add_warning_message ("Error with block [" + a_block_id + "]") - end - end - end - end - end - - get_block_view_new_password (a_block_id: READABLE_STRING_8; a_response: CMS_RESPONSE) - do - if a_response.request.is_get_request_method then - if attached template_block (a_block_id, a_response) as l_tpl_block then - a_response.add_block (l_tpl_block, "content") - else - debug ("cms") - a_response.add_warning_message ("Error with block [" + a_block_id + "]") - end - end - elseif a_response.request.is_post_request_method then - if a_response.values.has ("error_email") or else a_response.values.has ("error_username") then - if attached template_block (a_block_id, a_response) as l_tpl_block then --- l_tpl_block.set_value (a_response.values.item ("error_email"), "error_email") --- l_tpl_block.set_value (a_response.values.item ("email"), "email") --- l_tpl_block.set_value (a_response.values.item ("error_username"), "error_username") --- l_tpl_block.set_value (a_response.values.item ("username"), "username") - a_response.add_block (l_tpl_block, "content") - else - debug ("cms") - a_response.add_warning_message ("Error with block [" + a_block_id + "]") - end - end - else - if attached template_block ("post_password", a_response) as l_tpl_block then - a_response.add_block (l_tpl_block, "content") - else - debug ("cms") - a_response.add_warning_message ("Error with block [" + a_block_id + "]") - end - end - end - end - end - - get_block_view_reset_password (a_block_id: READABLE_STRING_8; a_response: CMS_RESPONSE) - do - if a_response.request.is_get_request_method then - if attached template_block (a_block_id, a_response) as l_tpl_block then --- l_tpl_block.set_value (a_response.values.item ("token"), "token") --- l_tpl_block.set_value (a_response.values.item ("error_token"), "error_token") - a_response.add_block (l_tpl_block, "content") - else - debug ("cms") - a_response.add_warning_message ("Error with block [" + a_block_id + "]") - end - end - elseif a_response.request.is_post_request_method then - if a_response.values.has ("error_token") or else a_response.values.has ("error_password") then - if attached template_block (a_block_id, a_response) as l_tpl_block then --- l_tpl_block.set_value (a_response.values.item ("error_token"), "error_token") --- l_tpl_block.set_value (a_response.values.item ("error_password"), "error_password") --- l_tpl_block.set_value (a_response.values.item ("token"), "token") - a_response.add_block (l_tpl_block, "content") - else - debug ("cms") - a_response.add_warning_message ("Error with block [" + a_block_id + "]") - end - end - else - if attached template_block ("post_reset", a_response) as l_tpl_block then - a_response.add_block (l_tpl_block, "content") - else - debug ("cms") - a_response.add_warning_message ("Error with block [" + a_block_id + "]") - end - end - end - end - end - -note - copyright: "Copyright (c) 1984-2013, Eiffel Software and others" - license: "Eiffel Forum License v2 (see http://www.eiffel.com/licensing/forum.txt)" - source: "[ - Eiffel Software - 5949 Hollister Ave., Goleta, CA 93117 USA - Telephone 805-685-1006, Fax 805-685-6869 - Website http://www.eiffel.com - Customer support http://support.eiffel.com - ]" -end diff --git a/modules/oauth20/oauth20.ecf b/modules/oauth20/oauth20.ecf index a13a01b..669b785 100644 --- a/modules/oauth20/oauth20.ecf +++ b/modules/oauth20/oauth20.ecf @@ -7,14 +7,14 @@