예제 #1
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))
예제 #2
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)
예제 #3
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))
예제 #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='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)
예제 #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 show_decide_page(self, identity, username, openidreq):
        request = self.request
        _ = self._

        if not request.user.valid or username != request.user.name:
            request.makeForbidden(403, _('''You need to manually go to your OpenID provider wiki
and log in before you can use your OpenID. MoinMoin will
never allow you to enter your password here.

Once you have logged in, simply reload this page.'''))
            return

        request.theme.send_title(_("OpenID Trust verification"), pagename=request.page.page_name)
        # Start content (important for RTL support)
        request.write(request.formatter.startContent("content"))

        request.write(request.formatter.paragraph(1))
        request.write(_('The site %s has asked for your identity.') % openidreq.trust_root)
        request.write(request.formatter.paragraph(0))
        request.write(request.formatter.paragraph(1))
        request.write(_('''
If you approve, the site represented by the trust root below will be
told that you control the identity URL %s. (If you are using a delegated
identity, the site will take care of reversing the
delegation on its own.)''') % openidreq.identity)
        request.write(request.formatter.paragraph(0))

        form = html.FORM(method='POST', action=request.page.url(request))
        form.append(html.INPUT(type='hidden', name='action', value='serveopenid'))
        form.append(html.INPUT(type='hidden', name='openid.identity', value=openidreq.identity))
        form.append(html.INPUT(type='hidden', name='openid.return_to', value=openidreq.return_to))
        form.append(html.INPUT(type='hidden', name='openid.trust_root', value=openidreq.trust_root))
        form.append(html.INPUT(type='hidden', name='openid.mode', value=openidreq.mode))
        form.append(html.INPUT(type='hidden', name='name', value=username))

        nonce = randomString(32, 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789')
        form.append(html.INPUT(type='hidden', name='nonce', value=nonce))
        request.session['openidserver.nonce'] = nonce

        table = html.TABLE()
        form.append(table)

        tr = html.TR()
        table.append(tr)
        tr.append(html.TD().append(html.STRONG().append(html.Text(_('Trust root')))))
        tr.append(html.TD().append(html.Text(openidreq.trust_root)))

        tr = html.TR()
        table.append(tr)
        tr.append(html.TD().append(html.STRONG().append(html.Text(_('Identity URL')))))
        tr.append(html.TD().append(html.Text(identity)))

        tr = html.TR()
        table.append(tr)
        tr.append(html.TD().append(html.STRONG().append(html.Text(_('Name')))))
        tr.append(html.TD().append(html.Text(username)))

        tr = html.TR()
        table.append(tr)
        tr.append(html.TD().append(html.STRONG().append(html.Text(_('Remember decision')))))
        td = html.TD()
        tr.append(td)
        td.append(html.INPUT(type='checkbox', name='remember', value='yes'))
        td.append(html.Text(_('Remember this trust decision and don\'t ask again')))

        tr = html.TR()
        table.append(tr)
        tr.append(html.TD())
        td = html.TD()
        tr.append(td)

        td.append(html.INPUT(type='submit', name='approve', value=_("Approve")))
        td.append(html.INPUT(type='submit', name='dontapprove', value=_("Don't approve")))

        request.write(unicode(form))

        request.write(request.formatter.endContent())
        request.theme.send_footer(request.page.page_name)
        request.theme.send_closing_html()
예제 #11
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)