From 1ece5b26be8efd77fc7ca9b8f99cf734a81c5b97 Mon Sep 17 00:00:00 2001 From: Rafael Monnerat <rafael@nexedi.com> Date: Mon, 12 Feb 2018 19:31:32 +0100 Subject: [PATCH] erp5_base: Upgrade login to Facebook/Google login when applicable. --- .../extension.erp5.PersonLoginMigration.py | 28 +++++++++++++------ 1 file changed, 20 insertions(+), 8 deletions(-) diff --git a/bt5/erp5_base/ExtensionTemplateItem/portal_components/extension.erp5.PersonLoginMigration.py b/bt5/erp5_base/ExtensionTemplateItem/portal_components/extension.erp5.PersonLoginMigration.py index 23aaec4bfc..4d2cecf1fc 100644 --- a/bt5/erp5_base/ExtensionTemplateItem/portal_components/extension.erp5.PersonLoginMigration.py +++ b/bt5/erp5_base/ExtensionTemplateItem/portal_components/extension.erp5.PersonLoginMigration.py @@ -1,22 +1,34 @@ def migrateToERP5Login(self): assert self.getPortalType() == 'Person' + login_portal_type = 'ERP5 Login' reference = self.getReference() if not reference: # no user id and no login is required return - if not self.hasUserId() or self.getUserId() == reference: + + if not (self.hasUserId() or self.getUserId() == reference): self._baseSetUserId(reference) self.reindexObject() - if not self.hasPassword(): - # no login is required, but possibly another Login type object is required if implemented - return - if len(self.objectValues(portal_type=self.getPortalObject().getPortalLoginTypeList())): + + if reference.startswith("go_"): + login_portal_type = "Google Login" + reference = self.getDefaultEmailText() + elif reference.startswith("fb_"): + login_portal_type = "Facebook Login" + reference = reference[len("fb_"):] + else: + if not self.hasPassword(): + # no login is required, but possibly another Login type object is required if implemented + return + if len(self.objectValues(portal_type=login_portal_type)): # already migrated return login = self.newContent( - portal_type='ERP5 Login', + portal_type=login_portal_type, reference=reference, ) - login._setEncodedPassword(self.getPassword()) + if login_portal_type == "ERP5 Login": + login._setEncodedPassword(self.getPassword()) + self._setEncodedPassword(None) + login.validate() - self._setEncodedPassword(None) -- 2.30.9