def check_auth(): # get cookie data ckie = myCookie.myCookie() ssin = ckie.getcookie("session") if ssin == None: # nothing cookie, next check user/pass a = check_user_pass() if a == None: return None k = a.hhhh else: # check session time (t, k) = ssin.split(',') if int(t) < int(time.time()): # timeout, next check user/pass a = check_user_pass() if a == None: return None k = a.hhhh else: a = myAccount.myAccount(k) # update session t = str(int(time.time()) + 60 * 30) ckie.setcookie("session", t + "," + k) print ckie.output() return a
#!/usr/bin/env python # -*- coding: utf-8 -*- import auth import myCookie if __name__ == '__main__': # check auth a = auth.check_auth() if a == None: auth.html("login") # print cleard levels from database c = myCookie.myCookie() print c.deletecookie("session") auth.html("login")