Welcome, guest! Login / Register - Why register?
[ Pastes: 84797 ] [ Members: 4801 ]


Short URL: http://goo.gl/sI8uq
Pasted as Plain Text by count12 on Thursday, November 1st, 2012 7:13am ( 5 years ago )

import os

import web

urls = (
 '/', 'index',
 '/login', 'Login',
 '/logout', 'Logout',
 '/add', 'add', 

render=web.template.render('/var/www/pvperformance/test/templates/', base='layout')
mrender=web.template.render('/var/www/pvperformance/test/templates/' )

app = web.application(urls, globals()) 
application = app.wsgifunc() 
session = web.session.Session(app, 
               initializer={'count': 0}) 

class index:
 def GET(self):
  return render.index() 

class Secure:
 def GET(self):
  return """
   <html>Hello %s 
   <a href="/logout">Log me out</a>&lt;/html&gt;
   """ % web.ctx.username   

class Login:

 def GET(self):
  return """
  &lt;form acti method="post"&gt;
  &lt;input type="text" name="username"&gt;
  &lt;input type="submit" value="Login"&gt;

 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 = app.wsgifunc()


Revise this Paste

Children: 56457
Your Name:
Code Language:

To minimise the influx of spam: you are required to register to post any code.