Updated Account Info
Add Link and Unlink account with OAuth.
This commit is contained in:
@@ -182,6 +182,8 @@ feature -- Router
|
||||
a_router.handle ("/account/roc-oauth-logout", create {WSF_URI_AGENT_HANDLER}.make (agent handle_logout (a_api, ?, ?)), a_router.methods_get_post)
|
||||
a_router.handle ("/account/login-with-oauth/{callback}", create {WSF_URI_TEMPLATE_AGENT_HANDLER}.make (agent handle_login_with_oauth (a_api,a_user_oauth_api, ?, ?)), a_router.methods_get_post)
|
||||
a_router.handle ("/account/oauth-callback/{callback}", create {WSF_URI_TEMPLATE_AGENT_HANDLER}.make (agent handle_callback_oauth (a_api, a_user_oauth_api, ?, ?)), a_router.methods_get_post)
|
||||
a_router.handle ("/account/oauth-associate", create {WSF_URI_TEMPLATE_AGENT_HANDLER}.make (agent handle_associate (a_api, a_user_oauth_api, ?, ?)), a_router.methods_post)
|
||||
a_router.handle ("/account/oauth-un-associate", create {WSF_URI_TEMPLATE_AGENT_HANDLER}.make (agent handle_un_associate (a_api, a_user_oauth_api, ?, ?)), a_router.methods_post)
|
||||
end
|
||||
|
||||
feature -- Hooks configuration
|
||||
@@ -205,6 +207,10 @@ feature -- Hooks
|
||||
then
|
||||
a_value.force ("account/roc-oauth-logout", "auth_login_strategy")
|
||||
end
|
||||
|
||||
if attached a_response.current_user (a_response.request) as u then
|
||||
associate_account (u, a_value)
|
||||
end
|
||||
end
|
||||
|
||||
menu_system_alter (a_menu_system: CMS_MENU_SYSTEM; a_response: CMS_RESPONSE)
|
||||
@@ -298,6 +304,28 @@ feature -- Hooks
|
||||
end
|
||||
end
|
||||
|
||||
feature {NONE} -- Associate
|
||||
|
||||
associate_account (a_user: CMS_USER; a_value: CMS_VALUE_TABLE)
|
||||
local
|
||||
l_associated: LIST [STRING]
|
||||
l_not_associated: LIST [STRING]
|
||||
do
|
||||
if attached user_oauth_api as l_oauth_api then
|
||||
create {ARRAYED_LIST [STRING]}l_associated.make (1)
|
||||
create {ARRAYED_LIST [STRING]}l_not_associated.make (1)
|
||||
across l_oauth_api.oauth2_consumers as ic loop
|
||||
if attached l_oauth_api.user_oauth2_by_id (a_user.id, ic.item) then
|
||||
l_associated.force (ic.item)
|
||||
else
|
||||
l_not_associated.force (ic.item)
|
||||
end
|
||||
end
|
||||
a_value.force (l_associated, "oauth_associated")
|
||||
a_value.force (l_not_associated, "oauth_not_associated")
|
||||
end
|
||||
end
|
||||
|
||||
feature {NONE} -- Helpers
|
||||
|
||||
template_block (a_block_id: READABLE_STRING_8; a_response: CMS_RESPONSE): detachable CMS_SMARTY_TEMPLATE_BLOCK
|
||||
@@ -406,7 +434,7 @@ feature -- OAuth2 Login with Provider
|
||||
then
|
||||
if attached l_user_api.user_by_email (l_email) as p_user then
|
||||
-- User with email exist
|
||||
if attached a_user_oauth_api.user_oauth2_by_id (p_user.id, l_consumer.name) then
|
||||
if attached a_user_oauth_api.user_oauth2_by_id (p_user.id, l_consumer.name) then
|
||||
-- Update oauth entry
|
||||
a_user_oauth_api.update_user_oauth2 (l_access_token.token, l_user_profile, p_user, l_consumer.name )
|
||||
else
|
||||
@@ -417,8 +445,13 @@ feature -- OAuth2 Login with Provider
|
||||
l_cookie.set_max_age (l_access_token.expires_in)
|
||||
l_cookie.set_path ("/")
|
||||
res.add_cookie (l_cookie)
|
||||
elseif attached a_user_oauth_api.user_oauth2_by_email (l_email, l_consumer.name) as p_user then
|
||||
a_user_oauth_api.update_user_oauth2 (l_access_token.token, l_user_profile, p_user, l_consumer.name )
|
||||
create l_cookie.make ({CMS_OAUTH_20_CONSTANTS}.oauth_session, l_access_token.token)
|
||||
l_cookie.set_max_age (l_access_token.expires_in)
|
||||
l_cookie.set_path ("/")
|
||||
res.add_cookie (l_cookie)
|
||||
else
|
||||
|
||||
create {ARRAYED_LIST [CMS_USER_ROLE]} l_roles.make (1)
|
||||
l_roles.force (l_user_api.authenticated_user_role)
|
||||
|
||||
@@ -453,6 +486,47 @@ feature -- OAuth2 Login with Provider
|
||||
|
||||
end
|
||||
|
||||
handle_associate (api: CMS_API; a_oauth_api: CMS_OAUTH_20_API; req: WSF_REQUEST; res: WSF_RESPONSE)
|
||||
local
|
||||
r: CMS_RESPONSE
|
||||
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 ("consumer") as l_consumer and then
|
||||
attached {WSF_STRING} req.form_parameter ("email") as l_email and then
|
||||
attached current_user (req) as l_user
|
||||
then
|
||||
l_user.set_email (l_email.value)
|
||||
a_oauth_api.new_user_oauth2 ("none", "none", l_user, l_consumer.value )
|
||||
-- TODO send email?
|
||||
end
|
||||
end
|
||||
r.set_redirection (req.absolute_script_url ("/account"))
|
||||
r.execute
|
||||
end
|
||||
|
||||
|
||||
handle_un_associate (api: CMS_API; a_oauth_api: CMS_OAUTH_20_API; req: WSF_REQUEST; res: WSF_RESPONSE)
|
||||
local
|
||||
r: CMS_RESPONSE
|
||||
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 ("consumer") as l_consumer and then
|
||||
attached current_user (req) as l_user
|
||||
then
|
||||
a_oauth_api.remove_user_oauth2 (l_user, l_consumer.value)
|
||||
-- TODO send email?
|
||||
end
|
||||
end
|
||||
r.set_redirection (req.absolute_script_url ("/account"))
|
||||
r.execute
|
||||
end
|
||||
|
||||
|
||||
|
||||
feature {NONE} -- Token Generation
|
||||
|
||||
new_token: STRING
|
||||
|
||||
Reference in New Issue
Block a user