diff --git a/extra/ifef.py b/extra/ifef.py index cb8f33f..6a594e3 100644 --- a/extra/ifef.py +++ b/extra/ifef.py @@ -6,6 +6,9 @@ import modules.configuration import authentic.admin.root import modules.afterjobs import modules.callback +import modules.admin_settings +import modules.qommon_template +import modules.authentic_saml get_publisher_class().register_translation_domain('ifef') authentic.admin.root.register_page('afterjobs', diff --git a/extra/modules/admin_settings.py b/extra/modules/admin_settings.py new file mode 100644 index 0000000..ca6ef9c --- /dev/null +++ b/extra/modules/admin_settings.py @@ -0,0 +1,58 @@ +import authentic.admin.settings as settings +from authentic.form import * +import qommon.template +from qommon import get_cfg +from quixote import get_publisher, redirect +import authentic.identities as identities + +STYLESHEET_URL = 'stylesheet_url' +REFERER_PREFIX_URL = 'referer_prefix_url' +CUSTOM_DOMAIN = 'custom_domain' +REGISTRATION_FIELD = 'registration_fields' +THEME = 'theme' + +class NewLibertyProviderUI(settings.LibertyProviderUI): + def edit_form(self): + form = super(NewLibertyProviderUI, self).edit_form() + form.add(StringWidget, STYLESHEET_URL, + title=_('Customized stylesheet URL'), + value=self.lp.get(STYLESHEET_URL, ''), + hint=_('The URL must be https if authentic also use https')) + form.add(StringWidget, REFERER_PREFIX_URL, + title=_('Prefix URL of the HTTP_REFERER'), + value=self.lp.get(REFERER_PREFIX_URL, ''), + hint=_('Used to find which service initiated a request to Authentic')) + names = [None] + [x[0] for x in qommon.template.get_themes().iteritems()] + form.add(SingleSelectWidget, THEME, + title=_('Custom theme'), + value=self.lp.get(THEME,None), + hint=_('Theme to use when an interaction is initated by this service'), + options=names) + form.add(StringWidget, CUSTOM_DOMAIN, + title=_('Custom domain'), + value=self.lp.get(CUSTOM_DOMAIN,None), + hint=_('If the IdP is published on this domain, the used theme will the custom theme for this service.'), + options=names) + form.add(identities.WidgetList, REGISTRATION_FIELD, + title=_('Registration fields'), + element_type=StringWidget, + value=self.lp.get(REGISTRATION_FIELD,[]), + hint=_('List of specific fields to show on the registration page.')) + return form + def edit_submit(self): + return super(NewLibertyProviderUI, self).edit_submit() + +class NewLibertyProvidersDir(settings.LibertyProvidersDir): + def submit_new(self, form, key_provider_id=None): + lpk, error = super(NewLibertyProvidersDir, self).submit_new(form, + key_provider_id) + if not error and form.get_widget(STYLESHEET_URL): + v = {} + for k in (STYLESHEET_URL, REFERER_PREFIX_URL, THEME, CUSTOM_DOMAIN, REGISTRATION_FIELD): + v[k] = form.get_widget(k).parse() + get_cfg('providers').get(lpk).update(v) + get_publisher().write_cfg() + return lpk, error + +settings.LibertyProviderUI = NewLibertyProviderUI +settings.LibertyProvidersDir = NewLibertyProvidersDir diff --git a/extra/modules/authentic_saml.py b/extra/modules/authentic_saml.py new file mode 100644 index 0000000..1ec7128 --- /dev/null +++ b/extra/modules/authentic_saml.py @@ -0,0 +1,11 @@ +from quixote import get_session +import authentic.liberty.saml2 +import qommon.misc as misc + +# Yeah another monkey patch +old_invoke_login = authentic.liberty.saml2.RootDirectory.invoke_login +def invoke_login(self, login, query): + print 'my invoke login' + get_session().service = misc.get_provider_key(login.remoteProviderId) + return old_invoke_login(self, login, query) +authentic.liberty.saml2.RootDirectory.invoke_login = invoke_login diff --git a/extra/modules/qommon_template.py b/extra/modules/qommon_template.py new file mode 100644 index 0000000..d599ce4 --- /dev/null +++ b/extra/modules/qommon_template.py @@ -0,0 +1,44 @@ +import qommon.template as template +from quixote import get_request, get_publisher, get_session +from qommon import get_cfg +from admin_settings import STYLESHEET_URL, REFERER_PREFIX_URL, THEME, \ + CUSTOM_DOMAIN + +__old_decorate = template.decorate + +def decorate(body, response): + request = get_request() + referer = request.environ.get('HTTP_REFERER') + domain = request.environ.get('SERVER_NAME') + session = get_session() + + more_css = [] + body_class = [] + theme = None + stylesheet_url = None + requesting_service = None + + for key, value in get_cfg('providers', {}).iteritems(): + custom_domain = value.get(CUSTOM_DOMAIN) + referer_prefix_url = value.get(REFERER_PREFIX_URL) + if custom_domain == domain or \ + (request.form and request.form.get('service') == key) or \ + (referer_prefix_url and referer and referer.startswith(referer_prefix_url)) or \ + getattr(session, 'service', None) == key: + theme = value.get(THEME) + requesting_service = key + stylesheet_url = value.get(STYLESHEET_URL) + break + if requesting_service: + session.service = requesting_service + body_class.append(requesting_service) + if stylesheet_url: + more_css.append(stylesheet_url) + if theme: + get_publisher().cfg['branding']['theme'] = theme + response.filter.update({'more_css': more_css, 'body_class': body_class}) + return __old_decorate(body, response) + +template.decorate = decorate +import authentic.sessions +authentic.sessions.BasicSession._has_info_keys.append('service') diff --git a/extra/modules/root.ptl b/extra/modules/root.ptl index 67b4ea8..ad3e688 100644 --- a/extra/modules/root.ptl +++ b/extra/modules/root.ptl @@ -1,6 +1,7 @@ from qommon import get_cfg, get_logger -from quixote import redirect +from quixote import redirect, get_session from authentic.form import * +from quixote.html import htmltext import qommon.errors as errors import qommon.template as template import authentic.identities as identities @@ -10,6 +11,8 @@ import authentic.admin.configuration as configuration import urllib2 import captcha from callback import BatchJob, XmlRpcAction +import lasso +import authentic.misc as misc schema = (('PART_EMP', _('Particulier-employeur')), (_('Salarie du Particulier-employeur'), @@ -50,17 +53,34 @@ def check_classification(classification): class IfefRootDirectory(authentic.root.RootDirectory): _q_exports = authentic.root.RootDirectory._q_exports + [ 'register2' ] + def _q_traverse(self, path): + request = get_request() + if request.form and request.form.get('service'): + service = request.form['service'] + get_session().service = service + request.service = service + return super(IfefRootDirectory, self)._q_traverse(path) + def register2 (self): return self.register(version=2) def register (self, version=1): identities_cfg = get_cfg('identities', {}) + session = get_session() if not identities_cfg.get('creation') in ('self', 'moderated'): raise errors.TraversalError() form = Form(enctype="multipart/form-data") - for field in identities.get_store_class().fields: + fields = identities.get_store_class().fields + keys = [] + if getattr(session, 'service', None): + keys = get_cfg('providers',{}).get(session.service, {}) \ + .get('registration_fields') + if keys: + fields = [ field for field in fields \ + if field.key in keys ] + for field in fields: if getattr(field, str('on_register'), True): field.add_to_form(form) and None @@ -79,51 +99,58 @@ vous connecter au portail de l'IFEF. Il peut contenir seulement des lettres et d else: form.add(HtmlWidget, htmltext('

%s

') % _('A password will be mailed to you.')) - classification = get_request().form.get('classification') - if classification: - if not check_classification(classification): - classification = None - if version == 1: - s='' % _('Vous etes') + for q in schema: + if isinstance(q[1], tuple): + s += '' % q[0] + for r in q[1:]: + code, text = r + if code == classification: + selected = 'selected="1"' + else: + selected = '' + s += '\n' % (selected, code, text) + s += '\n' + + else: + code, text = q if code == classification: selected = 'selected="1"' else: selected = '' s += '\n' % (selected, code, text) - s += '\n' + s += '' + else: + s='' % _('Vous etes') + for i, q in enumerate(schema): + if isinstance(q, tuple): + s += '

%s' % q[0] + for j, q in enumerate(q[1:]): + s += '%s' % (i, j, i, j, q) + s += '

\n' - else: - code, text = q - if code == classification: - selected = 'selected="1"' else: - selected = '' - s += '\n' % (selected, code, text) - s += '' - else: - s='' % _('Vous etes') - for i, q in enumerate(schema): - if isinstance(q, tuple): - s += '

%s' % q[0] - for j, q in enumerate(q[1:]): - s += '%s' % (i, j, i, j, q) - s += '

\n' + s += '

%s

' % (i, i, q) + s+='
' - else: - s += '

%s

' % (i, i, q) - s+='
' - - if get_request().get_method() == 'POST' and not classification: + if add_classification and get_request().get_method() == 'POST' \ + and not classification: form.set_error('username', ' ') form.add(HtmlWidget, 'erreur', htmltext('
%s
') % _('Vous devez choisir une classification')) elif get_request().get_method() == 'GET': get_request().form = {} - form.add(HtmlWidget, 'classification', htmltext(s)) + if add_classification: + form.add(HtmlWidget, 'classification', htmltext(s)) # domain name: fepem re_captcha_public_key = '6LcIULoSAAAAAIbUohbBeHCcUeWAt74sjvjK6w5W' re_captcha_private_key = '6LcIULoSAAAAADfaFk2E9x9G2FgpSsnNIfUV1rlS' @@ -198,5 +225,29 @@ RecaptchaOptions = { "theme" : "white", "lang" : "fr" }; get_response().add_after_job('''Send registration to Neogia, email = %r,\ classification = %r''' % (email, classification), BatchJob(action)) + def get_idp_sso_list [html] (self): + if not get_cfg('providers', {}).items(): + return '' + + '' + from qommon.publisher import get_publisher_class get_publisher_class().root_directory_class = IfefRootDirectory diff --git a/po/fr.po b/po/fr.po index f6a8aab..1043eb0 100644 --- a/po/fr.po +++ b/po/fr.po @@ -13,10 +13,34 @@ msgstr "" "Content-Transfer-Encoding: 8bit\n" "Plural-Forms: nplurals=2; plural=n>1;\n" -#: ../extra/ifef.py:13 ../extra/modules/afterjobs.ptl:32 +#: ../extra/ifef.py:15 ../extra/modules/afterjobs.ptl:32 msgid "Neogia registration jobs" msgstr "Appel d'enregistrement à Neogia" +#: ../extra/modules/admin_settings.py:15 +msgid "Customized stylesheet URL" +msgstr "" + +#: ../extra/modules/admin_settings.py:17 +msgid "The URL must be https if authentic also use https" +msgstr "" + +#: ../extra/modules/admin_settings.py:19 +msgid "Prefix URL of the HTTP_REFERER" +msgstr "" + +#: ../extra/modules/admin_settings.py:21 +msgid "Used to find which service initiated a request to Authentic" +msgstr "" + +#: ../extra/modules/admin_settings.py:24 +msgid "Custom theme" +msgstr "" + +#: ../extra/modules/admin_settings.py:26 +msgid "Theme to use when an interaction is initated by this service" +msgstr "" + #: ../extra/modules/configuration.py:6 msgid "XMLRPC Neogia registration URL" msgstr "" @@ -29,67 +53,67 @@ msgstr "" msgid "Condition d'utilisation" msgstr "Conditions d'utilisation" -#: ../extra/modules/root.ptl:14 +#: ../extra/modules/root.ptl:17 msgid "Particulier-employeur" msgstr "" -#: ../extra/modules/root.ptl:15 +#: ../extra/modules/root.ptl:18 msgid "Salarie du Particulier-employeur" msgstr "Salarié du Particulier-employeur" -#: ../extra/modules/root.ptl:16 ../extra/modules/root.ptl:19 +#: ../extra/modules/root.ptl:19 ../extra/modules/root.ptl:22 msgid "inscrit" msgstr "" -#: ../extra/modules/root.ptl:17 ../extra/modules/root.ptl:20 +#: ../extra/modules/root.ptl:20 ../extra/modules/root.ptl:23 msgid "pas inscrit en formation" msgstr "" -#: ../extra/modules/root.ptl:18 +#: ../extra/modules/root.ptl:21 msgid "Assistante(e) maternel(le)" msgstr "" -#: ../extra/modules/root.ptl:21 +#: ../extra/modules/root.ptl:24 msgid "Formateur ou directeur d'un organisme de formation" msgstr "" -#: ../extra/modules/root.ptl:22 +#: ../extra/modules/root.ptl:25 msgid "labellise par l'Institut-Fepem" msgstr "labellisé par l'Institut-Fepem" -#: ../extra/modules/root.ptl:23 +#: ../extra/modules/root.ptl:26 msgid "souhaitant etre labellise" msgstr "souhaitant être labellisé" -#: ../extra/modules/root.ptl:24 +#: ../extra/modules/root.ptl:27 msgid "pas encore labellise" msgstr "pas encore labéllisé" -#: ../extra/modules/root.ptl:25 +#: ../extra/modules/root.ptl:28 msgid "Formateur consultant souhaitant entrer dans la communaute" msgstr "Formateur consultant souhaitant entrer dans la communauté" -#: ../extra/modules/root.ptl:26 +#: ../extra/modules/root.ptl:29 msgid "Salarie d'un organisme public, d'une association ou d'une organisation" msgstr "" -#: ../extra/modules/root.ptl:27 +#: ../extra/modules/root.ptl:30 msgid "partenaire de l'Institut-Fepem" msgstr "" -#: ../extra/modules/root.ptl:28 +#: ../extra/modules/root.ptl:31 msgid "souhaitant devenir partenaire" msgstr "" -#: ../extra/modules/root.ptl:29 +#: ../extra/modules/root.ptl:32 msgid "pas encore partenaire" msgstr "" -#: ../extra/modules/root.ptl:30 +#: ../extra/modules/root.ptl:33 msgid "Un professionnel de la formation" msgstr "" -#: ../extra/modules/root.ptl:31 +#: ../extra/modules/root.ptl:34 msgid "" "Une personne interessee par le sujet de la professionnalisation de l'emploi " "familial" @@ -97,11 +121,11 @@ msgstr "" "Une personne interessée par le sujet de la professionnalisation de l'emploi " "familial" -#: ../extra/modules/root.ptl:69 +#: ../extra/modules/root.ptl:72 msgid "Username" msgstr "Identifiant" -#: ../extra/modules/root.ptl:71 +#: ../extra/modules/root.ptl:72 msgid "" "C'est cet identifiant qui vous permettra de vous connecter au portail de " "l'IFEF. Il peut contenir seulement des lettres et des chiffres." @@ -136,9 +160,45 @@ msgid "Cancel" msgstr "Annuler" #: ../extra/modules/root.ptl:180 ../extra/modules/root.ptl:181 +======= +#: ../extra/modules/root.ptl:76 +msgid "Password" +msgstr "Mot de passe" + +#: ../extra/modules/root.ptl:78 +msgid "A password will be mailed to you." +msgstr "Un mot de passe vous sera envoyé par courriel." + +#: ../extra/modules/root.ptl:85 ../extra/modules/root.ptl:107 +msgid "Vous etes" +msgstr "Vous êtes" + +#: ../extra/modules/root.ptl:121 +msgid "Vous devez choisir une classification" +msgstr "" + +#: ../extra/modules/root.ptl:148 +msgid "J'accepte les conditions d'utilisation" +msgstr "" + +#: ../extra/modules/root.ptl:157 +msgid "Submit" +msgstr "Valider" + +#: ../extra/modules/root.ptl:158 +msgid "Cancel" +msgstr "Annuler" + +#: ../extra/modules/root.ptl:178 ../extra/modules/root.ptl:179 +>>>>>>> Update translation:po/fr.po msgid "Registration" msgstr "Inscription" +#: ../extra/modules/root.ptl:219 +#, python-format +msgid "Log on %s" +msgstr "" + #: ../extra/modules/afterjobs.ptl:38 #, python-format msgid "Run job %s" @@ -296,11 +356,11 @@ msgstr "" #: ../extra/modules/store.py:71 msgid "votre page web personnelle" -msgstr "" +msgstr "Votre page web personelle" #: ../extra/modules/store.py:72 msgid "Adresse telephonie IP" -msgstr "" +msgstr "Addresse de téléphonie par internet" #: ../extra/modules/store.py:73 msgid "exemple: skype, sip, gtalk" diff --git a/po/ifef.pot b/po/ifef.pot index fde31d0..2e489a4 100644 --- a/po/ifef.pot +++ b/po/ifef.pot @@ -16,10 +16,34 @@ msgstr "" "Content-Type: text/plain; charset=CHARSET\n" "Content-Transfer-Encoding: 8bit\n" -#: ../extra/ifef.py:13 ../extra/modules/afterjobs.ptl:32 +#: ../extra/ifef.py:15 ../extra/modules/afterjobs.ptl:32 msgid "Neogia registration jobs" msgstr "" +#: ../extra/modules/admin_settings.py:15 +msgid "Customized stylesheet URL" +msgstr "" + +#: ../extra/modules/admin_settings.py:17 +msgid "The URL must be https if authentic also use https" +msgstr "" + +#: ../extra/modules/admin_settings.py:19 +msgid "Prefix URL of the HTTP_REFERER" +msgstr "" + +#: ../extra/modules/admin_settings.py:21 +msgid "Used to find which service initiated a request to Authentic" +msgstr "" + +#: ../extra/modules/admin_settings.py:24 +msgid "Custom theme" +msgstr "" + +#: ../extra/modules/admin_settings.py:26 +msgid "Theme to use when an interaction is initated by this service" +msgstr "" + #: ../extra/modules/configuration.py:6 msgid "XMLRPC Neogia registration URL" msgstr "" @@ -32,77 +56,77 @@ msgstr "" msgid "Condition d'utilisation" msgstr "" -#: ../extra/modules/root.ptl:14 +#: ../extra/modules/root.ptl:17 msgid "Particulier-employeur" msgstr "" -#: ../extra/modules/root.ptl:15 +#: ../extra/modules/root.ptl:18 msgid "Salarie du Particulier-employeur" msgstr "" -#: ../extra/modules/root.ptl:16 ../extra/modules/root.ptl:19 +#: ../extra/modules/root.ptl:19 ../extra/modules/root.ptl:22 msgid "inscrit" msgstr "" -#: ../extra/modules/root.ptl:17 ../extra/modules/root.ptl:20 +#: ../extra/modules/root.ptl:20 ../extra/modules/root.ptl:23 msgid "pas inscrit en formation" msgstr "" -#: ../extra/modules/root.ptl:18 +#: ../extra/modules/root.ptl:21 msgid "Assistante(e) maternel(le)" msgstr "" -#: ../extra/modules/root.ptl:21 +#: ../extra/modules/root.ptl:24 msgid "Formateur ou directeur d'un organisme de formation" msgstr "" -#: ../extra/modules/root.ptl:22 +#: ../extra/modules/root.ptl:25 msgid "labellise par l'Institut-Fepem" msgstr "" -#: ../extra/modules/root.ptl:23 +#: ../extra/modules/root.ptl:26 msgid "souhaitant etre labellise" msgstr "" -#: ../extra/modules/root.ptl:24 +#: ../extra/modules/root.ptl:27 msgid "pas encore labellise" msgstr "" -#: ../extra/modules/root.ptl:25 +#: ../extra/modules/root.ptl:28 msgid "Formateur consultant souhaitant entrer dans la communaute" msgstr "" -#: ../extra/modules/root.ptl:26 +#: ../extra/modules/root.ptl:29 msgid "Salarie d'un organisme public, d'une association ou d'une organisation" msgstr "" -#: ../extra/modules/root.ptl:27 +#: ../extra/modules/root.ptl:30 msgid "partenaire de l'Institut-Fepem" msgstr "" -#: ../extra/modules/root.ptl:28 +#: ../extra/modules/root.ptl:31 msgid "souhaitant devenir partenaire" msgstr "" -#: ../extra/modules/root.ptl:29 +#: ../extra/modules/root.ptl:32 msgid "pas encore partenaire" msgstr "" -#: ../extra/modules/root.ptl:30 +#: ../extra/modules/root.ptl:33 msgid "Un professionnel de la formation" msgstr "" -#: ../extra/modules/root.ptl:31 +#: ../extra/modules/root.ptl:34 msgid "" "Une personne interessee par le sujet de la professionnalisation de l'emploi " "familial" msgstr "" -#: ../extra/modules/root.ptl:69 +#: ../extra/modules/root.ptl:72 msgid "Username" msgstr "" -#: ../extra/modules/root.ptl:71 +#: ../extra/modules/root.ptl:72 msgid "" "C'est cet identifiant qui vous permettra de vous connecter au portail de " "l'IFEF. Il peut contenir seulement des lettres et des chiffres." @@ -137,9 +161,45 @@ msgid "Cancel" msgstr "" #: ../extra/modules/root.ptl:180 ../extra/modules/root.ptl:181 +======= +#: ../extra/modules/root.ptl:76 +msgid "Password" +msgstr "" + +#: ../extra/modules/root.ptl:78 +msgid "A password will be mailed to you." +msgstr "" + +#: ../extra/modules/root.ptl:85 ../extra/modules/root.ptl:107 +msgid "Vous etes" +msgstr "" + +#: ../extra/modules/root.ptl:121 +msgid "Vous devez choisir une classification" +msgstr "" + +#: ../extra/modules/root.ptl:148 +msgid "J'accepte les conditions d'utilisation" +msgstr "" + +#: ../extra/modules/root.ptl:157 +msgid "Submit" +msgstr "" + +#: ../extra/modules/root.ptl:158 +msgid "Cancel" +msgstr "" + +#: ../extra/modules/root.ptl:178 ../extra/modules/root.ptl:179 +>>>>>>> Update translation:po/ifef.pot msgid "Registration" msgstr "" +#: ../extra/modules/root.ptl:219 +#, python-format +msgid "Log on %s" +msgstr "" + #: ../extra/modules/afterjobs.ptl:38 #, python-format msgid "Run job %s"