Updated clean CMS_AUTHENTICATION_MODULE
Updated basic_auth module to handle templates All the auth modules depends on CMS_AUTHENTICATION_MODULE Send mail is done using features from CMS_AUTHENTICATION_MODULE. Update redirect in roc_auth.js after success login to home.
This commit is contained in:
@@ -1,7 +0,0 @@
|
|||||||
{
|
|
||||||
"api_secret":"ADD_YOUR_SECRET_KEY",
|
|
||||||
"api_key":"ADD_YOUR_PUBLIC_KEY",
|
|
||||||
"scope": "email",
|
|
||||||
"api_revoke":"https://accounts.google.com/o/oauth2/revoke?token=$ACCESS_TOKEN",
|
|
||||||
"protected_resource_url":"https://www.googleapis.com/plus/v1/people/me"
|
|
||||||
}
|
|
||||||
@@ -39,7 +39,7 @@ ROC_AUTH.login = function() {
|
|||||||
if (request.readyState == 4) {
|
if (request.readyState == 4) {
|
||||||
if (request.status==200) {
|
if (request.status==200) {
|
||||||
delete form;
|
delete form;
|
||||||
window.location=origin;
|
window.location=window.location.origin;
|
||||||
}
|
}
|
||||||
else{
|
else{
|
||||||
if (navigator.userAgent.toLowerCase().indexOf("firefox") != -1){
|
if (navigator.userAgent.toLowerCase().indexOf("firefox") != -1){
|
||||||
@@ -12,14 +12,11 @@ inherit
|
|||||||
register_hooks
|
register_hooks
|
||||||
end
|
end
|
||||||
|
|
||||||
CMS_HOOK_BLOCK
|
|
||||||
|
|
||||||
CMS_HOOK_AUTO_REGISTER
|
CMS_HOOK_AUTO_REGISTER
|
||||||
|
|
||||||
CMS_HOOK_MENU_SYSTEM_ALTER
|
CMS_HOOK_MENU_SYSTEM_ALTER
|
||||||
|
|
||||||
CMS_HOOK_VALUE_TABLE_ALTER
|
|
||||||
|
|
||||||
SHARED_EXECUTION_ENVIRONMENT
|
SHARED_EXECUTION_ENVIRONMENT
|
||||||
export
|
export
|
||||||
{NONE} all
|
{NONE} all
|
||||||
@@ -77,13 +74,7 @@ feature -- Router
|
|||||||
configure_web (a_api: CMS_API; a_router: WSF_ROUTER)
|
configure_web (a_api: CMS_API; a_router: WSF_ROUTER)
|
||||||
do
|
do
|
||||||
a_router.handle ("/account/roc-login", create {WSF_URI_AGENT_HANDLER}.make (agent handle_login (a_api, ?, ?)), a_router.methods_head_get)
|
a_router.handle ("/account/roc-login", create {WSF_URI_AGENT_HANDLER}.make (agent handle_login (a_api, ?, ?)), a_router.methods_head_get)
|
||||||
a_router.handle ("/account/roc-basic-auth", create {WSF_URI_AGENT_HANDLER}.make (agent handle_login_basic_auth (a_api, ?, ?)), a_router.methods_head_get)
|
a_router.handle ("/account/roc-logout", create {WSF_URI_AGENT_HANDLER}.make (agent handle_logout (a_api, ?, ?)), a_router.methods_head_get)
|
||||||
a_router.handle ("/account/roc-register", create {WSF_URI_AGENT_HANDLER}.make (agent handle_register (a_api, ?, ?)), a_router.methods_get_post)
|
|
||||||
a_router.handle ("/account/activate/{token}", create {WSF_URI_TEMPLATE_AGENT_HANDLER}.make (agent handle_activation (a_api, ?, ?)), a_router.methods_head_get)
|
|
||||||
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/roc-logout", create {WSF_URI_AGENT_HANDLER}.make (agent handle_logout (a_api, ?, ?)), a_router.methods_get_post)
|
|
||||||
end
|
end
|
||||||
|
|
||||||
feature -- Hooks configuration
|
feature -- Hooks configuration
|
||||||
@@ -92,18 +83,6 @@ feature -- Hooks configuration
|
|||||||
-- Module hooks configuration.
|
-- Module hooks configuration.
|
||||||
do
|
do
|
||||||
auto_subscribe_to_hooks (a_response)
|
auto_subscribe_to_hooks (a_response)
|
||||||
a_response.subscribe_to_block_hook (Current)
|
|
||||||
a_response.subscribe_to_value_table_alter_hook (Current)
|
|
||||||
end
|
|
||||||
|
|
||||||
feature -- Hooks
|
|
||||||
|
|
||||||
value_table_alter (a_value: CMS_VALUE_TABLE; a_response: CMS_RESPONSE)
|
|
||||||
-- <Precursor>
|
|
||||||
do
|
|
||||||
if attached current_user (a_response.request) as l_user then
|
|
||||||
a_value.force (l_user, "user")
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
|
|
||||||
menu_system_alter (a_menu_system: CMS_MENU_SYSTEM; a_response: CMS_RESPONSE)
|
menu_system_alter (a_menu_system: CMS_MENU_SYSTEM; a_response: CMS_RESPONSE)
|
||||||
@@ -120,61 +99,10 @@ feature -- Hooks
|
|||||||
create lnk.make ("Login", "account/roc-login")
|
create lnk.make ("Login", "account/roc-login")
|
||||||
lnk.set_weight (98)
|
lnk.set_weight (98)
|
||||||
a_menu_system.primary_menu.extend (lnk)
|
a_menu_system.primary_menu.extend (lnk)
|
||||||
if a_response.location.starts_with ("account/") then
|
|
||||||
create lnk.make ("Basic Auth", "account/roc-basic-auth")
|
|
||||||
lnk.set_expandable (True)
|
|
||||||
a_response.add_to_primary_tabs (lnk)
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
block_list: ITERABLE [like {CMS_BLOCK}.name]
|
feature -- Handler
|
||||||
local
|
|
||||||
l_string: STRING
|
|
||||||
do
|
|
||||||
Result := <<"login", "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 ("login") and then
|
|
||||||
a_response.location.starts_with ("account/roc-basic-auth")
|
|
||||||
then
|
|
||||||
a_response.add_javascript_url (a_response.url ("module/" + name + "/files/js/roc_auth.js", Void))
|
|
||||||
get_block_view_login (a_block_id, a_response)
|
|
||||||
elseif
|
|
||||||
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
|
|
||||||
|
|
||||||
handle_login (api: CMS_API; req: WSF_REQUEST; res: WSF_RESPONSE)
|
handle_login (api: CMS_API; req: WSF_REQUEST; res: WSF_RESPONSE)
|
||||||
local
|
local
|
||||||
@@ -192,469 +120,17 @@ feature -- Hooks
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
handle_login_basic_auth (api: CMS_API; req: WSF_REQUEST; res: WSF_RESPONSE)
|
|
||||||
local
|
|
||||||
r: CMS_RESPONSE
|
|
||||||
do
|
|
||||||
create {GENERIC_VIEW_CMS_RESPONSE} r.make (req, res, api)
|
|
||||||
r.set_value ("Basic Auth", "optional_content_type")
|
|
||||||
r.execute
|
|
||||||
end
|
|
||||||
|
|
||||||
handle_logout (api: CMS_API; req: WSF_REQUEST; res: WSF_RESPONSE)
|
handle_logout (api: CMS_API; req: WSF_REQUEST; res: WSF_RESPONSE)
|
||||||
local
|
local
|
||||||
r: CMS_RESPONSE
|
r: CMS_RESPONSE
|
||||||
l_url: STRING
|
|
||||||
do
|
do
|
||||||
create {GENERIC_VIEW_CMS_RESPONSE} r.make (req, res, api)
|
create {GENERIC_VIEW_CMS_RESPONSE} r.make (req, res, api)
|
||||||
r.set_status_code ({HTTP_CONSTANTS}.found)
|
r.set_redirection (r.absolute_url ("", Void))
|
||||||
l_url := req.absolute_script_url ("/basic_auth_logoff")
|
|
||||||
r.set_redirection (l_url)
|
|
||||||
r.execute
|
|
||||||
end
|
|
||||||
|
|
||||||
handle_register (api: CMS_API; req: WSF_REQUEST; res: WSF_RESPONSE)
|
|
||||||
local
|
|
||||||
r: CMS_RESPONSE
|
|
||||||
l_user_api: CMS_USER_API
|
|
||||||
u: CMS_USER
|
|
||||||
l_roles: LIST [CMS_USER_ROLE]
|
|
||||||
l_exist: BOOLEAN
|
|
||||||
es: CMS_AUTHENTICATON_EMAIL_SERVICE
|
|
||||||
l_url: STRING
|
|
||||||
l_token: STRING
|
|
||||||
do
|
|
||||||
create {GENERIC_VIEW_CMS_RESPONSE} r.make (req, res, api)
|
|
||||||
r.set_value ("Register", "optional_content_type")
|
|
||||||
if req.is_post_request_method then
|
|
||||||
if
|
|
||||||
attached {WSF_STRING} req.form_parameter ("name") as l_name and then
|
|
||||||
attached {WSF_STRING} req.form_parameter ("password") as l_password and then
|
|
||||||
attached {WSF_STRING} req.form_parameter ("email") as l_email
|
|
||||||
then
|
|
||||||
l_user_api := api.user_api
|
|
||||||
|
|
||||||
if attached l_user_api.user_by_name (l_name.value) then
|
|
||||||
-- Username already exist.
|
|
||||||
r.values.force ("The user name exist!", "error_name")
|
|
||||||
l_exist := True
|
|
||||||
end
|
|
||||||
if attached l_user_api.user_by_email (l_email.value) then
|
|
||||||
-- Emails already exist.
|
|
||||||
r.values.force ("The email exist!", "error_email")
|
|
||||||
l_exist := True
|
|
||||||
end
|
|
||||||
|
|
||||||
if not l_exist then
|
|
||||||
-- New user
|
|
||||||
create {ARRAYED_LIST [CMS_USER_ROLE]}l_roles.make (1)
|
|
||||||
l_roles.force (l_user_api.authenticated_user_role)
|
|
||||||
|
|
||||||
create u.make (l_name.value)
|
|
||||||
u.set_email (l_email.value)
|
|
||||||
u.set_password (l_password.value)
|
|
||||||
u.set_roles (l_roles)
|
|
||||||
l_user_api.new_user (u)
|
|
||||||
|
|
||||||
-- Create activation token
|
|
||||||
l_token := new_token
|
|
||||||
l_user_api.new_activation (l_token, u.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_email")
|
|
||||||
es.send_contact_email (l_email.value, l_url)
|
|
||||||
|
|
||||||
else
|
|
||||||
r.values.force (l_name.value, "name")
|
|
||||||
r.values.force (l_email.value, "email")
|
|
||||||
r.set_status_code ({HTTP_CONSTANTS}.bad_request)
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
r.execute
|
|
||||||
end
|
|
||||||
|
|
||||||
handle_activation (api: CMS_API; req: WSF_REQUEST; res: WSF_RESPONSE)
|
|
||||||
local
|
|
||||||
r: CMS_RESPONSE
|
|
||||||
l_user_api: CMS_USER_API
|
|
||||||
l_ir: INTERNAL_SERVER_ERROR_CMS_RESPONSE
|
|
||||||
do
|
|
||||||
l_user_api := api.user_api
|
|
||||||
create {GENERIC_VIEW_CMS_RESPONSE} r.make (req, res, api)
|
|
||||||
if attached {WSF_STRING} req.path_parameter ("token") as l_token then
|
|
||||||
|
|
||||||
if attached {CMS_USER} l_user_api.user_by_activation_token (l_token.value) as l_user then
|
|
||||||
-- Valid user_id
|
|
||||||
l_user.mark_active
|
|
||||||
l_user_api.update_user (l_user)
|
|
||||||
l_user_api.remove_activation (l_token.value)
|
|
||||||
r.set_value ("Account activated", "optional_content_type")
|
|
||||||
r.set_main_content ("<p> Your account <i>"+ l_user.name +"</i> has been activated</p>")
|
|
||||||
else
|
|
||||||
-- the token does not exist, or it was already used.
|
|
||||||
r.set_status_code ({HTTP_CONSTANTS}.bad_request)
|
|
||||||
r.set_value ("Account not activated", "optional_content_type")
|
|
||||||
r.set_main_content ("<p>The token <i>" + l_token.value +"</i> is not valid " + r.link ("Reactivate Account", "account/reactivate", Void) + "</p>")
|
|
||||||
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.values.force ("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.values.force ("The email does not exist or !", "error_email")
|
|
||||||
r.values.force (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.values.force ("The email does not exist !", "error_email")
|
|
||||||
r.values.force (l_email.value, "email")
|
|
||||||
r.set_status_code ({HTTP_CONSTANTS}.bad_request)
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
|
||||||
r.execute
|
r.execute
|
||||||
end
|
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.values.force (l_token.value, "token")
|
|
||||||
if l_user_api.user_by_password_token (l_token.value) = Void then
|
|
||||||
r.values.force ("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.values.force ("Passwords Don't Match", "error_password")
|
|
||||||
r.values.force (l_token.value, "token")
|
|
||||||
r.set_status_code ({HTTP_CONSTANTS}.bad_request)
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
|
||||||
r.execute
|
|
||||||
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") 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")
|
|
||||||
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
|
|
||||||
|
|
||||||
|
|
||||||
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} -- Implementation: date and time
|
|
||||||
|
|
||||||
http_date_format_to_date (s: READABLE_STRING_8): detachable DATE_TIME
|
|
||||||
local
|
|
||||||
d: HTTP_DATE
|
|
||||||
do
|
|
||||||
create d.make_from_string (s)
|
|
||||||
if not d.has_error then
|
|
||||||
Result := d.date_time
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
file_date (p: PATH): DATE_TIME
|
|
||||||
require
|
|
||||||
path_exists: (create {FILE_UTILITIES}).file_path_exists (p)
|
|
||||||
local
|
|
||||||
f: RAW_FILE
|
|
||||||
do
|
|
||||||
create f.make_with_path (p)
|
|
||||||
Result := timestamp_to_date (f.date)
|
|
||||||
end
|
|
||||||
|
|
||||||
timestamp_to_date (n: INTEGER): DATE_TIME
|
|
||||||
local
|
|
||||||
d: HTTP_DATE
|
|
||||||
do
|
|
||||||
create d.make_from_timestamp (n)
|
|
||||||
Result := d.date_time
|
|
||||||
end
|
|
||||||
|
|
||||||
|
|
||||||
note
|
note
|
||||||
|
|||||||
@@ -1,7 +0,0 @@
|
|||||||
{
|
|
||||||
"api_secret":"ADD_YOUR_SECRET_KEY",
|
|
||||||
"api_key":"ADD_YOUR_PUBLIC_KEY",
|
|
||||||
"scope": "email",
|
|
||||||
"api_revoke":"https://accounts.google.com/o/oauth2/revoke?token=$ACCESS_TOKEN",
|
|
||||||
"protected_resource_url":"https://www.googleapis.com/plus/v1/people/me"
|
|
||||||
}
|
|
||||||
@@ -12,7 +12,10 @@
|
|||||||
</option>
|
</option>
|
||||||
<library name="base" location="$ISE_LIBRARY\library\base\base-safe.ecf"/>
|
<library name="base" location="$ISE_LIBRARY\library\base\base-safe.ecf"/>
|
||||||
<library name="cms" location="..\..\cms-safe.ecf"/>
|
<library name="cms" location="..\..\cms-safe.ecf"/>
|
||||||
|
<library name="cms_app_env" location="..\..\library\app_env\app_env-safe.ecf" readonly="false"/>
|
||||||
|
<library name="cms_auth_module" location="..\..\modules\auth\auth-safe.ecf" readonly="false"/>
|
||||||
<library name="cms_model" location="..\..\library\model\cms_model-safe.ecf" readonly="false"/>
|
<library name="cms_model" location="..\..\library\model\cms_model-safe.ecf" readonly="false"/>
|
||||||
|
<library name="encoder" location="$ISE_LIBRARY\contrib\library\web\framework\ewf\text\encoder\encoder-safe.ecf"/>
|
||||||
<library name="http" location="$ISE_LIBRARY\contrib\library\network\protocol\http\http-safe.ecf"/>
|
<library name="http" location="$ISE_LIBRARY\contrib\library\network\protocol\http\http-safe.ecf"/>
|
||||||
<library name="http_authorization" location="$ISE_LIBRARY\contrib\library\network\authentication\http_authorization\http_authorization-safe.ecf" readonly="false"/>
|
<library name="http_authorization" location="$ISE_LIBRARY\contrib\library\network\authentication\http_authorization\http_authorization-safe.ecf" readonly="false"/>
|
||||||
<library name="wsf" location="$ISE_LIBRARY\contrib\library\web\framework\ewf\wsf\wsf-safe.ecf"/>
|
<library name="wsf" location="$ISE_LIBRARY\contrib\library\web\framework\ewf\wsf\wsf-safe.ecf"/>
|
||||||
|
|||||||
@@ -12,6 +12,7 @@
|
|||||||
</option>
|
</option>
|
||||||
<library name="base" location="$ISE_LIBRARY\library\base\base.ecf"/>
|
<library name="base" location="$ISE_LIBRARY\library\base\base.ecf"/>
|
||||||
<library name="cms" location="..\..\cms.ecf"/>
|
<library name="cms" location="..\..\cms.ecf"/>
|
||||||
|
<library name="cms_auth_module" location="..\..\modules\auth\auth.ecf" readonly="false"/>
|
||||||
<library name="cms_model" location="..\..\library\model\cms_model.ecf" readonly="false"/>
|
<library name="cms_model" location="..\..\library\model\cms_model.ecf" readonly="false"/>
|
||||||
<library name="http" location="$ISE_LIBRARY\contrib\library\network\protocol\http\http.ecf"/>
|
<library name="http" location="$ISE_LIBRARY\contrib\library\network\protocol\http\http.ecf"/>
|
||||||
<library name="http_authorization" location="$ISE_LIBRARY\contrib\library\network\authentication\http_authorization\http_authorization.ecf" readonly="false"/>
|
<library name="http_authorization" location="$ISE_LIBRARY\contrib\library\network\authentication\http_authorization\http_authorization.ecf" readonly="false"/>
|
||||||
|
|||||||
@@ -22,6 +22,12 @@ inherit
|
|||||||
|
|
||||||
CMS_HOOK_MENU_SYSTEM_ALTER
|
CMS_HOOK_MENU_SYSTEM_ALTER
|
||||||
|
|
||||||
|
CMS_HOOK_VALUE_TABLE_ALTER
|
||||||
|
|
||||||
|
SHARED_LOGGER
|
||||||
|
|
||||||
|
CMS_REQUEST_UTIL
|
||||||
|
|
||||||
create
|
create
|
||||||
make
|
make
|
||||||
|
|
||||||
@@ -45,6 +51,13 @@ feature -- Access: router
|
|||||||
do
|
do
|
||||||
configure_api_login (a_api, a_router)
|
configure_api_login (a_api, a_router)
|
||||||
configure_api_logoff (a_api, a_router)
|
configure_api_logoff (a_api, a_router)
|
||||||
|
a_router.handle ("/account/roc-basic-auth", create {WSF_URI_AGENT_HANDLER}.make (agent handle_login_basic_auth (a_api, ?, ?)), a_router.methods_head_get)
|
||||||
|
a_router.handle ("/account/roc-register", create {WSF_URI_AGENT_HANDLER}.make (agent handle_register (a_api, ?, ?)), a_router.methods_get_post)
|
||||||
|
a_router.handle ("/account/activate/{token}", create {WSF_URI_TEMPLATE_AGENT_HANDLER}.make (agent handle_activation (a_api, ?, ?)), a_router.methods_head_get)
|
||||||
|
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)
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|
||||||
feature -- Access: filter
|
feature -- Access: filter
|
||||||
@@ -81,27 +94,242 @@ feature {NONE} -- Implementation: routes
|
|||||||
a_router.handle ("/basic_auth_logoff", l_bal_handler, l_methods)
|
a_router.handle ("/basic_auth_logoff", l_bal_handler, l_methods)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
|
handle_login_basic_auth (api: CMS_API; req: WSF_REQUEST; res: WSF_RESPONSE)
|
||||||
|
local
|
||||||
|
r: CMS_RESPONSE
|
||||||
|
do
|
||||||
|
create {GENERIC_VIEW_CMS_RESPONSE} r.make (req, res, api)
|
||||||
|
r.set_value ("Basic Auth", "optional_content_type")
|
||||||
|
r.execute
|
||||||
|
end
|
||||||
|
|
||||||
|
|
||||||
|
handle_register (api: CMS_API; req: WSF_REQUEST; res: WSF_RESPONSE)
|
||||||
|
local
|
||||||
|
r: CMS_RESPONSE
|
||||||
|
l_user_api: CMS_USER_API
|
||||||
|
u: CMS_USER
|
||||||
|
l_roles: LIST [CMS_USER_ROLE]
|
||||||
|
l_exist: BOOLEAN
|
||||||
|
es: CMS_AUTHENTICATON_EMAIL_SERVICE
|
||||||
|
l_url: STRING
|
||||||
|
l_token: STRING
|
||||||
|
do
|
||||||
|
create {GENERIC_VIEW_CMS_RESPONSE} r.make (req, res, api)
|
||||||
|
r.set_value ("Register", "optional_content_type")
|
||||||
|
if req.is_post_request_method then
|
||||||
|
if
|
||||||
|
attached {WSF_STRING} req.form_parameter ("name") as l_name and then
|
||||||
|
attached {WSF_STRING} req.form_parameter ("password") as l_password and then
|
||||||
|
attached {WSF_STRING} req.form_parameter ("email") as l_email
|
||||||
|
then
|
||||||
|
l_user_api := api.user_api
|
||||||
|
|
||||||
|
if attached l_user_api.user_by_name (l_name.value) then
|
||||||
|
-- Username already exist.
|
||||||
|
r.values.force ("The user name exist!", "error_name")
|
||||||
|
l_exist := True
|
||||||
|
end
|
||||||
|
if attached l_user_api.user_by_email (l_email.value) then
|
||||||
|
-- Emails already exist.
|
||||||
|
r.values.force ("The email exist!", "error_email")
|
||||||
|
l_exist := True
|
||||||
|
end
|
||||||
|
|
||||||
|
if not l_exist then
|
||||||
|
-- New user
|
||||||
|
create {ARRAYED_LIST [CMS_USER_ROLE]}l_roles.make (1)
|
||||||
|
l_roles.force (l_user_api.authenticated_user_role)
|
||||||
|
|
||||||
|
create u.make (l_name.value)
|
||||||
|
u.set_email (l_email.value)
|
||||||
|
u.set_password (l_password.value)
|
||||||
|
u.set_roles (l_roles)
|
||||||
|
l_user_api.new_user (u)
|
||||||
|
|
||||||
|
-- Create activation token
|
||||||
|
l_token := new_token
|
||||||
|
l_user_api.new_activation (l_token, u.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_email")
|
||||||
|
es.send_contact_email (l_email.value, l_url)
|
||||||
|
|
||||||
|
else
|
||||||
|
r.values.force (l_name.value, "name")
|
||||||
|
r.values.force (l_email.value, "email")
|
||||||
|
r.set_status_code ({HTTP_CONSTANTS}.bad_request)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
r.execute
|
||||||
|
end
|
||||||
|
|
||||||
|
handle_activation (api: CMS_API; req: WSF_REQUEST; res: WSF_RESPONSE)
|
||||||
|
local
|
||||||
|
r: CMS_RESPONSE
|
||||||
|
l_user_api: CMS_USER_API
|
||||||
|
l_ir: INTERNAL_SERVER_ERROR_CMS_RESPONSE
|
||||||
|
do
|
||||||
|
l_user_api := api.user_api
|
||||||
|
create {GENERIC_VIEW_CMS_RESPONSE} r.make (req, res, api)
|
||||||
|
if attached {WSF_STRING} req.path_parameter ("token") as l_token then
|
||||||
|
|
||||||
|
if attached {CMS_USER} l_user_api.user_by_activation_token (l_token.value) as l_user then
|
||||||
|
-- Valid user_id
|
||||||
|
l_user.mark_active
|
||||||
|
l_user_api.update_user (l_user)
|
||||||
|
l_user_api.remove_activation (l_token.value)
|
||||||
|
r.set_value ("Account activated", "optional_content_type")
|
||||||
|
r.set_main_content ("<p> Your account <i>"+ l_user.name +"</i> has been activated</p>")
|
||||||
|
else
|
||||||
|
-- the token does not exist, or it was already used.
|
||||||
|
r.set_status_code ({HTTP_CONSTANTS}.bad_request)
|
||||||
|
r.set_value ("Account not activated", "optional_content_type")
|
||||||
|
r.set_main_content ("<p>The token <i>" + l_token.value +"</i> is not valid " + r.link ("Reactivate Account", "account/reactivate", Void) + "</p>")
|
||||||
|
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.values.force ("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.values.force ("The email does not exist or !", "error_email")
|
||||||
|
r.values.force (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.values.force ("The email does not exist !", "error_email")
|
||||||
|
r.values.force (l_email.value, "email")
|
||||||
|
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.values.force (l_token.value, "token")
|
||||||
|
if l_user_api.user_by_password_token (l_token.value) = Void then
|
||||||
|
r.values.force ("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.values.force ("Passwords Don't Match", "error_password")
|
||||||
|
r.values.force (l_token.value, "token")
|
||||||
|
r.set_status_code ({HTTP_CONSTANTS}.bad_request)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
r.execute
|
||||||
|
end
|
||||||
|
|
||||||
feature -- Hooks configuration
|
feature -- Hooks configuration
|
||||||
|
|
||||||
register_hooks (a_response: CMS_RESPONSE)
|
register_hooks (a_response: CMS_RESPONSE)
|
||||||
-- Module hooks configuration.
|
-- Module hooks configuration.
|
||||||
do
|
do
|
||||||
-- a_response.subscribe_to_block_hook (Current)
|
auto_subscribe_to_hooks (a_response)
|
||||||
|
a_response.subscribe_to_block_hook (Current)
|
||||||
|
a_response.subscribe_to_value_table_alter_hook (Current)
|
||||||
end
|
end
|
||||||
|
|
||||||
feature -- Hooks
|
feature -- Hooks
|
||||||
|
|
||||||
block_list: ITERABLE [like {CMS_BLOCK}.name]
|
value_table_alter (a_value: CMS_VALUE_TABLE; a_response: CMS_RESPONSE)
|
||||||
-- List of block names, managed by current object.
|
-- <Precursor>
|
||||||
do
|
do
|
||||||
Result := <<"basic_auth_login_form">>
|
if attached current_user (a_response.request) as l_user then
|
||||||
end
|
a_value.force (l_user, "user")
|
||||||
|
|
||||||
get_block_view (a_block_id: READABLE_STRING_8; a_response: CMS_RESPONSE)
|
|
||||||
-- Get block object identified by `a_block_id' and associate with `a_response'.
|
|
||||||
do
|
|
||||||
if a_block_id.same_string ("basic_auth_login_form") then
|
|
||||||
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
@@ -109,18 +337,285 @@ feature -- Hooks
|
|||||||
-- Hook execution on collection of menu contained by `a_menu_system'
|
-- Hook execution on collection of menu contained by `a_menu_system'
|
||||||
-- for related response `a_response'.
|
-- for related response `a_response'.
|
||||||
local
|
local
|
||||||
-- lnk: CMS_LOCAL_LINK
|
lnk: CMS_LOCAL_LINK
|
||||||
|
lnk2: detachable CMS_LINK
|
||||||
do
|
do
|
||||||
-- if attached a_response.current_user (a_response.request) as u then
|
if attached a_response.current_user (a_response.request) as u then
|
||||||
-- create lnk.make (u.name + " (Logout)", "basic_auth_logoff?destination=" + a_response.request.request_uri)
|
across
|
||||||
-- else
|
a_menu_system.primary_menu.items as ic
|
||||||
-- create lnk.make ("Login", "basic_auth_login?destination=" + a_response.request.request_uri)
|
until
|
||||||
-- end
|
lnk2 /= Void
|
||||||
-- if not a_menu_system.primary_menu.has (lnk) then
|
loop
|
||||||
-- lnk.set_weight (99)
|
if ic.item.title.has_substring ("(Logout)") then
|
||||||
-- a_menu_system.primary_menu.extend (lnk)
|
lnk2 := ic.item
|
||||||
-- end
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
if lnk2 /= Void then
|
||||||
|
a_menu_system.primary_menu.remove (lnk2)
|
||||||
|
end
|
||||||
|
|
||||||
|
create lnk.make (u.name + " (Logout)", "basic_auth_logoff" )
|
||||||
|
lnk.set_weight (98)
|
||||||
|
a_menu_system.primary_menu.extend (lnk)
|
||||||
|
else
|
||||||
|
if a_response.location.starts_with ("account/") then
|
||||||
|
create lnk.make ("Basic Auth", "account/roc-basic-auth")
|
||||||
|
lnk.set_expandable (True)
|
||||||
|
a_response.add_to_primary_tabs (lnk)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
block_list: ITERABLE [like {CMS_BLOCK}.name]
|
||||||
|
local
|
||||||
|
l_string: STRING
|
||||||
|
do
|
||||||
|
Result := <<"login", "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 ("login") and then
|
||||||
|
a_response.location.starts_with ("account/roc-basic-auth")
|
||||||
|
then
|
||||||
|
a_response.add_javascript_url (a_response.url ("module/" + name + "/files/js/roc_auth.js", Void))
|
||||||
|
get_block_view_login (a_block_id, a_response)
|
||||||
|
elseif
|
||||||
|
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
|
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") 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")
|
||||||
|
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
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -1,49 +0,0 @@
|
|||||||
note
|
|
||||||
description: "Summary description for {CMS_OAUTH_20_EMAIL_SERVICE}."
|
|
||||||
date: "$Date$"
|
|
||||||
revision: "$Revision$"
|
|
||||||
|
|
||||||
class
|
|
||||||
CMS_OAUTH_20_EMAIL_SERVICE
|
|
||||||
|
|
||||||
inherit
|
|
||||||
EMAIL_SERVICE
|
|
||||||
redefine
|
|
||||||
initialize,
|
|
||||||
parameters
|
|
||||||
end
|
|
||||||
|
|
||||||
create
|
|
||||||
make
|
|
||||||
|
|
||||||
feature {NONE} -- Initialization
|
|
||||||
|
|
||||||
initialize
|
|
||||||
do
|
|
||||||
Precursor
|
|
||||||
contact_email := parameters.contact_email
|
|
||||||
end
|
|
||||||
|
|
||||||
parameters: CMS_OAUTH_20_EMAIL_SERVICE_PARAMETERS
|
|
||||||
-- Associated parameters.
|
|
||||||
|
|
||||||
feature -- Access
|
|
||||||
|
|
||||||
contact_email: IMMUTABLE_STRING_8
|
|
||||||
-- contact email.
|
|
||||||
|
|
||||||
feature -- Basic Operations
|
|
||||||
|
|
||||||
send_contact_welcome_email (a_to, a_content: READABLE_STRING_8)
|
|
||||||
-- Send successful contact message `a_token' to `a_to'.
|
|
||||||
require
|
|
||||||
attached_to: a_to /= Void
|
|
||||||
local
|
|
||||||
l_message: STRING
|
|
||||||
do
|
|
||||||
create l_message.make_from_string (parameters.account_welcome)
|
|
||||||
l_message.replace_substring_all ("$link", a_content)
|
|
||||||
send_message (contact_email, a_to, parameters.contact_subject_register, l_message)
|
|
||||||
end
|
|
||||||
|
|
||||||
end
|
|
||||||
@@ -1,156 +0,0 @@
|
|||||||
note
|
|
||||||
description: "Summary description for {CMS_OAUTH_20_EMAIL_SERVICE_PARAMETERS}."
|
|
||||||
date: "$Date$"
|
|
||||||
revision: "$Revision$"
|
|
||||||
|
|
||||||
class
|
|
||||||
CMS_OAUTH_20_EMAIL_SERVICE_PARAMETERS
|
|
||||||
|
|
||||||
inherit
|
|
||||||
EMAIL_SERVICE_PARAMETERS
|
|
||||||
|
|
||||||
create
|
|
||||||
make
|
|
||||||
|
|
||||||
feature {NONE} -- Initialization
|
|
||||||
|
|
||||||
make (a_cms_api: CMS_API)
|
|
||||||
local
|
|
||||||
utf: UTF_CONVERTER
|
|
||||||
l_site_name: READABLE_STRING_8
|
|
||||||
s: detachable READABLE_STRING_32
|
|
||||||
l_contact_email, l_subject_register, l_subject_activate, l_subject_password, l_subject_oauth: detachable READABLE_STRING_8
|
|
||||||
do
|
|
||||||
cms_api := a_cms_api
|
|
||||||
-- Use global smtp setting if any, otherwise "localhost"
|
|
||||||
smtp_server := utf.escaped_utf_32_string_to_utf_8_string_8 (a_cms_api.setup.text_item_or_default ("smtp", "localhost"))
|
|
||||||
l_site_name := utf.escaped_utf_32_string_to_utf_8_string_8 (a_cms_api.setup.site_name)
|
|
||||||
admin_email := a_cms_api.setup.site_email
|
|
||||||
|
|
||||||
if not admin_email.has ('<') then
|
|
||||||
admin_email := l_site_name + " <" + admin_email +">"
|
|
||||||
end
|
|
||||||
|
|
||||||
if attached {CONFIG_READER} a_cms_api.module_configuration_by_name ({CMS_AUTHENTICATION_MODULE}.name, Void) as cfg then
|
|
||||||
if attached cfg.text_item ("smtp") as l_smtp then
|
|
||||||
-- Overwrite global smtp setting if any.
|
|
||||||
smtp_server := utf.utf_32_string_to_utf_8_string_8 (l_smtp)
|
|
||||||
end
|
|
||||||
s := cfg.text_item ("email")
|
|
||||||
if s /= Void then
|
|
||||||
l_contact_email := utf.utf_32_string_to_utf_8_string_8 (s)
|
|
||||||
end
|
|
||||||
s := cfg.text_item ("subject_register")
|
|
||||||
if s /= Void then
|
|
||||||
l_subject_register := utf.utf_32_string_to_utf_8_string_8 (s)
|
|
||||||
end
|
|
||||||
s := cfg.text_item ("subject_activate")
|
|
||||||
if s /= Void then
|
|
||||||
l_subject_register := utf.utf_32_string_to_utf_8_string_8 (s)
|
|
||||||
end
|
|
||||||
s := cfg.text_item ("subject_password")
|
|
||||||
if s /= Void then
|
|
||||||
l_subject_register := utf.utf_32_string_to_utf_8_string_8 (s)
|
|
||||||
end
|
|
||||||
s := cfg.text_item ("subject_oauth")
|
|
||||||
if s /= Void then
|
|
||||||
l_subject_oauth := utf.utf_32_string_to_utf_8_string_8 (s)
|
|
||||||
end
|
|
||||||
|
|
||||||
end
|
|
||||||
if l_contact_email /= Void then
|
|
||||||
if not l_contact_email.has ('<') then
|
|
||||||
l_contact_email := l_site_name + " <" + l_contact_email + ">"
|
|
||||||
end
|
|
||||||
contact_email := l_contact_email
|
|
||||||
else
|
|
||||||
contact_email := admin_email
|
|
||||||
end
|
|
||||||
if l_subject_register /= Void then
|
|
||||||
contact_subject_register := l_subject_register
|
|
||||||
else
|
|
||||||
contact_subject_register := "Thank you for registering with us."
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
feature -- Access
|
|
||||||
|
|
||||||
smtp_server: IMMUTABLE_STRING_8
|
|
||||||
|
|
||||||
admin_email: IMMUTABLE_STRING_8
|
|
||||||
|
|
||||||
contact_email: IMMUTABLE_STRING_8
|
|
||||||
-- Contact email.
|
|
||||||
|
|
||||||
contact_subject_register: IMMUTABLE_STRING_8
|
|
||||||
|
|
||||||
account_welcome: STRING
|
|
||||||
-- Account welcome template email message.
|
|
||||||
do
|
|
||||||
Result := template_string ("account_welcome.html", default_template_account_welcome)
|
|
||||||
end
|
|
||||||
|
|
||||||
feature {NONE} -- Implementation: Template
|
|
||||||
|
|
||||||
template_path (a_name: READABLE_STRING_GENERAL): PATH
|
|
||||||
-- Location of template named `a_name'.
|
|
||||||
do
|
|
||||||
Result := cms_api.module_location_by_name ({CMS_AUTHENTICATION_MODULE}.name).extended (a_name)
|
|
||||||
end
|
|
||||||
|
|
||||||
template_string (a_name: READABLE_STRING_GENERAL; a_default: STRING): STRING
|
|
||||||
-- Content of template named `a_name', or `a_default' if template is not found.
|
|
||||||
local
|
|
||||||
p: PATH
|
|
||||||
do
|
|
||||||
p := template_path ("account_activation.html")
|
|
||||||
if attached read_template_file (p) as l_content then
|
|
||||||
Result := l_content
|
|
||||||
else
|
|
||||||
create Result.make_from_string (a_default)
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
feature {NONE} -- Implementation
|
|
||||||
|
|
||||||
cms_api: CMS_API
|
|
||||||
|
|
||||||
read_template_file (a_path: PATH): detachable STRING
|
|
||||||
-- Read the content of the file at path `a_path'.
|
|
||||||
local
|
|
||||||
l_file: FILE
|
|
||||||
n: INTEGER
|
|
||||||
do
|
|
||||||
create {PLAIN_TEXT_FILE} l_file.make_with_path (a_path)
|
|
||||||
if l_file.exists and then l_file.is_readable then
|
|
||||||
n := l_file.count
|
|
||||||
l_file.open_read
|
|
||||||
l_file.read_stream (n)
|
|
||||||
Result := l_file.last_string
|
|
||||||
l_file.close
|
|
||||||
else
|
|
||||||
-- Error
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
|
|
||||||
feature {NONE} -- Message email
|
|
||||||
|
|
||||||
default_template_account_welcome: STRING = "[
|
|
||||||
<!doctype html>
|
|
||||||
<html lang="en">
|
|
||||||
<head>
|
|
||||||
<meta charset="utf-8">
|
|
||||||
<title>Welcome</title>
|
|
||||||
<meta name="description" content="Welcome">
|
|
||||||
<meta name="author" content="ROC CMS">
|
|
||||||
</head>
|
|
||||||
|
|
||||||
<body>
|
|
||||||
<p>Welcome to<a href="...">ROC CMS</a></p>
|
|
||||||
<p>Thank you for joining us.</p>
|
|
||||||
</body>
|
|
||||||
</html>
|
|
||||||
]"
|
|
||||||
|
|
||||||
end
|
|
||||||
@@ -379,7 +379,7 @@ feature -- OAuth2 Login with Provider
|
|||||||
l_user: CMS_USER
|
l_user: CMS_USER
|
||||||
l_roles: LIST [CMS_USER_ROLE]
|
l_roles: LIST [CMS_USER_ROLE]
|
||||||
l_cookie: WSF_COOKIE
|
l_cookie: WSF_COOKIE
|
||||||
es: CMS_OAUTH_20_EMAIL_SERVICE
|
es: CMS_AUTHENTICATON_EMAIL_SERVICE
|
||||||
do
|
do
|
||||||
if attached {WSF_STRING} req.path_parameter ({CMS_OAUTH_20_CONSTANTS}.oauth_callback) as l_callback and then
|
if attached {WSF_STRING} req.path_parameter ({CMS_OAUTH_20_CONSTANTS}.oauth_callback) as l_callback and then
|
||||||
attached {CMS_OAUTH_20_CONSUMER} a_user_oauth_api.oauth_consumer_by_callback (l_callback.value) as l_consumer and then
|
attached {CMS_OAUTH_20_CONSUMER} a_user_oauth_api.oauth_consumer_by_callback (l_callback.value) as l_consumer and then
|
||||||
@@ -435,7 +435,7 @@ feature -- OAuth2 Login with Provider
|
|||||||
|
|
||||||
|
|
||||||
-- Send Email
|
-- Send Email
|
||||||
create es.make (create {CMS_OAUTH_20_EMAIL_SERVICE_PARAMETERS}.make (api))
|
create es.make (create {CMS_AUTHENTICATION_EMAIL_SERVICE_PARAMETERS}.make (api))
|
||||||
write_debug_log (generator + ".handle_callback_oauth: send_contact_welcome_email")
|
write_debug_log (generator + ".handle_callback_oauth: send_contact_welcome_email")
|
||||||
es.send_contact_welcome_email (l_email, "")
|
es.send_contact_welcome_email (l_email, "")
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -1,50 +0,0 @@
|
|||||||
note
|
|
||||||
description: "Summary description for {CMS_OPENID_EMAIL_SERVICE}."
|
|
||||||
date: "$Date$"
|
|
||||||
revision: "$Revision$"
|
|
||||||
|
|
||||||
class
|
|
||||||
CMS_OPENID_EMAIL_SERVICE
|
|
||||||
|
|
||||||
inherit
|
|
||||||
EMAIL_SERVICE
|
|
||||||
redefine
|
|
||||||
initialize,
|
|
||||||
parameters
|
|
||||||
end
|
|
||||||
|
|
||||||
create
|
|
||||||
make
|
|
||||||
|
|
||||||
feature {NONE} -- Initialization
|
|
||||||
|
|
||||||
initialize
|
|
||||||
do
|
|
||||||
Precursor
|
|
||||||
contact_email := parameters.contact_email
|
|
||||||
end
|
|
||||||
|
|
||||||
parameters: CMS_OPENID_EMAIL_SERVICE_PARAMETERS
|
|
||||||
-- Associated parameters.
|
|
||||||
|
|
||||||
feature -- Access
|
|
||||||
|
|
||||||
contact_email: IMMUTABLE_STRING_8
|
|
||||||
-- contact email.
|
|
||||||
|
|
||||||
feature -- Basic Operations
|
|
||||||
|
|
||||||
|
|
||||||
send_contact_welcome_email (a_to, a_content: READABLE_STRING_8)
|
|
||||||
-- Send successful contact message `a_token' to `a_to'.
|
|
||||||
require
|
|
||||||
attached_to: a_to /= Void
|
|
||||||
local
|
|
||||||
l_message: STRING
|
|
||||||
do
|
|
||||||
create l_message.make_from_string (parameters.account_welcome)
|
|
||||||
l_message.replace_substring_all ("$link", a_content)
|
|
||||||
send_message (contact_email, a_to, parameters.contact_subject_register, l_message)
|
|
||||||
end
|
|
||||||
|
|
||||||
end
|
|
||||||
@@ -1,156 +0,0 @@
|
|||||||
note
|
|
||||||
description: "Summary description for {CMS_OPENID_EMAIL_SERVICE_PARAMETERS}."
|
|
||||||
date: "$Date$"
|
|
||||||
revision: "$Revision$"
|
|
||||||
|
|
||||||
class
|
|
||||||
CMS_OPENID_EMAIL_SERVICE_PARAMETERS
|
|
||||||
|
|
||||||
inherit
|
|
||||||
EMAIL_SERVICE_PARAMETERS
|
|
||||||
|
|
||||||
create
|
|
||||||
make
|
|
||||||
|
|
||||||
feature {NONE} -- Initialization
|
|
||||||
|
|
||||||
make (a_cms_api: CMS_API)
|
|
||||||
local
|
|
||||||
utf: UTF_CONVERTER
|
|
||||||
l_site_name: READABLE_STRING_8
|
|
||||||
s: detachable READABLE_STRING_32
|
|
||||||
l_contact_email, l_subject_register, l_subject_activate, l_subject_password, l_subject_oauth: detachable READABLE_STRING_8
|
|
||||||
do
|
|
||||||
cms_api := a_cms_api
|
|
||||||
-- Use global smtp setting if any, otherwise "localhost"
|
|
||||||
smtp_server := utf.escaped_utf_32_string_to_utf_8_string_8 (a_cms_api.setup.text_item_or_default ("smtp", "localhost"))
|
|
||||||
l_site_name := utf.escaped_utf_32_string_to_utf_8_string_8 (a_cms_api.setup.site_name)
|
|
||||||
admin_email := a_cms_api.setup.site_email
|
|
||||||
|
|
||||||
if not admin_email.has ('<') then
|
|
||||||
admin_email := l_site_name + " <" + admin_email +">"
|
|
||||||
end
|
|
||||||
|
|
||||||
if attached {CONFIG_READER} a_cms_api.module_configuration_by_name ({CMS_AUTHENTICATION_MODULE}.name, Void) as cfg then
|
|
||||||
if attached cfg.text_item ("smtp") as l_smtp then
|
|
||||||
-- Overwrite global smtp setting if any.
|
|
||||||
smtp_server := utf.utf_32_string_to_utf_8_string_8 (l_smtp)
|
|
||||||
end
|
|
||||||
s := cfg.text_item ("email")
|
|
||||||
if s /= Void then
|
|
||||||
l_contact_email := utf.utf_32_string_to_utf_8_string_8 (s)
|
|
||||||
end
|
|
||||||
s := cfg.text_item ("subject_register")
|
|
||||||
if s /= Void then
|
|
||||||
l_subject_register := utf.utf_32_string_to_utf_8_string_8 (s)
|
|
||||||
end
|
|
||||||
s := cfg.text_item ("subject_activate")
|
|
||||||
if s /= Void then
|
|
||||||
l_subject_register := utf.utf_32_string_to_utf_8_string_8 (s)
|
|
||||||
end
|
|
||||||
s := cfg.text_item ("subject_password")
|
|
||||||
if s /= Void then
|
|
||||||
l_subject_register := utf.utf_32_string_to_utf_8_string_8 (s)
|
|
||||||
end
|
|
||||||
s := cfg.text_item ("subject_oauth")
|
|
||||||
if s /= Void then
|
|
||||||
l_subject_oauth := utf.utf_32_string_to_utf_8_string_8 (s)
|
|
||||||
end
|
|
||||||
|
|
||||||
end
|
|
||||||
if l_contact_email /= Void then
|
|
||||||
if not l_contact_email.has ('<') then
|
|
||||||
l_contact_email := l_site_name + " <" + l_contact_email + ">"
|
|
||||||
end
|
|
||||||
contact_email := l_contact_email
|
|
||||||
else
|
|
||||||
contact_email := admin_email
|
|
||||||
end
|
|
||||||
if l_subject_register /= Void then
|
|
||||||
contact_subject_register := l_subject_register
|
|
||||||
else
|
|
||||||
contact_subject_register := "Thank you for registering with us."
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
feature -- Access
|
|
||||||
|
|
||||||
smtp_server: IMMUTABLE_STRING_8
|
|
||||||
|
|
||||||
admin_email: IMMUTABLE_STRING_8
|
|
||||||
|
|
||||||
contact_email: IMMUTABLE_STRING_8
|
|
||||||
-- Contact email.
|
|
||||||
|
|
||||||
contact_subject_register: IMMUTABLE_STRING_8
|
|
||||||
|
|
||||||
account_welcome: STRING
|
|
||||||
-- Account welcome template email message.
|
|
||||||
do
|
|
||||||
Result := template_string ("account_welcome.html", default_template_account_welcome)
|
|
||||||
end
|
|
||||||
|
|
||||||
feature {NONE} -- Implementation: Template
|
|
||||||
|
|
||||||
template_path (a_name: READABLE_STRING_GENERAL): PATH
|
|
||||||
-- Location of template named `a_name'.
|
|
||||||
do
|
|
||||||
Result := cms_api.module_location_by_name ({CMS_AUTHENTICATION_MODULE}.name).extended (a_name)
|
|
||||||
end
|
|
||||||
|
|
||||||
template_string (a_name: READABLE_STRING_GENERAL; a_default: STRING): STRING
|
|
||||||
-- Content of template named `a_name', or `a_default' if template is not found.
|
|
||||||
local
|
|
||||||
p: PATH
|
|
||||||
do
|
|
||||||
p := template_path ("account_activation.html")
|
|
||||||
if attached read_template_file (p) as l_content then
|
|
||||||
Result := l_content
|
|
||||||
else
|
|
||||||
create Result.make_from_string (a_default)
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
feature {NONE} -- Implementation
|
|
||||||
|
|
||||||
cms_api: CMS_API
|
|
||||||
|
|
||||||
read_template_file (a_path: PATH): detachable STRING
|
|
||||||
-- Read the content of the file at path `a_path'.
|
|
||||||
local
|
|
||||||
l_file: FILE
|
|
||||||
n: INTEGER
|
|
||||||
do
|
|
||||||
create {PLAIN_TEXT_FILE} l_file.make_with_path (a_path)
|
|
||||||
if l_file.exists and then l_file.is_readable then
|
|
||||||
n := l_file.count
|
|
||||||
l_file.open_read
|
|
||||||
l_file.read_stream (n)
|
|
||||||
Result := l_file.last_string
|
|
||||||
l_file.close
|
|
||||||
else
|
|
||||||
-- Error
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
|
|
||||||
feature {NONE} -- Message email
|
|
||||||
|
|
||||||
default_template_account_welcome: STRING = "[
|
|
||||||
<!doctype html>
|
|
||||||
<html lang="en">
|
|
||||||
<head>
|
|
||||||
<meta charset="utf-8">
|
|
||||||
<title>Welcome</title>
|
|
||||||
<meta name="description" content="Welcome">
|
|
||||||
<meta name="author" content="ROC CMS">
|
|
||||||
</head>
|
|
||||||
|
|
||||||
<body>
|
|
||||||
<p>Welcome to<a href="...">ROC CMS</a></p>
|
|
||||||
<p>Thank you for joining us.</p>
|
|
||||||
</body>
|
|
||||||
</html>
|
|
||||||
]"
|
|
||||||
|
|
||||||
end
|
|
||||||
@@ -381,7 +381,7 @@ feature -- Openid Login
|
|||||||
l_user: CMS_USER
|
l_user: CMS_USER
|
||||||
l_roles: LIST [CMS_USER_ROLE]
|
l_roles: LIST [CMS_USER_ROLE]
|
||||||
l_cookie: WSF_COOKIE
|
l_cookie: WSF_COOKIE
|
||||||
es: CMS_OPENID_EMAIL_SERVICE
|
es: CMS_AUTHENTICATON_EMAIL_SERVICE
|
||||||
b: STRING
|
b: STRING
|
||||||
o: OPENID_CONSUMER
|
o: OPENID_CONSUMER
|
||||||
v: OPENID_CONSUMER_VALIDATION
|
v: OPENID_CONSUMER_VALIDATION
|
||||||
@@ -431,9 +431,8 @@ feature -- Openid Login
|
|||||||
l_cookie.set_path ("/")
|
l_cookie.set_path ("/")
|
||||||
res.add_cookie (l_cookie)
|
res.add_cookie (l_cookie)
|
||||||
|
|
||||||
|
|
||||||
-- Send Email
|
-- Send Email
|
||||||
create es.make (create {CMS_OPENID_EMAIL_SERVICE_PARAMETERS}.make (api))
|
create es.make (create {CMS_AUTHENTICATION_EMAIL_SERVICE_PARAMETERS}.make (api))
|
||||||
write_debug_log (generator + ".handle_callback_openid: send_contact_welcome_email")
|
write_debug_log (generator + ".handle_callback_openid: send_contact_welcome_email")
|
||||||
es.send_contact_welcome_email (l_email, "")
|
es.send_contact_welcome_email (l_email, "")
|
||||||
end
|
end
|
||||||
|
|||||||
Reference in New Issue
Block a user