def reply_action(self, environ, start_response): print environ['wsgi.input'] form = cgi.FieldStorage(fp=environ['wsgi.input'], environ=environ) post = form['post'].value #username = '******' cookie = Cookie.SimpleCookie(environ["HTTP_COOKIE"]) username = cookie["username"].value user = meeplib.get_user(username) new_message = meeplib.Message(post, user) thread_id = int(form['thread_id'].value) t = meeplib.get_thread(thread_id) t.add_post(new_message) meeplib.save() headers = [('Content-type', 'text/html')] headers.append(('Location', '/m/list')) start_response("302 Found", headers) return ["reply added"]
def add_new_user(self, environ, start_response): print environ['wsgi.input'] form = cgi.FieldStorage(fp=environ['wsgi.input'], environ=environ) returnStatement = "user added" try: username = form['username'].value except KeyError: username = None try: password = form['password'].value except KeyError: password = None print username print password # Test whether variable is defined to be None if username is None: returnStatement = "username was not set. User could not be created" if password is None: returnStatement = "password was not set. User could not be created" else: new_user = meeplib.User(username, password) meeplib.save() headers = [('Content-type', 'text/html')] headers.append(('Location', '/')) start_response("302 Found", headers) return [returnStatement]
def add_new_user(self, environ, start_response): print environ["wsgi.input"] form = cgi.FieldStorage(fp=environ["wsgi.input"], environ=environ) returnStatement = "user added" try: username = form["username"].value except KeyError: username = None try: password = form["password"].value except KeyError: password = None print username print password # Test whether variable is defined to be None if username is None: returnStatement = "username was not set. User could not be created" if password is None: returnStatement = "password was not set. User could not be created" else: new_user = meeplib.User(username, password) meeplib.save() headers = [("Content-type", "text/html")] headers.append(("Location", "/")) start_response("302 Found", headers) return [returnStatement]
def reply_action(self, environ, start_response): print environ["wsgi.input"] form = cgi.FieldStorage(fp=environ["wsgi.input"], environ=environ) post = form["post"].value # username = '******' cookie = Cookie.SimpleCookie(environ["HTTP_COOKIE"]) username = cookie["username"].value user = meeplib.get_user(username) new_message = meeplib.Message(post, user) thread_id = int(form["thread_id"].value) t = meeplib.get_thread(thread_id) t.add_post(new_message) meeplib.save() headers = [("Content-type", "text/html")] headers.append(("Location", "/m/list")) start_response("302 Found", headers) return ["reply added"]
def add_message(self, environ, start_response): #get cookie try: cookie = Cookie.SimpleCookie(environ["HTTP_COOKIE"]) username = cookie["username"].value print "Username is %s" % username except: username = '' user = meeplib.get_user(username) if user is None: headers = [('Content-type', 'text/html')] headers.append(('Location', '/')) start_response("302 Found", headers) return ["Dude, login first if you want to use this 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 = [] #check to see if title and message are not empty if title == '' and message == '': pass elif title == '' and message != '': s.append("The title is empty.<p>") elif title != '' and message == '': s.append("The message is empty. <p>") elif title != '' and message != '': new_message = meeplib.Message(message, user) t = meeplib.Thread(title) t.add_post(new_message) meeplib.save() headers.append(('Location','/m/list')) start_response("302 Found", headers) s.append(render_page("add_message.html", title=title, message=message)) return ["".join(s)]
def delete_message_action(self, environ, start_response): 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() headers = [('Content-type', 'text/html')] headers.append(('Location', '/m/list')) start_response("302 Found", headers) return["Post was deleted."]
def delete_message_action(self, environ, start_response): 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() headers = [("Content-type", "text/html")] headers.append(("Location", "/m/list")) start_response("302 Found", headers) return ["post deleted"]
def reply(self, environ, start_response): # get cookie try: cookie = Cookie.SimpleCookie(environ["HTTP_COOKIE"]) username = cookie["username"].value except: 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 = '' #check to make sure post is not empty if post != '': new_message = meeplib.Message(post, user) t.add_post(new_message) meeplib.save() headers.append(('Location','/m/list')) start_response("302 Found", headers) s.append(render_page("reply.html", thread=t)) return ["".join(s)]
def add_message_action(self, environ, start_response): print environ['wsgi.input'] form = cgi.FieldStorage(fp=environ['wsgi.input'], environ=environ) title = form['title'].value message = form['message'].value cookie = Cookie.SimpleCookie(environ["HTTP_COOKIE"]) username = cookie["username"].value #username = meeplib.get_curr_user() user = meeplib.get_user(username) new_message = meeplib.Message(message, user) t = meeplib.Thread(title) t.add_post(new_message) meeplib.save() headers = [('Content-type', 'text/html')] headers.append(('Location', '/m/list')) start_response("302 Found", headers) return ["message added"]
def add_message_action(self, environ, start_response): print environ["wsgi.input"] form = cgi.FieldStorage(fp=environ["wsgi.input"], environ=environ) title = form["title"].value message = form["message"].value cookie = Cookie.SimpleCookie(environ["HTTP_COOKIE"]) username = cookie["username"].value # username = meeplib.get_curr_user() user = meeplib.get_user(username) new_message = meeplib.Message(message, user) t = meeplib.Thread(title) t.add_post(new_message) meeplib.save() headers = [("Content-type", "text/html")] headers.append(("Location", "/m/list")) start_response("302 Found", headers) return ["message added"]
def create_user(self, environ, start_response): 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 ["Already logged in. Must logout to create a user."] 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('''User creation has failed, miserably. <br> Your lack of creativity has resulted in an already existing username. <br> Please be more creative and create a different username.<p>''') # user doesn't exist but password is f****d elif password == '': s.append('''User was not created. <br> Must input a password to use.<p>''') else: u = meeplib.User(username, password) meeplib.save() # redirect it back 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)]