How To Logout From A Simple Web Appl. In Cherrypy, Python
I am not familiar with CherryPy and Python, but I need to write a very simple web application that performs login ---> do some commands ---> logout. For login I am using the
Solution 1:
Try running this code. It calls the AuthController().logout() function.
import cherrypy
import os.path
import struct
from auth import AuthController, require, member_of, name_is
classServer(object):
led_power=0
led_switch=1#Initial LED on
_cp_config = {
'tools.sessions.on': True,
'tools.auth.on': True
}
auth = AuthController()
@cherrypy.expose@require()defindex(self, switch='', power=''):
if switch:
self.led_switch = int(switch)
if power:
self.led_power = int(power)
html = open('led.html','r').read()
if self.led_switch:
print"ON"else:
print"OFF"if self.led_power:
print"Logout"
AuthController().logout()
return html
index.exposed = True
conf = {
'global' : {
'server.socket_host': '0.0.0.0', #0.0.0.0 or specific IP'server.socket_port': 8080#server port
},
'/images': { #images served as static files'tools.staticdir.on': True,
'tools.staticdir.dir': os.path.abspath('images')
},
'/favicon.ico': { #favorite icon'tools.staticfile.on': True,
'tools.staticfile.filename': os.path.abspath("images/bulb.ico")
}
}
cherrypy.quickstart(Server(), config=conf)
Hope this helps.
Andrew
Post a Comment for "How To Logout From A Simple Web Appl. In Cherrypy, Python"