def getUserData(token, userEmail): if database_helper.userSignedIn(token): if database_helper.userExists(userEmail): currentEmail = database_helper.getEmail(token) if not currentEmail == userEmail: print "inte samma så ökar" database_helper.incrementViews(userEmail) print "wsdict: " + str(wsDict) print "userviewdict : " + str(usersViewing) for user in usersViewing: wsDict.get(user).send("updateWall") userData = database_helper.getUserData(userEmail) usersViewing[currentEmail] = userEmail return json.dumps({ "success": True, "message": "User data retrieved.", "data": userData }) else: return json.dumps({"success": False, "message": "Nu such user."}) else: return json.dumps({ "success": False, "message": "You are not signed in." })
def postMessage(): if request.method == 'POST': token = request.form['token'] content = request.form['content'] toEmail = request.form['toEmail'] if database_helper.userSignedIn(token): if database_helper.userExists(toEmail): if database_helper.postMessage(token, content, toEmail): print "userviewing dict: " + str(usersViewing) for user in usersViewing: # fix this for later #print "usersviewing[user]: " + str(usersViewing[user]) #if usersViewing[user] == toEmail: print "getting: " + str(wsDict.get(user)) wsDict.get(user).send("updateWall") return json.dumps({ "success": True, "message": "Message posted." }) else: return json.dumps({ "success": False, "message": "Failed to post message" }) else: return json.dumps({ "success": False, "message": "Nu such user." }) else: return json.dumps({ "success": False, "message": "You are not signed in" })
def postMessage(): if request.method == 'POST': token = request.form['token'] content = request.form['content'] toEmail = request.form['toEmail'] if database_helper.userSignedIn(token): if database_helper.userExists(toEmail): if database_helper.postMessage(token, content, toEmail): return json.dumps({ "success": True, "message": "Message posted." }) else: return json.dumps({ "success": False, "message": "Failed to post message" }) else: return json.dumps({ "success": False, "message": "Nu such user." }) else: return json.dumps({ "success": False, "message": "You are not signed in" })
def getMessages(token, userEmail): if database_helper.userSignedIn(token): if database_helper.userExists(userEmail): messages = database_helper.getMessages(userEmail) return json.dumps({ "success": True, "message": "User messages retrieved.", "data": messages }) else: return json.dumps({"success": False, "message": "Nu such user."}) else: return json.dumps({ "success": False, "message": "You are not signed in." })
def getUserData(token, userEmail): if database_helper.userSignedIn(token): if database_helper.userExists(userEmail): userData = database_helper.getUserData(userEmail) return json.dumps({ "Success": True, "message": "User data retrieved.", "data": userData }) else: return json.dumps({"Success": False, "message": "Nu such user."}) else: return json.dumps({ "Success": False, "message": "You are not signed in." })
def signOut(): if request.method == 'POST': token = request.form['token'] email = database_helper.getEmail(token) if not database_helper.userExists(email): return json.dumps({ "Success": False, "message": "No such user logged in." }) if database_helper.signOut(token): return json.dumps({ "Success": True, "message": "Successfully logged out." }) else: return json.dumps({ "Success": False, "message": "Could not log out." })