def Post(env, resp): '''Post handles a submission of the forum's form. The message the user posted is saved in the database, then it sends a 302 Redirect back to the main page so the user can see their new post. ''' # Get post content print 'env = ', env input = env['wsgi.input'] print 'input: ', input length = int(env.get('CONTENT_LENGTH', 0)) # If length is zero, post is empty - don't save it. if length > 0: postdata = input.read(length) print 'postdata: ', postdata fields = cgi.parse_qs(postdata) content = fields['content'][0] username = fields['username'][0] passwd = fields['passwd'][0] reply_to_id = fields['post_id'][0] islegal = forumdb.checkUser(username, passwd) if not islegal: status = '404 Not Found' headers = [('Content-type', 'text/plain')] resp(status, headers) return ['Not Found user'] # If the post is just whitespace, don't save it. content = content.strip() if content: # Save it in the database forumdb.AddPost(content, username, reply_to_id) # 302 redirect back to the main page headers = [('Location', '/'), ('Content-type', 'text/plain')] resp('302 REDIRECT', headers) return ['Redirecting']
def Post(env, resp): '''Post handles a submission of the forum's form. The message the user posted is saved in the database, then it sends a 302 Redirect back to the main page so the user can see their new post. ''' # Get post content input = env['wsgi.input'] length = int(env.get('CONTENT_LENGTH', 0)) # If length is zero, post is empty - don't save it. if length > 0: postdata = input.read(length) fields = cgi.parse_qs(postdata) content = fields['content'][0] # If the post is just whitespace, don't save it. content = content.strip() if content: #sanitize bleachedContent = bleach.clean(content) # Save it in the database forumdb.AddPost(bleachedContent) # 302 redirect back to the main page headers = [('Location', '/'), ('Content-type', 'text/plain')] resp('302 REDIRECT', headers) return ['Redirecting']
def Post(env, resp): '''Post handles a submission of the forum's form. The message the user posted is saved in the database, then it sends a 302 Redirect back to the main page so the user can see their new post. ''' print('Post Function Called') # Get post content bleach.clean('u<script>') bleach.clean('u</script>') bleach.clean('u<script></script>') print('bl-4') input = env['wsgi.input'] print('Input') print(input) bleach.clean(input) length = int(env.get('CONTENT_LENGTH', 0)) bleach.clean(length) # If length is zero, post is empty - don't save it. if length > 0: postdata = input.read(length) bleach.clean(postdata) fields = cgi.parse_qs(postdata) bleach.clean(fields) content = fields['content'][0] # If the post is just whitespace, don't save it. content = content.strip() bleach.clean(content) if content: # Save it in the database bleach.clean(content) bleach.clean(u'<h2>') bleach.clean(u'</h2>') forumdb.AddPost(content) # 302 redirect back to the main page headers = [('Location', '/'), ('Content-type', 'text/plain')] resp('302 REDIRECT', headers) return ['Redirecting']