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 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)
elif comment.votedUsers[targName] == \ "downVote": comment\ .votedUsers[targName] = "noVote" comment.increaseScore() break stdStuff.objListToFile(userDict, stdStuff.directory, stdStuff.userFile, isDict=True) if "done" in form: writeComment(targId, username, stdStuff.deleteBrackets(form.getvalue("comment"))) body += displayPost(targId, c["username"].value, "", "", "", "") body += poster() 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>' print head
<form method="GET" action="addFriend.py"> <input name="addFriend" type="submit" value="Add a friend"> </form> <a href="profile.py">Go back to profile</a> <br> <a href="inbox.py">Go back to inbox</a> """ body += makePage(c) if "reply" in form: replyId = int(form.getvalue("postId")) for message in userDict[currentUser].inbox.messages: if message.id == replyId: message.reply( stdStuff.deleteBrackets( form.getvalue("replyBody")), userDict, currentUser) stdStuff.objListToFile(userDict, stdStuff.directory, stdStuff.userFile, isDict=True) break if "postId" in form: postId = int(form.getvalue("postId")) body += displayMessageAndReplies(userDict, currentUser, postId) body += '<a href="profile.py">Go back to profile</a>' else: body += "Failed to Authenticate cookie<br>\n"
<div id="userButtons"> <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> <a href="profile.py">Go back to profile</a> </div> </div> """ #for the fixed post body += "<div id='userHeader2'></div>" if "sendMessage" in form: recipient = stdStuff.deleteBrackets( form.getvalue("messageTarget")) try: userDict[currentUser].inbox.sendMessage( recipient, stdStuff.deleteBrackets(form.getvalue("messageTitle")), stdStuff.deleteBrackets(form.getvalue("messageBody"))) except KeyError: body += "<h1>" + recipient + " is not a registered user</h1>" except AttributeError: body += "<h1>Message failed to send, please try again</h1>" if "markRead" in form: targetMessage = form.getvalue("markRead") if targetMessage == "all": for message in userDict[currentUser].inbox.messages: if type(message) is stdStuff.Message:
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> <form method="GET" action="addFriend.py"> <input name="addFriend" type="submit" value="Add a friend"> </form> <a href="profile.py">Go back to profile</a> """ if "sendMessage" in form: recipient = stdStuff.deleteBrackets( form.getvalue("messageTarget")) try: userDict[currentUser].inbox.sendMessage( recipient, stdStuff.deleteBrackets(form.getvalue("messageTitle")), stdStuff.deleteBrackets(form.getvalue("messageBody"))) except KeyError: body += "<h1>" + recipient + " is not a registered user</h1>" except AttributeError: body += "<h1>Message failed to send, please try again</h1>" if "markRead" in form: targetMessage = int(form.getvalue("markRead")) if targetMessage == "all": for message in userDict[currentUser].inbox.messages: if type(message) is stdStuff.Message:
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> """ if "requestFriend" in form: body += sendFriendRequest(form, userDict, currentUser) body += makePage(c) if "search" in form: body += displayUserList(stdStuff.deleteBrackets(form.getvalue("userTarget")), userDict, currentUser) body += """<br><br><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>' print head print body print foot
while True: userList.append(pickle.load(userReadStream)) except EOFError: #print "End of File" pass finally: userReadStream.close() if nameIsAvailable(userList, form.getvalue("username")): with open(stdStuff.directory + stdStuff.userFile, "a") \ as userWriteStream: userWriteStream = \ open(stdStuff.directory + stdStuff.userFile, "a") pickle.dump( stdStuff.User( stdStuff.deleteBrackets(form.getvalue("username")), hashlib.sha256(form.getvalue("password")).hexdigest()), userWriteStream) body += \ 'Successfully added. <a href="login.py"> Click here to log in</a>.<br>' else: body += 'Username already taken!' else: body += "Please use the form!" print head print body print foot
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> """ if "requestFriend" in form: body += sendFriendRequest(form, userDict, currentUser) body += makePage(c) if "search" in form: body += displayUserList( stdStuff.deleteBrackets(form.getvalue("userTarget")), userDict, currentUser) body += """<br><br><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>' print head print body print foot
"downVote": comment\ .votedUsers[targName] = "noVote" comment.increaseScore() break stdStuff.objListToFile(userDict, stdStuff.directory, stdStuff.userFile, isDict=True) if "done" in form: writeComment(targId, username, stdStuff.deleteBrackets(form.getvalue("comment"))) body += displayPost(targId, c["username"].value, "", "", "", "") body += poster() 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>'
userList.append(pickle.load(userReadStream)) except EOFError: #print "End of File" pass finally: userReadStream.close() if nameIsAvailable(userList, form.getvalue("username")): with open(stdStuff.directory + stdStuff.userFile, "a") \ as userWriteStream: userWriteStream = \ open(stdStuff.directory + stdStuff.userFile, "a") pickle.dump( stdStuff.User( stdStuff.deleteBrackets(form.getvalue("username")), hashlib.sha256(form.getvalue("password")) .hexdigest()), userWriteStream) body += \ 'Successfully added. <a href="login.py"> Click here to log in</a>.<br>' else: body += 'Username already taken!' else: body += "Please use the form!" print head print body print foot
stdStuff.objListToFile( groupList, stdStuff.directory, stdStuff.groupFile, ) if form.getvalue('done') == "Change Visibility": for group in groupList: if group.name == currentGroup: group.changeVisibility(form.getvalue('visibility')) stdStuff.objListToFile( groupList, stdStuff.directory, stdStuff.groupFile, ) if form.getvalue('done') == "Change Name": groupName = stdStuff.deleteBrackets( form.getvalue('groupName')) for group in groupList: if group.name == currentGroup: if groupName in groupDict.keys(): global groupStatus groupStatus = "Group name is already taken. Group name has not been changed." else: group.changeName(groupName) f = open(directory + stdStuff.currentGroupFile, 'w') f.write(groupName) f.close() f = open(directory + stdStuff.currentGroupFile, 'r') currentGroup = f.read() f.close()
f.close() #append the line to the file f = open(filename, 'a') f.write(username + "," + str(number) + "," + str(IP) + "\n") f.close() def createCookie(c, username, ID): c['username'] = username c['ID'] = ID c['username']['expires'] = USER_EXPIRE_TIME c['ID']['expires'] = PASSWORD_EXPIRE_TIME if 'username' in form and 'password' in form: username = stdStuff.deleteBrackets(form.getvalue('username')) password = form.getvalue('password') if authenticate(username, password): import os, random IP = os.environ['REMOTE_ADDR'] ID = random.randint(1000000, 9999000) #print some debug info at the top of the page: #body += "Success!<br>" #body += "Random Number: "+str(ID)+"<br>" #body += "IP: "+ IP + "<br>" #write to a file writeOrReplace(stdStuff.directory + stdStuff.logFile, username, ID, IP) #create a cookie:
stdStuff.objListToFile(groupList, stdStuff.directory, stdStuff.groupFile,) if form.getvalue('done') == "Kick Member": for group in groupList: if group.name == currentGroup: group.kickMember(form.getvalue('kickMember')) stdStuff.objListToFile(groupList, stdStuff.directory, stdStuff.groupFile,) if form.getvalue('done') == "Change Visibility": for group in groupList: if group.name == currentGroup: group.changeVisibility(form.getvalue('visibility')) stdStuff.objListToFile(groupList, stdStuff.directory, stdStuff.groupFile,) if form.getvalue('done') == "Change Name": groupName = stdStuff.deleteBrackets(form.getvalue('groupName')) for group in groupList: if group.name == currentGroup: if groupName in groupDict.keys(): global groupStatus groupStatus = "Group name is already taken. Group name has not been changed." else: group.changeName(groupName) f = open(directory + stdStuff.currentGroupFile, 'w') f.write(groupName) f.close() f = open(directory + stdStuff.currentGroupFile, 'r') currentGroup = f.read() f.close() stdStuff.objListToFile(groupList, stdStuff.directory, stdStuff.groupFile,)
<form method="GET" action="addFriend.py"> <input name="addFriend" type="submit" value="Add a friend"> </form> <a href="profile.py">Go back to profile</a> <br> <a href="inbox.py">Go back to inbox</a> """ body += makePage(c) if "reply" in form: replyId = int(form.getvalue("postId")) for message in userDict[currentUser].inbox.messages: if message.id == replyId: message.reply( stdStuff.deleteBrackets(form.getvalue("replyBody")), userDict, currentUser) stdStuff.objListToFile(userDict, stdStuff.directory, stdStuff.userFile, isDict=True) break if "postId" in form: postId = int(form.getvalue("postId")) body += displayMessageAndReplies(userDict, currentUser, postId) body += '<a href="profile.py">Go back to profile</a>'
f.write(res) f.close() #append the line to the file f = open(filename,'a') f.write(username+","+str(number)+","+str(IP)+"\n") f.close() def createCookie(c,username,ID): c['username']=username c['ID']=ID c['username']['expires']=USER_EXPIRE_TIME c['ID']['expires']=PASSWORD_EXPIRE_TIME if 'username' in form and 'password' in form: username = stdStuff.deleteBrackets(form.getvalue('username')) password = form.getvalue('password') if authenticate(username,password): import os,random IP = os.environ['REMOTE_ADDR'] ID = random.randint(1000000,9999000) #print some debug info at the top of the page: #body += "Success!<br>" #body += "Random Number: "+str(ID)+"<br>" #body += "IP: "+ IP + "<br>" #write to a file writeOrReplace(stdStuff.directory + stdStuff.logFile,username,ID,IP) #create a cookie: