Hello all,
I'm trying to get a simple authentication system going using the stuff
in the web.py svn trunk (rev 192). I assume this is the right place to
get the latest sessions code from? I first tried to get the GSoC stuff
from the bazaar repo, but bzr failed to build on my machine. But I
will persevere in that direction, if need be...?
I'm quite new to the whole web-app thing in general, so it's quite
possible I'm doing something fundamentally wrong. We'll see :) Here's
my code:
import web
urls = ('/login', 'login',
'/(.*)', 'index')
render = web.template.render('templates/')
web.session.session_parameters.handler = 'file'
web.session.handler_parameters.file_prefix = 'session_'
web.session.handler_parameters.file_dir = 'sessions'
def set_if_empty(d, k, v):
if not d.has_key(k): d[k] = v
class index(object):
def GET(self, name):
s = web.webapi.ctx.session
s.start()
set_if_empty(s, 'loggedin', False)
set_if_empty(s, 'username', 'Englebert Humperdink')
if s.loggedin == False:
self.show_login()
else:
# make sure the user knows their trust is misplaced :)
print 'Hello %s, your password is %s' % (s.username,
s.password)
def show_login(self):
s = web.webapi.ctx.session
print render.login(s.username)
class login(object):
def POST(self):
s = web.webapi.ctx.session
s.start()
try:
i = web.input()
s.username = i.username
s.password = i.password
s.loggedin = True
s.save()
except:
pass
web.seeother('/')
def GET(self):
web.seeother('/')
def main():
web.webapi.internalerror = web.debugerror
web.run(urls, globals())
if __name__ == '__main__':
main()
and my login.html template:
$def with (username)
<html>
<body>
<form method="post" action="login" enctype="multipart/form-data">
<p>
<input type="text" name="username" value="$username"/> <br />
<input type="password" name="password" /> <br />
<input type="submit" value="Login" />
</p>
</form>
</body>
</html>
When I run the app and point my browser at localhost:8080/, I see the
login screen. After clicking on the "Login" button once my details are
entered, I am shown the login screen again. It appears to me that the
data is not written to the session, though something else could be
going on.
Any advice or general comments are very much appreciated!
Kind regards,
Edd
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"web.py" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at http://groups.google.com/group/webpy?hl=en
-~----------~----~----~----~------~----~------~--~---