1.4.2 Example

The following code is an exemple that uses the CookieAuthenticate module:

use CookieSessionAuthenticate

CherryClass MemberArea(CookieSessionAuthenticate):
mask:
    def index(self):
        <html><body>
        Welcome to the member area, <py-eval="self.login"><br>
        If you want to log out, just click <a py-attr="self.getPath()+'/doLogout'" href="">here</a>.<br>
        Otherwise, just click <a py-attr="request.base" href="">here</a> to go back to the home page.
        </body></html>
    def loginScreen(self, message, fromPage, login=''):
        <html><body>
            Welcome to the login page. Please enter your login and password below:
            <py-if="message==self.wrongLoginPasswordMessage">
                <br><font color=red>Sorry, the login or password was incorrect</font>
            </py-if>
            <form method="post" action="doLogin">
                Login: <input type=text name=login py-attr="login" value="" length=10><br>
                Password: <input type=password name=password length=10><br>
                <input type=hidden name=fromPage py-attr="fromPage" value=""><br>
                <input type=submit value="Login">
            </form>
        </body></html>
    def logoutScreen(self):
        <html><body>
            You have been logged out.<br>
            Click <a py-attr="request.base" href="">here</a> to go back to the home page.
        </body></html>
function:
    def isGoodLoginAndPassword(self, login, password):
        if login == 'login' and password == 'password': return 1
        else: return 0
        

CherryClass Root:
mask:
    def index(self):
        <html><body>
            Welcome to the site.<br>
            Click <a href='memberArea/index'>here</a> to access the
            member area.
        </body></html>

Note that you need to enable sessions in your configuration file. For instance, if you want to have session data stored in RAM, you need to put this in your config file:

[session]
storageType = ram
See About this document... for information on suggesting changes.