From c692c43f9836785a2c5e75b525306524b2ea137c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fr=C3=A9d=C3=A9ric=20Peters?= Date: Fri, 12 Dec 2008 11:26:14 +0100 Subject: [PATCH] magic parthenay store --- extra/modules/stores.py | 38 +++++++++++++++++++++++++++++++++++++- 1 file changed, 37 insertions(+), 1 deletion(-) diff --git a/extra/modules/stores.py b/extra/modules/stores.py index b0bbd99..dce683c 100644 --- a/extra/modules/stores.py +++ b/extra/modules/stores.py @@ -1,10 +1,15 @@ +import os +import twill + from quixote import get_session, get_session_manager, get_request, get_publisher +from qommon.storage import fix_key import authentic.identities import collectivity + class MergedIdentityStore(authentic.identities.IdentitiesStoreStorage): def get_identity_for_name_identifier(self, name_identifier): x = authentic.identities.IdentitiesStoreStorage.get_identity_for_name_identifier( @@ -33,15 +38,46 @@ class InheritingIdentityStore(authentic.identities.IdentitiesStoreStorage): return t +class ParthenayIdentityStore(InheritingIdentityStore): + def get_identity_for_account(self, account): + t = None + if not self.identity_class.has_key('_' + account.username): + t = InheritingIdentityStore.get_identity_for_account(self, account) + if t: + return t + + # some twill magic + twill.commands.reset_browser() + twill.commands.go( + "http://web.cc-parthenay.fr/_layouts/login.aspx?ReturnUrl=%2f_layouts%2fAuthenticate.aspx%3fSource%3d%252fPages%252f&Source=%2fPages%2f") + twill.commands.fv('aspnetForm', '2', account.username) + twill.commands.fv('aspnetForm', '3', account.password) + twill.commands.submit() + if twill.commands.browser.get_url() == 'http://web.cc-parthenay.fr/Pages/': + # authent ok + try: + t = self.identity_class.get('_' + account.username) + except KeyError: + t = self.identity_class(id = '_' + account.username) + t.store() + + return t + + def get_collectivity_identity_class(collectivity_id): class CollectivityIdentity(authentic.identities.Identity): _names = 'identities-' + str(collectivity_id) + def store(self): + self._filename = os.path.join(self._names, fix_key(self.id)) + self.__class__ = authentic.identities.Identity + authentic.identities.Identity.store(self) return CollectivityIdentity def get_collectivity_store(collectivity_id): if collectivity_id == '547263': # Parthenay - raise NotImplementedError() + store = ParthenayIdentityStore( + identity_class = get_collectivity_identity_class(collectivity_id)) elif collectivity_id: # Vandoeuvre (546555) and others store = InheritingIdentityStore(