To illustrate how to use database-driven user authentication, run logondbapp.py
. It will present you with a logon screen very similar to the one shown in the previous chapter. You may enter the built-in username/password combination of admin/admin, after which you will be presented with a welcoming page.
In order to make this mini application work with the database-driven version of user authentication, all we have to do is replace the reference to an instance of the Logon class to one of the LogonDB
class, as highlighted in the following code (the full code is available as logondbapp.py
):
Chapter4/logondbdb.py
import cherrypy
import logondb
class Root(object):
logon = logondb.LogonDB(path="/logon", authenticated="/", not_authenticated="/goaway", db="/tmp/pwd.db")
@cherrypy.expose
def index(self):
username=Root.logon.checkauth('/logon')
return '<html><body><p>Hello user <b>%s</b></p>...