#!/usr/bin/env python
# coding: utf-8
import web
from web import form
urls = (
'/','Index',
'/test','Test',
'/login','Login',
'/logout','Logout',
)
render = web.template.render("/opt/py/login")
allowed = (
('admin','123123'),
)
web.config.debug = False
app = web.application(urls, locals())
session = web.session.Session(app, web.session.DiskStore('sessions'))
class Index:
def GET(self):
if session.get('logged_in',False):
return '\Login Success!!!\testLogout'
raise web.seeother('/login')
class Login:
def GET(self):
return render.login()
def POST(self):
i = web.input()
username = i.get('username')
passwd = i.get('passwd')
if (username,passwd) in allowed:
session.logged_in = True
web.setcookie('system_mangement', , 60)
raise web.seeother('/')
else:
return '\Login Error!!!\Login'
class Logout:
def GET(self):
session.logged_in = False
raise web.seeother("/login")
class Test:
def GET(self):
if session.get('logged_in',False):
return '\ test login success!!!\Logout'
return '\logout now\Login'
if __name__ == '__main__':
app.run()