diff --git a/larpe/trunk/larpe/admin/hosts.ptl b/larpe/trunk/larpe/admin/hosts.ptl index 06376cf..2c1c25f 100644 --- a/larpe/trunk/larpe/admin/hosts.ptl +++ b/larpe/trunk/larpe/admin/hosts.ptl @@ -791,8 +791,12 @@ POST request. You can desactivate some or all of them, or change their value.''' self.host.http_headers[name] = old_value self.host.store() - def generate_apache_filter(self): + def generate_apache_filters(self): # Set Python filter path for Apache configuration + site_auth = site_authentication.get_site_authentication(self.host) + filters = site_auth.get_filters() + replace_login_form = self.host.auth_form_places == 'form_everywhere' and \ + self.host.auth_form_action python_path = os.path.join(self.host.site_dir, 'filters') if python_path not in self.host.apache_python_paths: self.host.apache_python_paths.append(python_path) @@ -800,16 +804,25 @@ POST request. You can desactivate some or all of them, or change their value.''' # Write Python filter python_file = open(os.path.join(self.host.site_dir, 'filters', 'output_replace_form.py'), 'w') python_file.write(open(OUTPUT_FILTER_BASE).read()) - python_file.write('''\ -def filter_page(filter, page): + if filters or replace_login_form: + python_file.write("def filter_page(filter, page):\n") + if replace_login_form: + python_file.write('''\ current_form = re.compile('
]*?action="%(auth_form_action)s".*?>.*?
', re.DOTALL) - return current_form.sub('
', page) -''' % { 'auth_form_action': self.host.auth_form_action, 'name': self.host.name }) - python_file.close() + page = current_form.sub('
', page)''' + % { 'auth_form_action': self.host.auth_form_action, 'name': self.host.name }) + for filter in filters: + python_file.write(" r = re.compile(r\"\"\"%s\"\"\", re.DOTALL)\n" % filter["re"]) + python_file.write(" page = r.sub(r\"\"\"%s\"\"\", page)\n" % filter["sub"]) + python_file.write(" return page\n") + python_file.close() + # Set Python filter for Apache configuration + if not 'output_replace_form' in self.host.apache_output_python_filters: + self.host.apache_output_python_filters.append('output_replace_form') + else: + if 'output_replace_form' in self.host.apache_output_python_filters: + self.host.apache_output_python_filters.remove('output_replace_form') - # Set Python filter for Apache configuration - if not 'output_replace_form' in self.host.apache_output_python_filters: - self.host.apache_output_python_filters.append('output_replace_form') def sso_init_link [html] (self): form = self.form_sso_init_link() @@ -859,13 +872,7 @@ authenticate on any of these pages, and don't need to be redirected to a separat for f in fields: setattr(self.host, f, form.get_widget(f).parse()) self.host.auth_form_url = self.host.auth_url - - if self.host.auth_form_places == 'form_everywhere' and self.host.auth_form_action: - self.generate_apache_filter() - else: - if 'output_replace_form' in self.host.apache_output_python_filters: - self.host.apache_output_python_filters.remove('output_replace_form') - + self.generate_apache_filters() self.host.store() write_apache2_vhosts() diff --git a/larpe/trunk/larpe/plugins/site_authentication/ciril_net_rh.py b/larpe/trunk/larpe/plugins/site_authentication/ciril_net_rh.py index 100c1a5..8a00a22 100644 --- a/larpe/trunk/larpe/plugins/site_authentication/ciril_net_rh.py +++ b/larpe/trunk/larpe/plugins/site_authentication/ciril_net_rh.py @@ -1,3 +1,4 @@ + import re from quixote import redirect @@ -31,9 +32,24 @@ class CirilSiteAuthentication(SiteAuthentication): match = regexp.findall(data) if match: success = True - return_content = '' % match[0] + return_content = redirect(match[0]) return success, return_content + def get_filters(self): + """ Rewrite the logout link """ + filters = [] + logout = {} + if not hasattr(self.host, 'base_url'): + return None + base_url_tokens = self.host.base_url.split('/') + base_url_tokens[-1] = 'logout' + new_logout_url = '/'.join(base_url_tokens) + logout["re"] = """(D.*?connexion)""" + logout["sub"] = r"\1%s\2" % new_logout_url + filters.append(logout) + return filters + + site_authentication_plugins.register(CirilSiteAuthentication) diff --git a/larpe/trunk/larpe/site_authentication.ptl b/larpe/trunk/larpe/site_authentication.ptl index 3343b02..68f54aa 100644 --- a/larpe/trunk/larpe/site_authentication.ptl +++ b/larpe/trunk/larpe/site_authentication.ptl @@ -105,6 +105,18 @@ class SiteAuthentication: value = values[0], options = options) return form + def get_filters(self): + """ Allows to filters the page + Example with a logout link: + filters = [] + filter = {} + filer["re"] = "Logout" + filer["sub"] = "Logout" % logout_url + filters.append(filter) + return filters + """ + return None + def submit_local_auth_form(self, form): username = form.get_widget('username').parse() password = form.get_widget('password').parse() @@ -279,9 +291,6 @@ class SiteAuthentication: return success, return_content def local_logout(self, federation=None, user=None): - """ - TODO : recode with twill - """ if federation is None and user is not None: federations = Federation.select(lambda x: user.name_identifiers[0] in x.name_identifiers) if federations: