Psst.. new poll here.
Psst.. new forums here.
Microsoft is blocking us again (TY IP Reputation!) so just use oauth login instead. :)
Paste
Pasted as Plain Text by count12 ( 14 years ago )
#!/usr/bin/python
# code.py
# new portal using web.py
import os
#import hashlib
import web
urls = (
'/', 'index',
'/login', 'Login',
'/logout', 'Logout',
'/add', 'add',
'/secure','Secure',
)
render=web.template.render('/var/www/pvperformance/test/templates/', base='layout')
mrender=web.template.render('/var/www/pvperformance/test/templates/' )
db=web.database(dbn='sqlite',db='/var/www/pvperformance/test/users.db')
webapp = web.application(urls, globals())
store = web.session.DBStore(db, '/var/www/pvperformance/test/sessions')
session = web.session.Session(webapp, store, initializer={'count': 0})
app = webapp.wsgifunc()
class index:
def GET(self):
return render.index()
class Secure:
def GET(self):
return """
<html>Hello %s
<hr>
<a href="/logout">Log me out</a></html>
""" % web.ctx.username
class Login:
def GET(self):
return """
<html>
<form acti method="post">
<input type="text" name="username">
<input type="submit" value="Login">
</form>
</html>
"""
def POST(self):
# only set cookie if user login succeeds
name = web.input(username=None).username
if name:
web.setcookie('username', name)
raise web.seeother('/secure')
class Logout:
def GET(self):
web.setcookie('username', '', expires=-1)
raise web.seeother('/login')
# Auth Processor
def auth_app_processor(handle):
path = web.ctx.path
web.ctx.username = name = web.cookies(username=None).username
if not name and path != '/login':
raise web.seeother('/login')
return handle()
app = webapp.wsgifunc()
app.add_processor(auth_app_processor)
#########################################
app.add_processor(auth_app_processor)
[Mon Oct 29 16:56:52 2012] [error] [client 50.0.17.2] AttributeError: 'function' object has no attribute 'add_proc
[Mon Oct 29 16:56:52 2012] [error] [client 50.0.17.2] File does not exist: /var/www/pvperformance/favicon.ico
Revise this Paste