def createNotMember(): notMember = '' groupList = stdStuff.objFileToList(stdStuff.directory, stdStuff.groupFile) for group in groupList: if group.name == currentGroup: userList = stdStuff.objFileToList(stdStuff.directory, stdStuff.userFile) for member in userList: if not(member.name in group.members): notMember += '<option>' + (member.name) + '</option?> \n\t' return notMember
def createIsMember(): isMember = '' groupList = stdStuff.objFileToList(stdStuff.directory, stdStuff.groupFile) for group in groupList: if group.name == currentGroup: userList = stdStuff.objFileToList(stdStuff.directory, stdStuff.userFile) for member in userList: if (member.name in group.members) and (member.name != currentUser): isMember += '<option>' + (member.name) + '</option> \n\t' return isMember
def displayReadMessages(cookie): res = "" orderedMessages = [] currentUser = cookie["username"].value userDict = stdStuff.objFileToList(stdStuff.directory, stdStuff.userFile, byName=True) res += \ "<a href='inbox.py?markUnread=all&read=hey'>Mark all as unread</a><br><br>" for message in userDict[currentUser].inbox.messages: if type(message) is stdStuff.Message: orderedMessages.append(message) orderedMessages.sort(key=lambda x: x.id, reverse=True) for message in orderedMessages: if message.viewed == True: res += "<div class='message'>" res += message.display() res += "<a href='messageChain.py?postId=" + \ str(message.id) + "'>View all replies</a>" res += "<br>" res += "<a href='inbox.py?markUnread=" + \ str(message.id) + \ "&read=hey'>Mark as unread</a>" res += '''<form action = "inbox.py" method = "GET"> Reply: <textarea name="replyBody" rows="10" cols="15"> </textarea> <br> <input name="postId" type="hidden" value="''' + str(message.id) + '''"> <input name="reply" type="submit" value="Reply"> </form> </div>''' #res += "</div>" return res
def displayPost(id, cookie, titleTag, bodyTag, userTag, commentTag): res = "" userList = stdStuff.objFileToList(stdStuff.directory, stdStuff.userFile) for x in userList: if x.name == cookie["username"].value: for post in x.posts: if post.id == id: res += post.display() res += "<br><h3>Comments</h3><br>" for comment in post.comments: res += """<table> <tr> <td>""" + str(comment.score) + """</td> <td> """ res += comment.display() res += "<a href='postExpanded.py?downVote=lol&commentId="+\ str(comment.id) + "'&postId='" + str(post.id) + "'>Down Vote</a><br>" res += "<a href='postExpanded.py?upVote=lol&commentId="+\ str(comment.id) + "'&postId='" + str(post.id) + "'>Up Vote</a><br>" res += """</td> </tr> </table> """ break return res
def displayGroup(): availableGroups = '' groupList = stdStuff.objFileToList(stdStuff.directory, stdStuff.groupFile) for name in groupList: if (name.visibility == 'public') or (currentUser in name.members): availableGroups += '<option>' + str(name.name) + '</option>' return availableGroups
def displayUnreadMessages(cookie): res = "<br>" orderedMessages = [] #friend requests orderedRequests = [] currentUser = cookie["username"].value userDict = stdStuff.objFileToList(stdStuff.directory, stdStuff.userFile, byName=True) res += \ """<a href='inbox.py?markRead=all&unread=hey'>Mark all as read</a><br><br>""" for message in userDict[currentUser].inbox.messages: if type(message) is stdStuff.Message: orderedMessages.append(message) elif type(message) is stdStuff.FriendRequest: orderedRequests.append(message) orderedMessages.sort(key=lambda x: x.id, reverse=True) orderedRequests.sort(key=lambda x: x.id, reverse=True) for request in orderedRequests: if request.viewed == False: res += request.display() res += "<a href='inbox.py?aReq=" + str(request.id) + \ "&unread=hey'>Accept</a><br>" res += "<a href='inbox.py?dReq=" + str(request.id) + \ "&unread=hey'>Decline</a>" for message in orderedMessages: if message.viewed == False: res += message.display() res += "<a href='inbox.py?markRead=" + str(message.id) + \ "&unread=hey'>Mark as read</a>" return res
def makePage(cookie): res = str(poster()) userList = stdStuff.objFileToList(stdStuff.directory, stdStuff.userFile) for x in userList: if x.name == cookie["username"].value: for post in x.posts: res += """<table> <tr> <td>""" + str(post.score) + """</td> <td> """ res += post.display() res += "<a href='profile.py?downVote=lol&postId="+\ str(post.id) + "'>Down Vote</a><br>" res += "<a href='profile.py?upVote=lol&postId="+\ str(post.id) + "'>Up Vote</a><br>" res += """<a href='postExpanded.py?expandButton=""" + \ str(post.id) + "'>Comment </a>" res += """</td> </tr> </table> """ break return res
def displayPost(id, currentUser, titleTag, bodyTag, userTag, commentTag): res = "" userDict = stdStuff.objFileToList(stdStuff.directory, stdStuff.userFile, byName=True) for post in userDict[currentUser].posts: if post.id == id: res += post.display() res += "<br><h3>Comments</h3><br>" for comment in post.comments: res += """<table> <tr> <td>""" + str(comment.score) + """</td> <td> """ res += comment.display() res += "<a href='postExpanded.py?downVote=lol&commentId="+\ str(comment.id) + "'&postId='" + str(post.id) + "'>Down Vote</a><br>" res += "<a href='postExpanded.py?upVote=lol&commentId="+\ str(comment.id) + "'&postId='" + str(post.id) + "'>Up Vote</a><br>" res += """</td> </tr> </table> """ return res for friend in userDict[currentUser].friends: for post in userDict[friend].posts: if post.id == id: res += post.display() res += "<br><h3>Comments</h3><br>" for comment in post.comments: res += """<table> <tr> <td>""" + str(comment.score) + """</td> <td> """ res += comment.display() res += "<a href='postExpanded.py?downVote=lol&commentId="+\ str(comment.id) + "'&postId='" + str(post.id) + "'>Down Vote</a><br>" res += "<a href='postExpanded.py?upVote=lol&commentId="+\ str(comment.id) + "'&postId='" + str(post.id) + "'>Up Vote</a><br>" res += """</td> </tr> </table> """ return res return res
def makePage(): res = str(poster()) #not sure why it doesnt work postList = stdStuff.objFileToList(stdStuff.directory, stdStuff.postFile) #print len(postList) for post in postList: res += displayPost(post, "h1", "p", "h6") return res
def writeComment(commentText, cookie, targId): allPosts = stdStuff.objFileToList(stdStuff.directory, stdStuff.postFile) for index, value in enumerate(allPosts): if value.id == targId: allPosts[index].addComment(cookie['username'].value, commentText) commentWStream = open(stdStuff.directory + stdStuff.postFile, "w") for x in allPosts: pickle.dump(x, commentWStream) commentWStream.close()
def writeComment(targId, cookie, commentText): targName = cookie["username"].value allUsers = stdStuff.objFileToList(stdStuff.directory, stdStuff.userFile) counter = stdStuff.getCounter() for index, value in enumerate(allUsers): if value.name == targName: for index2, value2 in enumerate(value.posts): if int(value2.id) == int(targId): value.posts[index2].addComment(counter, targName, commentText) stdStuff.objListToFile(allUsers, stdStuff.directory, stdStuff.userFile) stdStuff.setCounter(counter)
def writeComment(targId, cookie, commentText): targName = currentGroup currentUser = c['username'].value groupList = stdStuff.objFileToList(stdStuff.directory, stdStuff.groupFile) counter = stdStuff.getCounter() for index, value in enumerate(groupList): if value.name == targName: for index2, value2 in enumerate(value.posts): if int(value2.id) == int(targId): value.posts[index2].addComment(counter, currentUser, commentText) stdStuff.objListToFile(groupList, stdStuff.directory, stdStuff.groupFile) stdStuff.setCounter(counter)
def sendFriendRequest(form, userDict, srcUser): res = "<h4>Request sent to: " atLeastOne = False for element in form: if element in userDict: # send the friend request userDict[srcUser].inbox.sendMessage(element, "", "", request=True) atLeastOne = True res += element + ", " res = res[: len(res) - 2] res += "</h4>" if not (atLeastOne): res = "<h2>You didn't select anyone!</h2>" userDict = stdStuff.objFileToList(stdStuff.directory, stdStuff.userFile, byName=True) return res
def writePost(cookie, formThing): counter = stdStuff.getCounter() groupList = stdStuff.objFileToList(stdStuff.directory, stdStuff.groupFile) for x in groupList: if x.name == currentGroup: x.addPost( stdStuff.Post( counter, cookie["username"].value, formThing.getvalue("postTitle"), formThing.getvalue('textBody'))) break stdStuff.setCounter(counter) stdStuff.objListToFile(groupList, stdStuff.directory, stdStuff.groupFile)
def displayInboxWidget(cookie): currentUser = cookie["username"].value userDict = stdStuff.objFileToList(stdStuff.directory, stdStuff.userFile, byName=True) res = """ <div class="widget" id="inboxWidget"> <table border='1'> <tr> <td> <a href="inbox.py">View messages</a> </td> </tr> </table> </div> """ return res
def displayGroupWidget(cookie): currentUser = cookie["username"].value userDict = stdStuff.objFileToList(stdStuff.directory, stdStuff.userFile, byName=True) res = """ <div align='right'> <table border='1'> <tr> <td> <a href="groups.py">View groups</a> </td> </tr> </table> </div> """ return res
def writePost(cookie, formThing): counter = stdStuff.getCounter() userList = stdStuff.objFileToList(stdStuff.directory, stdStuff.userFile) for x in userList: if x.name == cookie["username"].value: x.addPost(stdStuff.Post( counter, cookie["username"].value, stdStuff.deleteBrackets(formThing.getvalue("postTitle")), stdStuff.deleteBrackets(formThing.getvalue('textBody')))) break stdStuff.setCounter(counter) stdStuff.objListToFile(userList, stdStuff.directory, stdStuff.userFile)
def displayPosts(cookie): currentUser = cookie["username"].value res = "" #will sort totalPosts = [] #all users in system userDict = stdStuff.objFileToList(stdStuff.directory, stdStuff.userFile, byName=True) totalPosts.extend(userDict[currentUser].posts[:]) #remember, the friends array only holds names for friend in userDict[currentUser].friends: totalPosts.extend(userDict[friend].posts[:]) totalPosts.sort(key=lambda x: x.id, reverse=True) for post in totalPosts: res += """<table> <tr> <td>""" + str(post.score) + """</td> <td> """ res += post.display() res += "<a href='profile.py?downVote=lol&postId="+\ str(post.id) + "'>Down Vote</a><br>" res += "<a href='profile.py?upVote=lol&postId="+\ str(post.id) + "'>Up Vote</a><br>" res += "<a href='profile.py?removeVote=lol&postId="+\ str(post.id) + "'>Remove Vote</a><br>" res += """<a href='postExpanded.py?expandButton=""" + \ str(post.id) + "'>Comment </a>" res += """</td> </tr> </table> """ return res
def displayUnreadMessages(cookie): res = "<br>" orderedMessages = [] #friend requests orderedRequests = [] currentUser = cookie["username"].value userDict = stdStuff.objFileToList(stdStuff.directory, stdStuff.userFile, byName=True) res += \ """<a href='inbox.py?markRead=all&unread=hey'>Mark all as read</a><br><br>""" for message in userDict[currentUser].inbox.messages: if type(message) is stdStuff.Message: orderedMessages.append(message) elif type(message) is stdStuff.FriendRequest: orderedRequests.append(message) orderedMessages.sort(key=lambda x: x.id, reverse=True) orderedRequests.sort(key=lambda x: x.id, reverse=True) for request in orderedRequests: if request.viewed == False: res += request.display() res += "<a href='inbox.py?aReq=" + str(request.id) + \ "&unread=hey'>Accept</a><br>" res += "<a href='inbox.py?dReq=" + str(request.id) + \ "&unread=hey'>Decline</a>" for message in orderedMessages: if message.viewed == False: res += message.display() res += "<a href='messageChain.py?postId=" + \ str(message.id) + "'>View all replies</a>" res += "<br>" res += "<a href='inbox.py?markRead=" + str(message.id) + \ "&unread=hey'>Mark as read</a>" res += '''<form action = "inbox.py" method = "GET"> Reply: <textarea name="replyBody" rows="10" cols="15"> </textarea> <br> <input name="postId" type="hidden" value="''' + str(message.id) + '''"> <input name="reply" type="submit" value="Reply"> </form>''' return res
def displayReadMessages(cookie): res = "<br>" orderedMessages = [] currentUser = cookie["username"].value userDict = stdStuff.objFileToList(stdStuff.directory, stdStuff.userFile, byName=True) res += \ "<a href='inbox.py?markUnread=all&read=hey'>Mark all as unread</a><br><br>" for message in userDict[currentUser].inbox.messages: orderedMessages.append(message) orderedMessages.sort(key=lambda x: x.id, reverse=True) for message in orderedMessages: if message.viewed == True: res += message.display() res += "<a href='inbox.py?markUnread=" + str(message.id) + \ "&read=hey'>Mark as unread</a>" return res
def writeComment(targId, currentUser, commentText): userDict = stdStuff.objFileToList(stdStuff.directory, stdStuff.userFile, byName=True) counter = stdStuff.getCounter() for post in userDict[currentUser].posts: if post.id == targId: post.addComment(counter, currentUser, commentText) stdStuff.objListToFile(userDict, stdStuff.directory, stdStuff.userFile, isDict=True) stdStuff.setCounter(counter) return for friend in userDict[currentUser].friends: for post in userDict[friend].posts: if post.id == targId: post.addComment(counter, currentUser, commentText) stdStuff.objListToFile(userDict, stdStuff.directory, stdStuff.userFile, isDict=True) stdStuff.setCounter(counter) return
def makePage(): res = str(poster()) #not sure why it doesnt work postList = stdStuff.objFileToList(directory, postFile) ''' postReadStream = open(directory + postFile, "rb") postList = [] try: while True: postList.append(pickle.load(postReadStream)) except EOFError: print "End of File" finally: postReadStream.close() ''' for post in postList: res += displayPost(post, "h1", "p", "h6") return res
form = cgi.FieldStorage() body = '' foot = '''</body> <html>''' #print currentGroup f = open(directory + stdStuff.groupFile, 'r') groupList = f.read() f.close() userDict = stdStuff.objFileToList(stdStuff.directory, stdStuff.userFile, byName=True) groupDict = stdStuff.objFileToList(stdStuff.directory, stdStuff.groupFile, byName=True) userList = stdStuff.objFileToList(stdStuff.directory, stdStuff.userFile) groupList = stdStuff.objFileToList(stdStuff.directory, stdStuff.groupFile) def authenticate(u,ID,IP): loggedIn = open(stdStuff.directory + stdStuff.logFile,'r').read().split('\n') loggedIn = [each.split(',') for each in loggedIn] loggedIn.remove(['']) for a in loggedIn: if a[0] == username: return a[1]==str(ID) and a[2]==IP return False
</form> """ if "expandButton" in form: temp = int(form.getvalue("expandButton")) lol = open(stdStuff.directory + stdStuff.postIdFile, "w") lol.write(str(temp)) lol.close() lol = open(stdStuff.directory + stdStuff.postIdFile, "r") targId = int(lol.read()) lol.close() if "done" in form: writeComment(form.getvalue("comment"), c, targId) allPosts = stdStuff.objFileToList(stdStuff.directory, stdStuff.postFile) for x in allPosts: if x.id == targId: body += displayPost(x, "h1", "p", "h3", "p") break body += """<a href="profile.py">Go back to profile</a>""" else: body += "Failed to Authenticate cookie<br>\n" body += 'Go Login <a href="login.py">here</a><br>' else: body += "Your information expired<br>\n" body += 'Go Login <a href="login.py">here</a><br>' else: body += 'You seem new<br>\n' body += 'Go Login <a href="login.py">here</a><br>'
head = \ ''' <!DOCTYPE html> <html> <head><title>Profile</title> </head> <body> ''' body = "" foot = \ ''' </body> </html> ''' thing = stdStuff.objFileToList(stdStuff.directory, stdStuff.userFile) for user in thing: print user.displayPosts() print head print body print foot
<html> <head> <link rel="stylesheet" type="text/css" href="../style/groupsPage.css">''' body = '' foot = '''</body> <html>''' #print currentGroup f = open(directory + stdStuff.groupFile, 'r') groupList = f.read() f.close() userDict = stdStuff.objFileToList(stdStuff.directory, stdStuff.userFile, byName=True) groupDict = stdStuff.objFileToList(stdStuff.directory, stdStuff.groupFile, byName=True) userList = stdStuff.objFileToList(stdStuff.directory, stdStuff.userFile) groupList = stdStuff.objFileToList(stdStuff.directory, stdStuff.groupFile) def authenticate(u,ID,IP): loggedIn = open(stdStuff.directory + stdStuff.logFile,'r').read().split('\n') loggedIn = [each.split(',') for each in loggedIn] loggedIn.remove(['']) for a in loggedIn: if a[0] == username: return a[1]==str(ID) and a[2]==IP return False
""" if "expandButton" in form: temp = int(form.getvalue("expandButton")) lol = open(stdStuff.directory + stdStuff.postIdFile, "w") lol.write(str(temp)) lol.close() lol = open(stdStuff.directory + stdStuff.postIdFile, "r") targId = int(lol.read()) lol.close() if "done" in form: writeComment(form.getvalue("comment"), c, targId) allPosts = stdStuff.objFileToList(stdStuff.directory, stdStuff.postFile) for x in allPosts: if x.id == targId: body += displayPost(x, "h1", "p", "h3", "p") break body += """<a href="profile.py">Go back to profile</a>""" else: body+="Failed to Authenticate cookie<br>\n" body+= 'Go Login <a href="login.py">here</a><br>' else: body+= "Your information expired<br>\n" body+= 'Go Login <a href="login.py">here</a><br>' else: body+= 'You seem new<br>\n' body+='Go Login <a href="login.py">here</a><br>'
body += "Logged in as: " + username body += """<form method="GET" action="homepage.py"> <input name="logOut" type="submit" value="Log out"> </form> <form method="GET" action="addFriend.py"> <input name="addFriend" type="submit" value="Add a friend"> </form> """ if "postTitle" in form: writePost(c, form) if "downVote" in form or "upVote" in form: targId = int(form.getvalue("postId")) targName = c["username"].value userDict = stdStuff.objFileToList(stdStuff.directory, stdStuff.userFile, byName=True) if "downVote" in form: for index, value in enumerate(userDict[targName].posts): if value.id == targId: userDict[targName].posts[index].decreaseScore() break elif "upVote" in form: for index, value in enumerate(userDict[targName].posts): if value.id == targId: userDict[targName].posts[index].increaseScore() break stdStuff.objListToFile(userDict, stdStuff.directory, stdStuff.userFile, isDict=True) body+=makePage(c)
def displayPost(id, currentUser, titleTag, bodyTag, userTag, commentTag): res = "" userDict = stdStuff.objFileToList(stdStuff.directory, stdStuff.userFile, byName=True) for post in userDict[currentUser].posts: if post.id == id: res += post.display() res += "<br><h3>Comments</h3><br>" for comment in post.comments: res += """<table> <tr> <td>""" + str(comment.score) + """</td> <td> """ res += comment.display() res += "<a href='postExpanded.py?downVote=lol&commentId="+\ str(comment.id) + "&postId=" + str(post.id) + "'>Down Vote</a><br>" res += "<a href='postExpanded.py?upVote=lol&commentId="+\ str(comment.id) + "&postId=" + str(post.id) + "'>Up Vote</a><br>" res += "<a href='postExpanded.py?removeVote=lol&commentId="+\ str(comment.id) + "&postId=" + str(post.id) + "'>Remove Vote</a><br>" res += """</td> </tr> </table> """ return res for friend in userDict[currentUser].friends: for post in userDict[friend].posts: if post.id == id: res += post.display() res += "<br><h3>Comments</h3><br>" for comment in post.comments: res += """<table> <tr> <td>""" + str(comment.score) + """</td> <td> """ res += comment.display() res += "<a href='postExpanded.py?downVote=lol&commentId="+\ str(comment.id) + "&postId=" + str(post.id) + "'>Down Vote</a><br>" res += "<a href='postExpanded.py?upVote=lol&commentId="+\ str(comment.id) + "&postId=" + str(post.id) + "'>Up Vote</a><br>" res += "<a href='postExpanded.py?removeVote=lol&commentId="+\ str(comment.id) + "&postId=" + str(post.id) + "'>Remove Vote</a><br>" res += """</td> </tr> </table> """ return res return res
cgitb.enable() sys.path.insert(0, "../modules") import stdStuff head = \ ''' <!DOCTYPE html> <html> <head><title>Profile</title> </head> <body> ''' body = "" foot = \ ''' </body> </html> ''' thing = stdStuff.objFileToList(stdStuff.directory, stdStuff.userFile) for user in thing: print user.displayPosts() print head print body print foot
head = \ ''' <!DOCTYPE html> <html> <head><title>Profile</title> </head> <body> ''' body = "" foot = \ ''' </body> </html> ''' thing = stdStuff.objFileToList(stdStuff.directory, stdStuff.userFile, byName=True) stdStuff.objListToFile(thing, stdStuff.directory, stdStuff.userFile, isDict=True) lol = stdStuff.objFileToList(stdStuff.directory, stdStuff.userFile, byName=True) for x in lol: print lol[x].password print head print body print foot
def displayPost(id, cookie, titleTag, bodyTag, userTag, commentTag): res = "" groupList = stdStuff.objFileToList(stdStuff.directory, stdStuff.groupFile) for x in groupList: if (x.name == currentGroup): for post in x.posts: if post.id == id: res += "<div id='post'>" res += post.display() res += "<br><h3>Comments</h3><br>" for comment in post.comments: res += """<table class="comment"> <tr> <td>""" + str(comment.score) + """</td> <td> """ res += comment.display() res += "<a href='groupExpanded.py?downVote=lol&commentId="+\ str(comment.id) + "&postId=" + str(post.id) + "'>Down Vote</a><br>" res += "<a href='groupExpanded.py?upVote=lol&commentId="+\ str(comment.id) + "&postId=" + str(post.id) + "'>Up Vote</a><br>" res += "<a href='groupExpanded.py?removeVote=lol&commentId="+\ str(comment.id) + "&postId=" + str(post.id) + "'>Remove Vote</a><br>" res += """</td> </tr> </table> """ res += "</div>" break if 'searchUserPost' in form: for x in groupList: if (x.name == searchUserPost): for post in x.posts: if post.id == id: res += post.display() res += "<br><h3>Comments</h3><br>" for comment in post.comments: res += """<table> <tr> <td>""" + str(comment.score) + """</td> <td> """ res += comment.display() res += "<a href='groupExpanded.py?downVote=lol&commentId="+\ str(comment.id) + "'&postId='" + str(post.id) + "'>Down Vote</a><br>" res += "<a href='groupExpanded.py?upVote=lol&commentId="+\ str(comment.id) + "'&postId='" + str(post.id) + "'>Up Vote</a><br>" res += "<a href='groupExpanded.py?removeVote=lol&commentId="+\ str(comment.id) + "'&postId='" + str(post.id) + "'>Remove Vote</a><br>" res += """</td> </tr> </table> """ break return res
c.load(cookie_string) ##print all the data in the cookie #body+= "<h1>cookie data</h1>" #for each in c: # body += each+":"+str(c[each].value)+"<br>" if 'username' in c and 'ID' in c: username = c['username'].value ID = c['ID'].value IP = os.environ['REMOTE_ADDR'] if authenticate(username,ID,IP): currentUser = c["username"].value userDict = stdStuff.objFileToList(stdStuff.directory, stdStuff.userFile, byName=True) body += "Logged in as: " + currentUser body += """<form method="GET" action="homepage.py"> <input name="logOut" type="submit" value="Log out"> </form> <a href="profile.py">Go back to profile</a> """ body += makePage() if "search" in form: body += displayUserList(form.getvalue("userTarget"), userDict) body += """<br><br><a href="profile.py">Go back to profile</a>""" else: body+="Failed to Authenticate cookie<br>\n"
<!DOCTYPE html> <html> <head><title>Profile</title> </head> <body> ''' body = "" foot = \ ''' </body> </html> ''' thing = stdStuff.objFileToList(stdStuff.directory, stdStuff.userFile, byName=True) stdStuff.objListToFile(thing, stdStuff.directory, stdStuff.userFile, isDict=True) lol = stdStuff.objFileToList(stdStuff.directory, stdStuff.userFile, byName=True) for x in lol: print lol[x].password print head print body