Commit 55988caf authored by Rafael Monnerat's avatar Rafael Monnerat Committed by Kazuhiko Shiozaki

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 6505490b
...@@ -9,11 +9,8 @@ def _getFacebookClientIdAndSecretKey(portal, reference="default"): ...@@ -9,11 +9,8 @@ def _getFacebookClientIdAndSecretKey(portal, reference="default"):
Internal function. Internal function.
""" """
result_list = unrestrictedSearchFacebookConnector(portal, reference=reference) facebook_connector = unrestrictedSearchFacebookConnector(portal, reference=reference)
assert result_list, "Facebook Connector not found" assert facebook_connector, "Facebook Connector not found"
if len(result_list) == 2:
raise ValueError("Impossible to select one Facebook Connector")
facebook_connector = result_list[0]
return facebook_connector.getClientId(), facebook_connector.getSecretKey() return facebook_connector.getClientId(), facebook_connector.getSecretKey()
def redirectToFacebookLoginPage(self, came_from=None): def redirectToFacebookLoginPage(self, came_from=None):
...@@ -34,11 +31,18 @@ def getAccessTokenFromCode(self, code, redirect_uri): ...@@ -34,11 +31,18 @@ def getAccessTokenFromCode(self, code, redirect_uri):
app_id=client_id, app_secret=secret_key) app_id=client_id, app_secret=secret_key)
def unrestrictedSearchFacebookConnector(self, reference="default"): def unrestrictedSearchFacebookConnector(self, reference="default"):
return self.getPortalObject().portal_catalog.unrestrictedSearchResults( result_list = self.getPortalObject().portal_catalog.unrestrictedSearchResults(
portal_type="Facebook Connector", portal_type="Facebook Connector",
reference=reference, reference=reference,
validation_state="validated", validation_state="validated",
limit=2) 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): def unrestrictedSearchFacebookLogin(self, login, REQUEST=None):
if REQUEST is not None: if REQUEST is not None:
......
...@@ -16,7 +16,7 @@ ...@@ -16,7 +16,7 @@
</item> </item>
<item> <item>
<key> <string>id</string> </key> <key> <string>id</string> </key>
<value> <string>ERP5Site_getFacebookConnector</string> </value> <value> <string>ERP5Site_getDefaultFacebookConnector</string> </value>
</item> </item>
<item> <item>
<key> <string>title</string> </key> <key> <string>title</string> </key>
......
...@@ -4,6 +4,9 @@ result_list = portal.portal_catalog( ...@@ -4,6 +4,9 @@ result_list = portal.portal_catalog(
reference=reference, reference=reference,
validation_state="validated", validation_state="validated",
limit=2) limit=2)
if not result_list:
return
if len(result_list) != 1: if len(result_list) != 1:
raise ValueError("Impossible to select one Google Connector") raise ValueError("Impossible to select one Google Connector")
return result_list[0].getObject() return result_list[0].getObject()
...@@ -3,13 +3,13 @@ oauth_login_list = [] ...@@ -3,13 +3,13 @@ oauth_login_list = []
portal_skin = context.getPortalObject().portal_skins portal_skin = context.getPortalObject().portal_skins
if getattr(portal_skin, "erp5_oauth_google_login", None) is not None: if getattr(portal_skin, "erp5_oauth_google_login", None) is not None:
connector = context.ERP5Site_getGoogleConnector() connector = context.ERP5Site_getDefaultGoogleConnector()
if connector and connector[0].getClientId() is not None: if connector is not None and connector.getClientId() is not None:
oauth_login_list.append("google") oauth_login_list.append("google")
if getattr(portal_skin, "erp5_oauth_facebook_login", None) is not None: if getattr(portal_skin, "erp5_oauth_facebook_login", None) is not None:
connector = context.ERP5Site_getFacebookConnector() connector = context.ERP5Site_getDefaultFacebookConnector()
if connector and connector[0].getClientId() is not None: if connector is not None and connector.getClientId() is not None:
oauth_login_list.append("facebook") oauth_login_list.append("facebook")
if getattr(portal_skin, "erp5_openid_connect_client", None) is not None: 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