Webware / WebKit / Admin / LoginPage.py

from random import randint
from time import time, localtime

from AdminPage import AdminPage


class LoginPage(AdminPage):
    """The log-in screen for the admin pages."""

    def writeContent(self):
        if self.loginDisabled():
            self.write(self.loginDisabled())
            return
        self.writeln('<div style="margin-left:auto;margin-right:auto;width:20em">'
            '<p>&nbsp;</p>')
        extra = self.request().field('extra', None)
        if extra:
            self.writeln('<p style="color:#333399">%s</p>' % self.htmlEncode(extra))
        self.writeln('''<p>Please log in to view Administration Pages.
The username is <tt>admin</tt>. The password has been set during installation and is
stored in the <tt>Application.config</tt> file in the <tt>WebKit/Configs</tt> directory.</p>
<form method="post">
<table cellpadding="4" cellspacing="4" style="background-color:#CCCCEE;border:1px solid #3333CC;width:20em">
<tr><td align="right"><label for="username">Username:</label></td>
<td><input type="text" id="username" name="username" value="admin"></td></tr>
<tr><td align="right"><label for="password">Password:</label></td>
<td><input type="password" id="password" name="password" value=""></td></tr>
<tr><td colspan="2" align="right"><input type="submit" name="login" value="Login"></td></tr>
</table>''')
        for name, value in self.request().fields().items():
            if name.lower() not in ('username', 'password', 'login', 'logout', 'loginid'):
                if not isinstance(value, list):
                    value = [value]
                for v in value:
                    self.writeln('<input type="hidden" name="%s" value="%s">' % (name, v))
        if self.session().hasValue('loginid'):
            loginid = self.session().value('loginid')
        else:
            # Create a "unique" login id and put it in the form as well as in the session.
            # Login will only be allowed if they match.
            loginid = ''.join(map(lambda x: '%02d' % x,
                localtime(time())[:6])) + str(randint(10000, 99999))
            self.session().setValue('loginid', loginid)
        self.writeln('<input type="hidden" name="loginid" value="%s">' % loginid)
        self.writeln('</form>\n<p>&nbsp;</p></div>')
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.