File: node13.html

package info (click to toggle)
cherrypy 0.10-1
  • links: PTS
  • area: main
  • in suites: sarge
  • size: 10,324 kB
  • ctags: 1,759
  • sloc: python: 14,411; sh: 6,915; perl: 2,472; makefile: 76
file content (146 lines) | stat: -rw-r--r-- 5,840 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<html>
<head>
<title>1.4.2 Example</title>
<META NAME="description" CONTENT="1.4.2 Example">
<META NAME="keywords" CONTENT="lib">
<META NAME="resource-type" CONTENT="document">
<META NAME="distribution" CONTENT="global">
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<link rel="STYLESHEET" href="lib.css" type='text/css'>
<link rel="first" href="lib.html">
<link rel="contents" href="contents.html" title="Contents">

<LINK REL="previous" HREF="node12.html">
<LINK REL="up" href="module-CookieSessionAuthenticate.html">
<LINK REL="next" href="module-Form.html">
<meta name='aesop' content='information'>
</head>
<body>
<DIV CLASS="navigation">
<table align="center" width="100%" cellpadding="0" cellspacing="2">
<tr>
<td><A HREF="node12.html"><img src="../icons/previous.gif"
  border="0" height="32"
  alt="Previous Page" width="32"></A></td>
<td><A href="module-CookieSessionAuthenticate.html"><img src="../icons/up.gif"
  border="0" height="32"
  alt="Up One Level" width="32"></A></td>
<td><A href="module-Form.html"><img src="../icons/next.gif"
  border="0" height="32"
  alt="Next Page" width="32"></A></td>
<td align="center" width="100%">CherryPy Standard Library Reference</td>
<td><A href="contents.html"><img src="../icons/contents.gif"
  border="0" height="32"
  alt="Contents" width="32"></A></td>
<td><img src="../icons/blank.gif"
  border="0" height="32"
  alt="" width="32"></td>
<td><img src="../icons/blank.gif"
  border="0" height="32"
  alt="" width="32"></td>
</tr></table>
<b class="navlabel">Previous:</b> <a class="sectref" HREF="node12.html">1.4.1 Module</A>
<b class="navlabel">Up:</b> <a class="sectref" href="module-CookieSessionAuthenticate.html">1.4 CookieSessionAuthenticate  </A>
<b class="navlabel">Next:</b> <a class="sectref" href="module-Form.html">1.5 Form  </A>
<br><hr>
</DIV>
<!--End of Navigation Panel-->

<H2><A NAME="SECTION003420000000000000000">
1.4.2 Example</A>
</H2>
The following code is an exemple that uses the CookieAuthenticate module:

<P>
<div class="verbatim"><pre>
use CookieSessionAuthenticate

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

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

<P>
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:

<P>
<div class="verbatim"><pre>
[session]
storageType = ram
</pre></div>

<DIV CLASS="navigation">
<p><hr>
<table align="center" width="100%" cellpadding="0" cellspacing="2">
<tr>
<td><A HREF="node12.html"><img src="../icons/previous.gif"
  border="0" height="32"
  alt="Previous Page" width="32"></A></td>
<td><A href="module-CookieSessionAuthenticate.html"><img src="../icons/up.gif"
  border="0" height="32"
  alt="Up One Level" width="32"></A></td>
<td><A href="module-Form.html"><img src="../icons/next.gif"
  border="0" height="32"
  alt="Next Page" width="32"></A></td>
<td align="center" width="100%">CherryPy Standard Library Reference</td>
<td><A href="contents.html"><img src="../icons/contents.gif"
  border="0" height="32"
  alt="Contents" width="32"></A></td>
<td><img src="../icons/blank.gif"
  border="0" height="32"
  alt="" width="32"></td>
<td><img src="../icons/blank.gif"
  border="0" height="32"
  alt="" width="32"></td>
</tr></table>
<b class="navlabel">Previous:</b> <a class="sectref" HREF="node12.html">1.4.1 Module</A>
<b class="navlabel">Up:</b> <a class="sectref" href="module-CookieSessionAuthenticate.html">1.4 CookieSessionAuthenticate  </A>
<b class="navlabel">Next:</b> <a class="sectref" href="module-Form.html">1.5 Form  </A>
<hr>
<span class="release-info">Release 0.10, documentation updated on 19 March 2004.</span>
</DIV>
<!--End of Navigation Panel-->
<ADDRESS>
See <i><a href="about.html">About this document...</a></i> for information on suggesting changes.
</ADDRESS>
</BODY>
</HTML>