Commit 2bf29d0d authored by Gabriel Monnerat's avatar Gabriel Monnerat

erp5_oauth_google_login: Add comments and minor changes to make the code more readable

parent bd182d18
...@@ -7,17 +7,21 @@ context.REQUEST.set('Base_createOauth2User', 1) ...@@ -7,17 +7,21 @@ context.REQUEST.set('Base_createOauth2User', 1)
portal = context.getPortalObject() portal = context.getPortalObject()
if portal.portal_activities.countMessageWithTag(tag) > 0: if portal.portal_activities.countMessageWithTag(tag) > 0:
# If activity already exists, it means that the user reloaded the page and
# searchUsers() from ERP5ExternalOauth2ExtractionPlugin:186 did not find the user yet
return return
person = portal.Base_getUserValueByUserId(reference) person = portal.Base_getUserValueByUserId(reference)
if person is not None: current_user = portal.portal_membership.getAuthenticatedMember()
context.log("Person already exists please " + \
"consider this object: %s" % person.getRelativeUrl()) if person is not None or (current_user and current_user is None):
# Script should here stop if person exists or the user logged in is a Zope user
return return
activate_kw = {'tag': tag} activate_kw = {'tag': tag}
# In future we can move this script to another, because this script is generic enough # In future we can move this script to another, because this script is generic enough
# to support Facebook login # to support Facebook login, for example.
assert login_portal_type in ("Google Login",), "Impossible to select a portal type" assert login_portal_type in ("Google Login",), "Impossible to select a portal type"
if user_id in ("Anonymous User", None): if user_id in ("Anonymous User", None):
...@@ -27,13 +31,11 @@ if user_id in ("Anonymous User", None): ...@@ -27,13 +31,11 @@ if user_id in ("Anonymous User", None):
last_name=last_name, last_name=last_name,
default_email_coordinate_text=email, default_email_coordinate_text=email,
activate_kw=activate_kw) activate_kw=activate_kw)
# Support erp5_credential duration = getattr(portal.portal_preferences,
getDuration = getattr(portal.portal_preferences, "getPreferredCredentialAssignmentDuration",
"getPreferredCredentialAssignmentDuration", lambda: 0)() or 365
None)
assignment_duration = getDuration and getDuration() or 365
today = DateTime() today = DateTime()
delay = today + assignment_duration delay = today + duration
# Support erp5_credential # Support erp5_credential
getAssignmentCategoryList = getattr(portal.portal_preferences, getAssignmentCategoryList = getattr(portal.portal_preferences,
......
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