~ubuntu-branches/ubuntu/natty/moin/natty-updates

« back to all changes in this revision

Viewing changes to MoinMoin/userform/login.py

  • Committer: Bazaar Package Importer
  • Author(s): Jonas Smedegaard
  • Date: 2008-06-22 21:17:13 UTC
  • mfrom: (0.9.1 upstream)
  • Revision ID: james.westby@ubuntu.com-20080622211713-fpo2zrq3s5dfecxg
Tags: 1.7.0-3
Simplify /etc/moin/wikilist format: "USER URL" (drop unneeded middle
CONFIG_DIR that was wrongly advertised as DATA_DIR).  Make
moin-mass-migrate handle both formats and warn about deprecation of
the old one.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
# -*- coding: iso-8859-1 -*-
 
2
"""
 
3
    MoinMoin - Login form
 
4
 
 
5
    @copyright: 2001-2004 Juergen Hermann <jh@web.de>,
 
6
                2003-2007 MoinMoin:ThomasWaldmann
 
7
    @license: GNU GPL, see COPYING for details.
 
8
"""
 
9
 
 
10
from MoinMoin.widget import html
 
11
 
 
12
 
 
13
class Login:
 
14
    """ User login. """
 
15
 
 
16
    def __init__(self, request):
 
17
        """ Initialize user settings form.
 
18
        """
 
19
        self.request = request
 
20
        self._ = request.getText
 
21
        self.cfg = request.cfg
 
22
 
 
23
    def make_row(self, label, cell, **kw):
 
24
        """ Create a row in the form table.
 
25
        """
 
26
        self._table.append(html.TR().extend([
 
27
            html.TD(**kw).extend([html.B().append(label), '   ']),
 
28
            html.TD().extend(cell),
 
29
        ]))
 
30
 
 
31
 
 
32
    def asHTML(self):
 
33
        """ Create the complete HTML form code. """
 
34
        _ = self._
 
35
        request = self.request
 
36
        sn = request.getScriptname()
 
37
        pi = request.getPathinfo()
 
38
        action = u"%s%s" % (sn, pi)
 
39
        hints = []
 
40
        for authm in request.cfg.auth:
 
41
            hint = authm.login_hint(request)
 
42
            if hint:
 
43
                hints.append(hint)
 
44
        self._form = html.FORM(action=action, name="loginform")
 
45
        self._table = html.TABLE(border="0")
 
46
 
 
47
        # Use the user interface language and direction
 
48
        lang_attr = request.theme.ui_lang_attr()
 
49
        self._form.append(html.Raw('<div class="userpref"%s>' % lang_attr))
 
50
 
 
51
        self._form.append(html.INPUT(type="hidden", name="action", value="login"))
 
52
        self._form.append(self._table)
 
53
        for hint in hints:
 
54
            self._form.append(html.P().append(html.Raw(hint)))
 
55
        self._form.append(html.Raw("</div>"))
 
56
 
 
57
        cfg = request.cfg
 
58
        if 'username' in cfg.auth_login_inputs:
 
59
            self.make_row(_('Name'), [
 
60
                html.INPUT(
 
61
                    type="text", size="32", name="name",
 
62
                ),
 
63
            ])
 
64
 
 
65
        if 'password' in cfg.auth_login_inputs:
 
66
            self.make_row(_('Password'), [
 
67
                html.INPUT(
 
68
                    type="password", size="32", name="password",
 
69
                ),
 
70
            ])
 
71
 
 
72
        if 'openid_identifier' in cfg.auth_login_inputs:
 
73
            self.make_row(_('OpenID'), [
 
74
                html.INPUT(
 
75
                    type="text", size="32", name="openid_identifier",
 
76
                    id="openididentifier"
 
77
                ),
 
78
            ])
 
79
 
 
80
        self.make_row('', [
 
81
            html.INPUT(
 
82
                type="submit", name='login', value=_('Login')
 
83
            ),
 
84
        ])
 
85
 
 
86
        return unicode(self._form)
 
87
 
 
88
def getLogin(request):
 
89
    """ Return HTML code for the login. """
 
90
    return Login(request).asHTML()