) s += ("</head>") s += ("<body>") s += ("<p>" + content_line + "\n") s += ("</body>") s += ("</html>") return s cgitb.enable() form = cgi.FieldStorage() signup_type = form['signup_type'].value if signup_type not in ['register', 'login', 'logout']: print buildLoginForm.build_login_form("Signup type incorrectly specified.") exit(0) #checking signup type first, to see if you should logout and not check for other form elements that wouldn't exist if signup_type == "logout": oldc = Cookie.SimpleCookie(os.environ.get('HTTP_COOKIE')) if oldc is None: page = buildLoginForm.build_login_form( 'Error finding your current cookie. :(') else: c = Cookie.SimpleCookie() a = oldc['sessid'] c['sessid'] = a c['sessid']['expires'] = 'Sun, 26 Oct 2014 00:00:01 GMT' page = buildLoginForm.build_login_form("You've successfully logged out", cookie=c)
s += ("<meta http-equiv='refresh' content='0; url=http://www.lindyfiles.com/' />") s += ("</head>") s += ("<body>") s += ("<p>" + content_line + "\n") s += ("</body>") s += ("</html>") return s cgitb.enable() form = cgi.FieldStorage() signup_type = form['signup_type'].value if signup_type not in ['register', 'login', 'logout']: print buildLoginForm.build_login_form("Signup type incorrectly specified.") exit(0) #checking signup type first, to see if you should logout and not check for other form elements that wouldn't exist if signup_type == "logout": oldc = Cookie.SimpleCookie(os.environ.get('HTTP_COOKIE')) if oldc is None: page = buildLoginForm.build_login_form('Error finding your current cookie. :(') else: c = Cookie.SimpleCookie() a = oldc['sessid'] c['sessid'] = a c['sessid']['expires'] = 'Sun, 26 Oct 2014 00:00:01 GMT' page = buildLoginForm.build_login_form("You've successfully logged out", cookie=c) print page exit(0)
conn = sqlite3.connect('/home2/mmullock/public_html/lindyfiles/lindyfiles.db') cur = conn.cursor() # check for cookie cookie_string = os.environ.get('HTTP_COOKIE') # if there is a cookie if cookie_string: # look in database for user with that sessid try: ck = Cookie.SimpleCookie(cookie_string) sessid = ck["sessid"].value cur.execute("SELECT email FROM users WHERE sessid = ?", (sessid, )) results = cur.fetchone() email = results[0] print buildPage.build_html_page("Welcome back, " + email) except: # print buildPage.build_html_page("Cookie found but user not found. sessid = " + cookie["sessid"].value) print buildLoginForm.build_login_form("") # if no cookie show register/login option else: # show login/register options print buildLoginForm.build_login_form("") # close db connection cur.close() conn.close()
cookie_string = os.environ.get('HTTP_COOKIE') # if there is a cookie if cookie_string: # look in database for user with that sessid try: ck = Cookie.SimpleCookie(cookie_string) sessid = ck["sessid"].value cur.execute("SELECT email FROM users WHERE sessid = ?", (sessid,)) results = cur.fetchone() email = results[0] print buildPage.build_html_page("Welcome back, " + email) except: # print buildPage.build_html_page("Cookie found but user not found. sessid = " + cookie["sessid"].value) print buildLoginForm.build_login_form("") # if no cookie show register/login option else: # show login/register options print buildLoginForm.build_login_form("") # close db connection cur.close() conn.close()