Commit 9dd76a3b authored by Rafael Monnerat's avatar Rafael Monnerat

erp5_oauth_[google|facebook]_login: Normalize get*Connector so we can use on login page

  This is helpfull to display or not the buttons on login page
parent fc742752
......@@ -9,11 +9,8 @@ def _getFacebookClientIdAndSecretKey(portal, reference="default"):
Internal function.
"""
result_list = unrestrictedSearchFacebookConnector(portal, reference=reference)
assert result_list, "Facebook Connector not found"
if len(result_list) == 2:
raise ValueError("Impossible to select one Facebook Connector")
facebook_connector = result_list[0]
facebook_connector = unrestrictedSearchFacebookConnector(portal, reference=reference)
assert facebook_connector, "Facebook Connector not found"
return facebook_connector.getClientId(), facebook_connector.getSecretKey()
def redirectToFacebookLoginPage(self, came_from=None):
......@@ -34,11 +31,18 @@ def getAccessTokenFromCode(self, code, redirect_uri):
app_id=client_id, app_secret=secret_key)
def unrestrictedSearchFacebookConnector(self, reference="default"):
return self.getPortalObject().portal_catalog.unrestrictedSearchResults(
result_list = self.getPortalObject().portal_catalog.unrestrictedSearchResults(
portal_type="Facebook Connector",
reference=reference,
validation_state="validated",
limit=2)
if not result_list:
return
if len(result_list) != 1:
raise ValueError('Impossible to select Facebook Connector')
return result_list[0].getObject()
def unrestrictedSearchFacebookLogin(self, login, REQUEST=None):
if REQUEST is not None:
......
......@@ -16,7 +16,7 @@
</item>
<item>
<key> <string>id</string> </key>
<value> <string>ERP5Site_getFacebookConnector</string> </value>
<value> <string>ERP5Site_getDefaultFacebookConnector</string> </value>
</item>
<item>
<key> <string>title</string> </key>
......
......@@ -4,6 +4,9 @@ result_list = portal.portal_catalog(
reference=reference,
validation_state="validated",
limit=2)
if not result_list:
return
if len(result_list) != 1:
raise ValueError("Impossible to select one Google Connector")
return result_list[0].getObject()
......@@ -3,13 +3,13 @@ oauth_login_list = []
portal_skin = context.getPortalObject().portal_skins
if getattr(portal_skin, "erp5_oauth_google_login", None) is not None:
connector = context.ERP5Site_getGoogleConnector()
if connector and connector[0].getClientId() is not None:
connector = context.ERP5Site_getDefaultGoogleConnector()
if connector is not None and connector.getClientId() is not None:
oauth_login_list.append("google")
if getattr(portal_skin, "erp5_oauth_facebook_login", None) is not None:
connector = context.ERP5Site_getFacebookConnector()
if connector and connector[0].getClientId() is not None:
connector = context.ERP5Site_getDefaultFacebookConnector()
if connector is not None and connector.getClientId() is not None:
oauth_login_list.append("facebook")
if getattr(portal_skin, "erp5_openid_connect_client", None) is not None:
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment