예제 #1
0
    def _associate_account(self, request, form, accountname, msg=None):
        _ = request.getText

        form.append(html.INPUT(type='hidden', name='oidstage', value='3'))
        table = html.TABLE(border='0')
        form.append(table)
        td = html.TD(colspan=2)
        td.append(
            html.Raw(
                _("""The username you have chosen is already
taken. If it is your username, enter your password below to associate
the username with your OpenID. Otherwise, please choose a different
username and leave the password field blank.""")))
        table.append(html.TR().append(td))
        if msg:
            td.append(html.P().append(html.STRONG().append(html.Raw(msg))))
        td1 = html.TD()
        td1.append(html.STRONG().append(html.Raw(_('Name'))))
        td2 = html.TD()
        td2.append(html.INPUT(type='text', name='username', value=accountname))
        table.append(html.TR().append(td1).append(td2))
        td1 = html.TD()
        td1.append(html.STRONG().append(html.Raw(_('Password'))))
        td2 = html.TD()
        td2.append(html.INPUT(type='password', name='password'))
        table.append(html.TR().append(td1).append(td2))
        td1 = html.TD()
        td2 = html.TD()
        td2.append(
            html.INPUT(type='submit',
                       name='submit',
                       value=_('Associate this name')))
        table.append(html.TR().append(td1).append(td2))
예제 #2
0
    def _get_account_name(self, request, form, msg=None):
        # now we need to ask the user for a new username
        # that they want to use on this wiki
        # XXX: request nickname from OP and suggest using it
        # (if it isn't in use yet)
        logging.debug("running _get_account_name")
        _ = request.getText
        form.append(html.INPUT(type='hidden', name='oidstage', value='2'))
        table = html.TABLE(border='0')
        form.append(table)
        td = html.TD(colspan=2)
        td.append(
            html.Raw(
                _("""Please choose an account name now.
If you choose an existing account name you will be asked for the
password and be able to associate the account with your OpenID.""")))
        table.append(html.TR().append(td))
        if msg:
            td = html.TD(colspan='2')
            td.append(html.P().append(html.STRONG().append(html.Raw(msg))))
            table.append(html.TR().append(td))
        td1 = html.TD()
        td1.append(html.STRONG().append(html.Raw(_('Name'))))
        td2 = html.TD()
        td2.append(html.INPUT(type='text', name='username'))
        table.append(html.TR().append(td1).append(td2))
        td1 = html.TD()
        td2 = html.TD()
        td2.append(
            html.INPUT(type='submit',
                       name='submit',
                       value=_('Choose this name')))
        table.append(html.TR().append(td1).append(td2))
예제 #3
0
def _create_form(request):
    _ = request.getText
    url = request.page.url(request)
    ret = html.FORM(action=url)
    ret.append(html.INPUT(type='hidden', name='action', value='recoverpass'))
    lang_attr = request.theme.ui_lang_attr()
    ret.append(html.Raw('<div class="userpref"%s>' % lang_attr))
    tbl = html.TABLE(border="0")
    ret.append(tbl)
    ret.append(html.Raw('</div>'))

    row = html.TR()
    tbl.append(row)
    row.append(html.TD().append(html.STRONG().append(html.Text(
        _("Username")))))
    row.append(html.TD().append(html.INPUT(type="text", size="36",
                                           name="name")))

    row = html.TR()
    tbl.append(row)
    row.append(html.TD().append(html.STRONG().append(html.Text(_("Email")))))
    row.append(html.TD().append(
        html.INPUT(type="text", size="36", name="email")))

    row = html.TR()
    tbl.append(row)
    row.append(html.TD())
    td = html.TD()
    row.append(td)
    td.append(
        html.INPUT(type="submit",
                   name="account_sendmail",
                   value=_('Mail me my account data')))

    return unicode(ret)
예제 #4
0
def _create_form(request):
    _ = request.getText
    url = request.page.url(request)
    ret = html.FORM(action=url)
    ret.append(
        html.INPUT(type='hidden', name='action', value='CreateNewAccount'))
    lang_attr = request.theme.ui_lang_attr()
    ret.append(html.Raw('<div class="userpref"%s>' % lang_attr))
    tbl = html.TABLE(border="0")
    ret.append(tbl)
    ret.append(html.Raw('</div>'))

    row = html.TR()
    tbl.append(row)
    row.append(html.TD().append(html.STRONG().append(html.Text(_("Name")))))
    cell = html.TD()
    row.append(cell)
    cell.append(html.INPUT(type="text", size="36", name="name"))
    cell.append(html.Text(' ' + _("(Use FirstnameLastname)")))

    row = html.TR()
    tbl.append(row)
    row.append(html.TD().append(html.STRONG().append(html.Text(
        _("Password")))))
    row.append(html.TD().append(
        html.INPUT(type="password", size="36", name="password1")))

    row = html.TR()
    tbl.append(row)
    row.append(html.TD().append(html.STRONG().append(
        html.Text(_("Password repeat")))))
    row.append(html.TD().append(
        html.INPUT(type="password", size="36", name="password2")))

    row = html.TR()
    tbl.append(row)
    row.append(html.TD().append(html.STRONG().append(html.Text(_("Email")))))
    row.append(html.TD().append(
        html.INPUT(type="text", size="36", name="email")))

    textcha = TextCha(request)
    if textcha.is_enabled():
        row = html.TR()
        tbl.append(row)
        row.append(html.TD().append(html.STRONG().append(
            html.Text(_('TextCha (required)')))))
        td = html.TD()
        if textcha:
            td.append(textcha.render())
        row.append(td)

    row = html.TR()
    tbl.append(row)
    row.append(html.TD())
    td = html.TD()
    row.append(td)
    td.append(
        html.INPUT(type="submit", name="create", value=_('Create Profile')))

    return unicode(ret)
예제 #5
0
    def make_form(self, explanation=None):
        '''
            To have a consistent UI, use this method for most
            preferences forms and then call make_row(). See
            existing plugins, e.g. changepass.py.
        '''
        action = self.request.page.url(self.request)
        _form = html.FORM(action=action)
        _form.append(html.INPUT(type="hidden", name="action", value="userprefs"))
        _form.append(html.INPUT(type="hidden", name="handler", value=self.name))

        self._table = html.TABLE(border="0")

        # Use the user interface language and direction
        lang_attr = self.request.theme.ui_lang_attr()
        _form.append(html.Raw('<div class="userpref"%s>' % lang_attr))
        para = html.P()
        _form.append(para)
        if explanation:
            para.append(explanation)

        para.append(self._table)
        _form.append(html.Raw("</div>"))

        return _form
예제 #6
0
def _create_token_form(request, name=None, token=None):
    _ = request.getText
    url = request.page.url(request)
    ret = html.FORM(action=url)
    ret.append(html.INPUT(type='hidden', name='action', value='recoverpass'))
    lang_attr = request.theme.ui_lang_attr()
    ret.append(html.Raw('<div class="userpref"%s>' % lang_attr))
    tbl = html.TABLE(border="0")
    ret.append(tbl)
    ret.append(html.Raw('</div>'))

    row = html.TR()
    tbl.append(row)
    row.append(html.TD().append(html.STRONG().append(
        html.Text(_("Recovery token")))))
    value = token or ''
    row.append(html.TD().append(
        html.INPUT(type='text', size="36", name="token", value=value)))

    row = html.TR()
    tbl.append(row)
    row.append(html.TD().append(html.STRONG().append(html.Text(
        _("Username")))))
    value = name or ''
    row.append(html.TD().append(
        html.INPUT(type='text', size="36", name="name", value=value)))

    row = html.TR()
    tbl.append(row)
    row.append(html.TD().append(html.STRONG().append(
        html.Text(_("New password")))))
    row.append(html.TD().append(
        html.INPUT(type="password", size="36", name="password")))

    row = html.TR()
    tbl.append(row)
    row.append(html.TD().append(html.STRONG().append(
        html.Text(_("New password (repeat)")))))
    row.append(html.TD().append(
        html.INPUT(type="password", size="36", name="password_repeat")))

    row = html.TR()
    tbl.append(row)
    row.append(html.TD())
    td = html.TD()
    row.append(td)
    td.append(
        html.INPUT(type="submit", name="recover",
                   value=_('Reset my password')))

    return unicode(ret)
예제 #7
0
    def _event_select(self):
        """ Create event subscription list. """
        _ = self._

        types = []
        if self.cfg.mail_enabled and self.request.user.email:
            types.append(('email', _("'''Email'''", wiki=True)))
        if self.cfg.jabber_enabled and self.request.user.jid:
            types.append(('jabber', _("'''Jabber'''", wiki=True)))

        table = html.TABLE()
        header = html.TR()
        table.append(header)
        for name, descr in types:
            header.append(html.TH().append(html.Raw(descr)))
        header.append(
            html.TH(align='left').append(
                html.Raw(_("'''Event type'''", wiki=True))))

        event_list = events.get_subscribable_events()
        super = self.request.user.isSuperUser()

        # Create a list of (value, name) tuples for display as radiobuttons
        # Only include super-user visible events if current user has these rights.
        # It's cosmetic - the check for super-user rights should be performed
        # in event handling code as well!
        allowed = []
        for key in event_list.keys():
            if not event_list[key]['superuser'] or super:
                allowed.append((key, event_list[key]['desc']))

        for evname, evdescr in allowed:
            tr = html.TR()
            table.append(tr)
            for notiftype, notifdescr in types:
                checked = evname in getattr(self.request.user,
                                            '%s_subscribed_events' % notiftype)
                tr.append(html.TD().append(
                    html.INPUT(type='checkbox',
                               checked=checked,
                               name='subscribe:%s:%s' % (notiftype, evname))))
            tr.append(html.TD().append(html.Raw(
                self.request.getText(evdescr))))

        return table
예제 #8
0
    def create_form(self):
        """ Create the complete HTML form code. """
        _ = self._

        ret = html.P()
        # Use the user interface language and direction
        lang_attr = self.request.theme.ui_lang_attr()
        ret.append(html.Raw('<div %s>' % lang_attr))
        self._table = html.TABLE(border="0")
        ret.append(self._table)
        ret.append(html.Raw("</div>"))

        request = self.request

        if hasattr(request.user, 'openid_trusted_roots') and request.user.openid_trusted_roots:
            self._trust_root_list()

        form = self._make_form()
        label = _("Cancel")
        form.append(html.INPUT(type="submit", name='cancel', value=label))
        self._make_row('', [form])
        return unicode(ret)
예제 #9
0
    def create_form(self):
        """ Create the complete HTML form code. """
        _ = self._

        ret = html.P()
        # Use the user interface language and direction
        lang_attr = self.request.theme.ui_lang_attr()
        ret.append(html.Raw('<div %s>' % lang_attr))
        self._table = html.TABLE(border="0")
        ret.append(self._table)
        ret.append(html.Raw("</div>"))

        request = self.request

        if 'openid.prefs.form_html' in request.session:
            txt = _('OpenID verification requires that you click this button:')
            # create JS to automatically submit the form if possible
            submitjs = """<script type="text/javascript">
<!--//
document.getElementById("openid_message").submit();
//-->
</script>
"""
            oidhtml = request.session['openid.prefs.form_html']
            del request.session['openid.prefs.form_html']
            return ''.join([txt, oidhtml, submitjs])

        if hasattr(request.user, 'openids') and request.user.openids:
            self._oidlist()
        self._addoidform()

        form = self._make_form()
        label = _("Cancel")
        form.append(html.INPUT(type="submit", name='cancel', value=label))
        self._make_row('', [form])
        return unicode(ret)
