Commit 8cf48d0b authored by Rafael Monnerat's avatar Rafael Monnerat

erp5_oauth_facebook_login: Search Login avoiding security_uids

This makes exponentially faster, if you have way too many security uids.
parent 8033b57c
......@@ -2,6 +2,7 @@ import facebook
from ZTUtils import make_query
from Products.ERP5Security.ERP5ExternalOauth2ExtractionPlugin import getFacebookUserEntry
from zExceptions import Unauthorized
def _getFacebookClientIdAndSecretKey(portal, reference="default"):
"""Returns facebook client id and secret key.
......@@ -44,5 +45,14 @@ def unrestrictedSearchFacebookConnector(self):
validation_state="validated",
limit=2)
def unrestrictedSearchFacebookLogin(self, login, REQUEST=None):
if REQUEST is not None:
raise Unauthorized
return self.getPortalObject().portal_catalog.unrestrictedSearchResults(
portal_type="Facebook Login",
reference=login,
validation_state="validated", limit=1)
def getUserEntry(token):
return getFacebookUserEntry(token)
<?xml version="1.0"?>
<ZopeData>
<record id="1" aka="AAAAAAAAAAE=">
<pickle>
<global name="ExternalMethod" module="Products.ExternalMethod.ExternalMethod"/>
</pickle>
<pickle>
<dictionary>
<item>
<key> <string>_function</string> </key>
<value> <string>unrestrictedSearchFacebookLogin</string> </value>
</item>
<item>
<key> <string>_module</string> </key>
<value> <string>FacebookLoginUtility</string> </value>
</item>
<item>
<key> <string>id</string> </key>
<value> <string>ERP5Site_getFacebookLogin</string> </value>
</item>
<item>
<key> <string>title</string> </key>
<value> <string></string> </value>
</item>
</dictionary>
</pickle>
</record>
</ZopeData>
......@@ -3,12 +3,12 @@ from zExceptions import Unauthorized
if REQUEST is not None:
raise Unauthorized
portal_catalog = context.getPortalObject().portal_catalog
login = context.ERP5Site_getFacebookLogin(login)
login = portal_catalog.getResultValue(
portal_type="Facebook Login",
reference=login,
validation_state="validated")
if login is None:
return login
if login is not None:
return login.getParentValue().getRelativeUrl()
if len(login) > 1:
raise ValueError("Duplicated User")
return login[0].getParentValue().getRelativeUrl()
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