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." })
return json.dumps({'success' : False, 'message' : 'you are not signed in'}) if database_helper.existsUser(email): user = database_helper.getUser(email) return json.dumps({'success' : True, 'user' : user}) else: return json.dumps({'success' : False, 'message' : 'no such user'}) @app.route('/getmessagetoken') def getUserMessagesByToken(): #Returns an array containing all messages sent to user token = request.args.get('token') try: email = loggedInUsers[token] except Exception, e: return json.dumps({'success' : False, 'message' : 'you are not signed in'}) messages = database_helper.getMessages(email) return json.dumps({'success' : True , 'messages' : messages}) @app.route('/getmessageemail') def getUserMessagesByEmail(): #Same as above for the email-user token = request.args.get('token') email = request.args.get('email') try: loggedInUser = loggedInUsers[token] except Exception, e: return json.dumps({'success' : False, 'message' : 'you are not signed in'}) if database_helper.existsUser(email): messages = database_helper.getMessages(email) return json.dumps({'success' : True, 'messages' : messages}) else:
def getUserMessages(email): dbRet = database_helper.getMessages(email) return jsonify(success = True, message = "Returning messages", data = dbRet)