예제 #10
0
    def create_form(self):
        """ Create the complete HTML form code. """
        _ = self._
        self._form = self.make_form(
            _('Select the events you want to be notified about.'))

        self._form.append(
            html.INPUT(type="hidden", name="action", value="userprefs"))
        self._form.append(
            html.INPUT(type="hidden", name="handler", value="prefs"))

        ticket = wikiutil.createTicket(self.request)
        self._form.append(
            html.INPUT(type="hidden", name="ticket", value="%s" % ticket))

        if (not (self.cfg.mail_enabled and self.request.user.email)
                and not (self.cfg.jabber_enabled and self.request.user.jid)):
            self.make_row('', [
                html.Text(
                    _("Before you can be notified, you need to provide a way"
                      " to contact you in the general preferences."))
            ])
            self.make_row(
                '',
                [html.INPUT(type="submit", name="cancel", value=_("Cancel"))])
            return unicode(self._form)

        self.make_row(_('Subscribed events'), [self._event_select()])

        # Get list of subscribe pages, DO NOT sort! it should
        # stay in the order the user entered it in his input
        # box.
        notifylist = self.request.user.getSubscriptionList()

        self.make_row(html.Raw(
            _('Subscribed wiki pages<<BR>>(one regex per line)', wiki=True)), [
                html.TEXTAREA(name="subscribed_pages", rows="6",
                              cols="50").append('\n'.join(notifylist)),
            ],
                      valign="top")

        # Add buttons
        self.make_row('', [
            html.INPUT(type="submit", name="save", value=_("Save")), ' ',
            html.INPUT(type="submit", name="cancel", value=_("Cancel"))
        ])

        return unicode(self._form)
예제 #11
0
    def testCreate(self):
        """widget.html: creating html widgets

        TO DO: add tests for all elements by HTML 4 spec.
        """
        tests = (
            # description, call, expected
            ('Create text', html.Text('<br> &'), '&lt;br&gt; &amp;'),
            ('Create raw html', html.Raw('<br> &amp;'), '<br> &amp;'),
            ('Create br', html.BR(), '<br>'),
            ('Create hr', html.HR(), '<hr>'),
            ('Create p', html.P(), '<p></p>'),
        )

        for description, obj, expected in tests:
            result = unicode(obj)
            assert result == expected
예제 #12
0
    def asHTML(self):
        """ Create the complete HTML form code. """
        _ = self._
        request = self.request
        action = "%s%s" % (request.script_root, request.path)
        hints = []
        for authm in request.cfg.auth:
            hint = authm.login_hint(request)
            if hint:
                hints.append(hint)
        self._form = html.FORM(action=action, name="loginform", id="loginform")
        self._table = html.TABLE(border="0")

        # Use the user interface language and direction
        lang_attr = request.theme.ui_lang_attr()
        self._form.append(html.Raw('<div class="userpref"%s>' % lang_attr))

        self._form.append(
            html.INPUT(type="hidden", name="action", value="login"))
        self._form.append(self._table)
        for hint in hints:
            self._form.append(html.P().append(html.Raw(hint)))
        self._form.append(html.Raw("</div>"))

        cfg = request.cfg
        if 'username' in cfg.auth_login_inputs:
            self.make_row(_('Name'), [
                html.INPUT(
                    type="text",
                    size="32",
                    name="name",
                ),
            ])

        if 'password' in cfg.auth_login_inputs:
            self.make_row(_('Password'), [
                html.INPUT(
                    type="password",
                    size="32",
                    name="password",
                ),
            ])

        # Restrict type of input available for OpenID input
        # based on wiki configuration.
        if 'openid_identifier' in cfg.auth_login_inputs:
            if len(cfg.openidrp_allowed_op) == 1:
                self.make_row(_('OpenID'), [
                    html.INPUT(type="hidden",
                               name="openid_identifier",
                               value=cfg.openidrp_allowed_op[0]),
                ])
            elif len(cfg.openidrp_allowed_op) > 1:
                op_select = html.SELECT(name="openid_identifier",
                                        id="openididentifier")
                for op_uri in cfg.openidrp_allowed_op:
                    op_select.append(
                        html.OPTION(value=op_uri).append(html.Raw(op_uri)))

                self.make_row(_('OpenID'), [
                    op_select,
                ])
            else:
                self.make_row(_('OpenID'), [
                    html.INPUT(type="text",
                               size="32",
                               name="openid_identifier",
                               id="openididentifier"),
                ])

        # Need both hidden field and submit values for auto-submit to work
        self.make_row('', [
            html.INPUT(type="hidden", name="login", value=_('Login')),
            html.INPUT(type="submit", name='login', value=_('Login')),
        ])

        # Automatically submit the form if only a single OpenID Provider is allowed
        if 'openid_identifier' in cfg.auth_login_inputs and len(
                cfg.openidrp_allowed_op) == 1:
            self._form.append("""<script type="text/javascript">
<!--//
document.getElementById("loginform").submit();
//-->
</script>
""")

        return unicode(self._form)