def render_registration_fields(self, req, data):
        """Add a hidden text input field to the registration form, and
        a visible one with mandatory input as well, if token is configured.
        """
        if self.reg_basic_token:
            # Preserve last input for editing on failure instead of typing
            # everything again.
            old_value = req.args.get('basic_token', '')

            if self.reg_basic_question:
                # TRANSLATOR: Question-style hint for visible bot trap
                # registration input field.
                hint = tag.p(_("Please answer above: %(question)s",
                               question=self.reg_basic_question),
                             class_='hint')
            else:
                # TRANSLATOR: Verbatim token hint for visible bot trap
                # registration input field.
                hint = tag.p(tag_(
                    "Please type [%(token)s] as verification token, "
                    "exactly replicating everything within the braces.",
                    token=tag.b(self.reg_basic_token)), class_='hint')
            insert = tag(
                tag.label(_("Parole:"),
                          tag.input(type='text', name='basic_token', size=20,
                                    class_='textwidget', value=old_value)),
                hint)
        else:
            insert = None
        # TRANSLATOR: Registration form hint for hidden bot trap input field.
        insert = tag(insert,
                     tag.input(type='hidden', name='sentinel',
                               title=_("Better do not fill this field.")))
        return insert, data
 def render_registration_fields(self, req, data):
     """Add an email address text input field to the registration form."""
     # Preserve last input for editing on failure instead of typing
     # everything again.
     old_value = req.args.get('email', '').strip()
     insert = tag.label(_("Email:"),
                        tag.input(type='text', name='email', size=20,
                                  class_='textwidget', value=old_value))
     # Deferred import required to aviod circular import dependencies.
     from acct_mgr.web_ui import AccountModule
     reset_password = AccountModule(self.env).reset_password_enabled
     verify_account = self.env.is_enabled(EmailVerificationModule) and \
                      EmailVerificationModule(self.env).verify_email
     if verify_account:
         # TRANSLATOR: Registration form hints for a mandatory input field.
         hint = tag.p(_("""
             The email address is required for Trac to send you a
             verification token.
             """), class_='hint')
         if reset_password:
             hint = tag(hint, tag.p(_("""
                 Entering your email address will also enable you to reset
                 your password if you ever forget it.
                 """), class_='hint'))
         return tag(insert, hint), data
     elif reset_password:
         # TRANSLATOR: Registration form hint, if email input is optional.
         hint = tag.p(_("""Entering your email address will enable you to
                        reset your password if you ever forget it."""),
                      class_='hint')
         return dict(optional=tag(insert, hint)), data
     else:
         # Always return the email text input itself as optional field.
         return dict(optional=insert), data
