def delete_message_action(self, environ, start_response): # get cookie if there is one try: cookie = Cookie.SimpleCookie(environ["HTTP_COOKIE"]) username = cookie["username"].value #print "Username = %s" % username except: #print "session cookie not set! defaulting username" username = '' user = meeplib.get_user(username) if user is None: headers = [('Content-type', 'text/html')] headers.append(('Location', '/')) start_response("302 Found", headers) return ["You must be logged in to use that feature."] print environ['wsgi.input'] form = cgi.FieldStorage(fp=environ['wsgi.input'], environ=environ) thread_id = int(form['thread_id'].value) post_id = int(form['post_id'].value) t = meeplib.get_thread(thread_id) post = t.get_post(post_id) t.delete_post(post) meeplib.save_state() headers = [('Content-type', 'text/html')] headers.append(('Location', '/m/list')) start_response("302 Found", headers) return["post deleted"]
def reply(self, environ, start_response): print "enter reply" username = check_cookie(environ) user = meeplib.get_user(username) if user is None: headers = [('Content-type', 'text/html')] headers.append(('Location', '/')) start_response("302 Found", headers) return ["log in to use that feature"] headers = [('Content-type', 'text/html')] form = cgi.FieldStorage(fp=environ['wsgi.input'], environ=environ) thread_id = int(form['thread_id'].value) t = meeplib.get_thread(thread_id) s = [] try: post = form['post'].value except KeyError: post = '' if post != '': new_message = meeplib.Message(post, user) t.add_post(new_message) meeplib.save_state() headers.append(('Location','/m/list')) start_response("302 Found", headers) s.append(render_page("reply.html", thread=t)) print "exit reply" return ["".join(s)]
def reply(self, environ, start_response): print "enter reply" username = check_cookie(environ) user = meeplib.get_user(username) if user is None: headers = [('Content-type', 'text/html')] headers.append(('Location', '/')) start_response("302 Found", headers) return ["log in to use that feature"] headers = [('Content-type', 'text/html')] form = cgi.FieldStorage(fp=environ['wsgi.input'], environ=environ) thread_id = int(form['thread_id'].value) t = meeplib.get_thread(thread_id) s = [] try: post = form['post'].value except KeyError: post = '' if post != '': new_message = meeplib.Message(post, user) t.add_post(new_message) meeplib.save_state() headers.append(('Location', '/m/list')) start_response("302 Found", headers) s.append(render_page("reply.html", thread=t)) print "exit reply" return ["".join(s)]
def create_user(self, environ, start_response): # get cookie if there is one try: cookie = Cookie.SimpleCookie(environ["HTTP_COOKIE"]) username = cookie["username"].value except: username = '' user = meeplib.get_user(username) if user is not None: headers = [('Content-type', 'text/html')] headers.append(('Location', '/')) start_response("302 Found", headers) return ["You must be logged out to use that feature."] headers = [('Content-type', 'text/html')] print environ['wsgi.input'] form = cgi.FieldStorage(fp=environ['wsgi.input'], environ=environ) try: username = form['username'].value except KeyError: username = '' try: password = form['password'].value except KeyError: password = '' s = [] ##if we have username and password if username != '': user = meeplib.get_user(username) ## user already exists if user is not None: s.append('''Creation Failed! <br> User already exists, please use a different username.<p>''' ) ## user doesn't exist but they messed up the passwords elif password == '': s.append('''Creation Failed! <br> Please fill in the Password field<p>''') else: u = meeplib.User(username, password) meeplib.save_state() ## send back a redirect to '/' k = 'Location' v = '/' headers.append((k, v)) cookie_name, cookie_val = meepcookie.make_set_cookie_header( 'username', username) headers.append((cookie_name, cookie_val)) start_response('302 Found', headers) s.append(render_page("create_user.html", username=username)) return [''.join(s)]
def create_user(self, environ, start_response): # get cookie if there is one try: cookie = Cookie.SimpleCookie(environ["HTTP_COOKIE"]) username = cookie["username"].value except: username = '' user = meeplib.get_user(username) if user is not None: headers = [('Content-type', 'text/html')] headers.append(('Location', '/')) start_response("302 Found", headers) return ["You must be logged out to use that feature."] headers = [('Content-type', 'text/html')] print environ['wsgi.input'] form = cgi.FieldStorage(fp=environ['wsgi.input'], environ=environ) try: username = form['username'].value except KeyError: username = '' try: password = form['password'].value except KeyError: password = '' s=[] ##if we have username and password if username != '': user = meeplib.get_user(username) ## user already exists if user is not None: s.append('''Creation Failed! <br> User already exists, please use a different username.<p>''') ## user doesn't exist but they messed up the passwords elif password == '': s.append('''Creation Failed! <br> Please fill in the Password field<p>''') else: u = meeplib.User(username, password) meeplib.save_state() ## send back a redirect to '/' k = 'Location' v = '/' headers.append((k, v)) cookie_name, cookie_val = meepcookie.make_set_cookie_header('username',username) headers.append((cookie_name, cookie_val)) start_response('302 Found', headers) s.append(render_page("create_user.html", username=username)) return [''.join(s)]
def add_thread(self, environ, start_response): # get cookie if there is one try: cookie = Cookie.SimpleCookie(environ["HTTP_COOKIE"]) username = cookie["username"].value #print "Username = %s" % username except: #print "session cookie not set! defaulting username" username = '' user = meeplib.get_user(username) if user is None: headers = [('Content-type', 'text/html')] headers.append(('Location', '/')) start_response("302 Found", headers) return ["You must be logged in to use that feature."] headers = [('Content-type', 'text/html')] print environ['wsgi.input'] form = cgi.FieldStorage(fp=environ['wsgi.input'], environ=environ) try: title = form['title'].value except KeyError: title = '' try: message = form ['message'].value except KeyError: message = '' s = [] # title and message are non-empty if title == '' and message == '': pass elif title == '' and message != '': s.append("Title was empty.<p>") elif title != '' and message == '': s.append("Message was empty. <p>") elif title != '' and message != '': new_message = meeplib.Message(message, user) t = meeplib.Thread(title) t.add_post(new_message) meeplib.save_state() headers.append(('Location','/m/list')) start_response("302 Found", headers) # doesn't get executed if we had valid input and created a thread s.append(render_page("add_thread.html", title=title, message=message)) return ["".join(s)]
def delete_message_action(self, environ, start_response): print "enter delete message action" form = cgi.FieldStorage(fp=environ['wsgi.input'], environ=environ) thread_id = int(form['msg_id'].value) post_id = int(form['post_id'].value) t = meeplib.get_thread(thread_id) p = t.get_post(post_id) t.delete_post(p) meeplib.save_state() headers = [('Content-type', 'text/html')] headers.append(('Location', '/m/list')) start_response("302 Found", headers) print "exit delete message action" return["post deleted"]
def delete_message_action(self, environ, start_response): print "enter delete message action" form = cgi.FieldStorage(fp=environ['wsgi.input'], environ=environ) thread_id = int(form['msg_id'].value) post_id = int(form['post_id'].value) t = meeplib.get_thread(thread_id) p = t.get_post(post_id) t.delete_post(p) meeplib.save_state() headers = [('Content-type', 'text/html')] headers.append(('Location', '/m/list')) start_response("302 Found", headers) print "exit delete message action" return ["post deleted"]
def delete_all_messages_action(self, environ, start_response): print "enter delete all messages action" form = cgi.FieldStorage(fp=environ['wsgi.input'], environ=environ) username = check_cookie(environ) threads = meeplib.get_all_threads() for t in threads: meeplib.delete_thread(t) headers = [('Content-type', 'text/html')] headers.append(('Location', '/m/list')) start_response("302 Found", headers) meeplib.save_state() print "exit delete all messages action" return ["all threads deleted"]
def create_user(self, environ, start_response): print "enter create user" username = check_cookie(environ) user = meeplib.get_user(username) if user is not None: headers = [('Content-type', 'text/html')] headers.append(('Location', '/')) start_response("302 Found", headers) return ["log out to use that feature"] headers = [('Content-type', 'text/html')] form = cgi.FieldStorage(fp=environ['wsgi.input'], environ=environ) try: username = form['username'].value except KeyError: username = '' try: password = form['password'].value except KeyError: password = '' s = [] ##if we have username and password if username != '': user = meeplib.get_user(username) ## user already exists if user is not None: s.append('''user already exists; <br> please use a different username.<p>''') ## user doesn't exist but they messed up the passwords elif password == '': s.append('''enter a password <br/>''') else: u = meeplib.User(username, password) meeplib.save_state() ## send back a redirect to '/' k = 'Location' v = '/' headers.append((k, v)) cookie_name, cookie_val = meepcookie.make_set_cookie_header( 'username', username) headers.append((cookie_name, cookie_val)) start_response('302 Found', headers) s.append(render_page("create_user.html", username=username)) print "exit create user" return [''.join(s)]
def create_user(self, environ, start_response): print "enter create user" username = check_cookie(environ) user = meeplib.get_user(username) if user is not None: headers = [('Content-type', 'text/html')] headers.append(('Location', '/')) start_response("302 Found", headers) return ["log out to use that feature"] headers = [('Content-type', 'text/html')] form = cgi.FieldStorage(fp=environ['wsgi.input'], environ=environ) try: username = form['username'].value except KeyError: username = '' try: password = form['password'].value except KeyError: password = '' s=[] ##if we have username and password if username != '': user = meeplib.get_user(username) ## user already exists if user is not None: s.append('''user already exists; <br> please use a different username.<p>''') ## user doesn't exist but they messed up the passwords elif password == '': s.append('''enter a password <br/>''') else: u = meeplib.User(username, password) meeplib.save_state() ## send back a redirect to '/' k = 'Location' v = '/' headers.append((k, v)) cookie_name, cookie_val = meepcookie.make_set_cookie_header('username',username) headers.append((cookie_name, cookie_val)) start_response('302 Found', headers) s.append(render_page("create_user.html", username=username)) print "exit create user" return [''.join(s)]
def reply(self, environ, start_response): # get cookie if there is one try: cookie = Cookie.SimpleCookie(environ["HTTP_COOKIE"]) username = cookie["username"].value #print "Username = %s" % username except: #print "session cookie not set! defaulting username" username = '' user = meeplib.get_user(username) if user is None: headers = [('Content-type', 'text/html')] headers.append(('Location', '/')) start_response("302 Found", headers) return ["You must be logged in to use that feature."] headers = [('Content-type', 'text/html')] print environ['wsgi.input'] form = cgi.FieldStorage(fp=environ['wsgi.input'], environ=environ) thread_id = int(form['thread_id'].value) t = meeplib.get_thread(thread_id) s = [] try: post = form['post'].value except KeyError: post = '' # post is non-empty if post != '': new_message = meeplib.Message(post, user) t.add_post(new_message) meeplib.save_state() headers.append(('Location','/m/list')) start_response("302 Found", headers) # doesn't get executed unless we had invalid input s.append(render_page("reply.html", thread=t)) return ["".join(s)]
def add_thread(self, environ, start_response): print "enter add thread" username = check_cookie(environ) user = meeplib.get_user(username) if user is None: headers = [('Content-type', 'text/html')] headers.append(('Location', '/')) start_response("302 Found", headers) return ["log in in to use that feature"] headers = [('Content-type', 'text/html')] form = cgi.FieldStorage(fp=environ['wsgi.input'], environ=environ) try: title = form['title'].value except KeyError: title = '' try: message = form ['message'].value except KeyError: message = '' s = [] if title == '' and message == '': pass elif title == '' and message != '': s.append('''''title' cannot be empty<p>''') elif title != '' and message == '': s.append('''''message' cannot be empty<p>''') elif title != '' and message != '': new_message = meeplib.Message(message, user) t = meeplib.Thread(title) t.add_post(new_message) meeplib.save_state() headers.append(('Location','/m/list')) start_response("302 Found", headers) s.append(render_page("add_message.html", title=title, message=message)) print "exit add thread" return ["".join(s)]
def add_thread(self, environ, start_response): print "enter add thread" username = check_cookie(environ) user = meeplib.get_user(username) if user is None: headers = [('Content-type', 'text/html')] headers.append(('Location', '/')) start_response("302 Found", headers) return ["log in in to use that feature"] headers = [('Content-type', 'text/html')] form = cgi.FieldStorage(fp=environ['wsgi.input'], environ=environ) try: title = form['title'].value except KeyError: title = '' try: message = form['message'].value except KeyError: message = '' s = [] if title == '' and message == '': pass elif title == '' and message != '': s.append('''''title' cannot be empty<p>''') elif title != '' and message == '': s.append('''''message' cannot be empty<p>''') elif title != '' and message != '': new_message = meeplib.Message(message, user) t = meeplib.Thread(title) t.add_post(new_message) meeplib.save_state() headers.append(('Location', '/m/list')) start_response("302 Found", headers) s.append(render_page("add_message.html", title=title, message=message)) print "exit add thread" return ["".join(s)]
def create_user(self, environ, start_response): # get cookie if there is one try: cookie = Cookie.SimpleCookie(environ["HTTP_COOKIE"]) username = cookie["username"].value #print "Username = %s" % username except: #print "session cookie not set! defaulting username" username = '' user = meeplib.get_user(username) if user is not None: headers = [('Content-type', 'text/html')] headers.append(('Location', '/')) start_response("302 Found", headers) return ["You must be logged out to use that feature."] headers = [('Content-type', 'text/html')] print environ['wsgi.input'] form = cgi.FieldStorage(fp=environ['wsgi.input'], environ=environ) #print "form", form try: username = form['username'].value # retrieve user #print "we gots a username", username except KeyError: username = '' #print "no user input" try: password = form['password'].value #print "we gots a password", password except KeyError: password = '' #print 'no password input' try: password2 = form['password_confirm'].value #print "we gots a password", password except KeyError: password2 = '' #print 'no password confirmation' s=[] ##if we have username and password and confirmation password if username != '': user = meeplib.get_user(username) ## user already exists if user is not None: s.append('''Creation Failed! <br> User already exists, please use a different username.<p>''') ## user doesn't exist but they messed up the passwords elif password == '': s.append('''Creation Failed! <br> Please fill in the Password field<p>''') elif password != password2: s.append('''Creation Failed! <br> The passwords you provided did not match.<p>''') else: u = meeplib.User(username, password) meeplib.save_state() ## send back a redirect to '/' k = 'Location' v = '/' headers.append((k, v)) cookie_name, cookie_val = meepcookie.make_set_cookie_header('username',username) headers.append((cookie_name, cookie_val)) elif password != '' or password2 != '': s.append('''Creation Failed! <br> Please provide a username.<p>''') start_response('302 Found', headers) ##if we have a valid username and password this is not executed s.append(render_page("create_user.html", username=username)) return [''.join(s)]