Example #3
0
 def filter_stream(self, req, method, filename, stream, data):
     if filename == 'wiki_edit.html' and 'section' in req.args and 'merge' not in req.args:
         if 'section_text' in req.args:
             section_pre, section_text, section_post = req.args.get('section_pre'), req.args.get('section_text'), req.args.get('section_post')
         else:
             section_pre, section_text, section_post = self._split_page_text(data['page'].text, req.args['section'])
             section_text = ''.join(section_text)
         
         section_element = html.input(type='hidden', name='section', id='section', value=req.args.get('section'))
         pre_element = html.input(type='hidden', name='section_pre', id='section_pre', value=''.join(section_pre))
         post_element = html.input(type='hidden', name='section_post', id='section_post', value=''.join(section_post))
         
         section_html = html(section_element, pre_element, post_element)
         stream = stream | Transformer('//textarea[@name="text"]').empty().append(section_text).before(section_html)
         stream = stream | Transformer('//div[@id="content"]//h1').append("/%s (section %s)"%(section_text[:section_text.find('\n')].strip(" = \r\n"), req.args['section']))
         if not self.preview_whole_page:
            stream = stream | Transformer('//div[@class="wikipage"]').empty().append(HTML(wiki_to_html(section_text, self.env, req)))
     return stream
 def render_ticket_action_control(self, req, ticket, action):
     """Returns the action control"""
     id = 'action_%s_xref' % action
     ticketnum = req.args.get(id, '')
     actions = self.get_configurable_workflow().actions
     label = actions[action]['name']
     hint = actions[action].get('xref_hint') or \
            _("The specified ticket will be cross-referenced with this "
              "ticket.")
     control = html.input(type='text', id=id, name=id, value=ticketnum)
     return label, control, hint
    def filter_stream(self, req, method, filename, stream, data):
        if req.path_info.startswith('/register') and (
            req.method == 'GET' or
            'registration_error' in data or
                'captcha_error' in req.session):
            if not (self.private_key or self.private_key):
                return stream
            captcha_opts = tag.script("""\
var RecaptchaOptions = {
  theme: "%s",
  lang: "%s"
}""" % (self.theme, self.lang), type='text/javascript')
            captcha_js = captcha.displayhtml(
                self.public_key, use_ssl=req.scheme == 'https',
                error='reCAPTCHA incorrect. Please try again.',
                version=2
            ) + captcha.load_script(version=2)
            # First Fieldset of the registration form XPath match
            xpath_match = '//form[@id="acctmgr_registerform"]/fieldset[1]'
            return stream | Transformer(xpath_match). \
                append(captcha_opts + tag(Markup(captcha_js)))
        # Admin Configuration
        elif req.path_info.startswith('/admin/accounts/config'):
            api_html = tag.div(
                tag.label("Public Key:", for_="recaptcha_public_key") +
                tag.input(class_="textwidget", name="recaptcha_public_key",
                          value=self.public_key, size=40)
            ) + tag.div(
                tag.label("Private Key:", for_="recaptcha_private_key") +
                tag.input(class_="textwidget", name="recaptcha_private_key",
                          value=self.private_key, size=40)
            )
            if not (self.private_key or self.public_key):
                api_html = tag.div(
                    tag.a("Generate a reCAPTCHA API key for this Trac "
                          "instance domain.", target="_blank",
                          href="http://recaptcha.net/api/getkey?domain=%s&"
                          "app=TracRecaptchaRegister" %
                          req.environ.get('SERVER_NAME')
                          )
                ) + tag.br() + api_html

            theme_html = tag.div(
                tag.label("reCPATCHA theme:", for_='recaptcha_theme') +
                tag.select(
                    tag.option("Black Glass",
                               value="blackglass",
                               selected=self.theme == 'blackglass' or None) +
                    tag.option("Clean",
                               value="clean",
                               selected=self.theme == 'clean' or None) +
                    tag.option("Red",
                               value="red",
                               selected=self.theme == 'red' or None) +
                    tag.option("White",
                               value="white",
                               selected=self.theme == 'white' or None),
                    name='recaptcha_theme'
                )
            )

            language_html = tag.div(
                tag.label("reCAPTCHA language:", for_='recaptcha_lang') +
                tag.select(
                    tag.option("Dutch",
                               value="nl",
                               selected=self.lang == 'nl' or None) +
                    tag.option("English",
                               value="en",
                               selected=self.lang == 'en' or None) +
                    tag.option("French",
                               selected=self.lang == 'fr' or None) +
                    tag.option("German",
                               value="de",
                               selected=self.lang == 'de' or None) +
                    tag.option("Portuguese",
                               value="pt",
                               selected=self.lang == 'pt' or None) +
                    tag.option("Russian",
                               value="ru",
                               selected=self.lang == 'ru' or None) +
                    tag.option("Spanish",
                               value="es",
                               selected=self.lang == 'es' or None) +
                    tag.option("Turkish",
                               value="tr",
                               selected=self.lang == 'tr' or None),
                    name='recaptcha_lang'))

            # First fieldset of the Account Manager config form
            xpath_match = '//form[@id="cfg_wiz"]/fieldset[1]'

            return stream | Transformer(xpath_match). \
                before(tag.fieldset(tag.legend("reCAPTCHA") + api_html +
                                    tag.br() + theme_html + language_html))
        return stream
Example #6
0
                 if data.has_key('messages'):
                     um_data['messages'].extend(data.pop('messages'))
     
     # adding user list
     um_data.update(users = UserManager(self.env).get_active_users())
     
     # additional cells
     um_data.update(cells=list(self._get_cells(um_data['users'])))
     
     # adding usernamager's data to the data dict
     data.update(user_manager = um_data)
     
     # checking for external users
     trac_managed_users_out = self._do_import_current_users(req, dry_run=True)
     if len(trac_managed_users_out)>0:
         um_data['errors'].append(html.form(html.b(_("WARNING: ")),_(" [%s] users are not added to the team.")%(', '.join(trac_managed_users_out)),html.input(type="submit", name="um_import_current_users", value=_("Add Users")), action=req.href.admin('accounts/users'), method="post") )
     
     try:
         from acct_mgr.api import AccountManager
         data.update(account_manager = AccountManager(self.env))
     except Exception, e:
         data.update(account_manager = {'has_user':lambda x: False})
         self.log.error('Account manager not loaded')
     
     # adding stylesheets
     add_stylesheet(req, 'tracusermanager/css/admin_um.css')
     add_script(req, 'tracusermanager/js/admin_um.js')
     
     return 'admin_um.html', data    
 
 # Internal methods