def post_message(): token = request.json['token'] message = request.json['message'] email = request.json['email'] logged = database_helper.user_logged_by_token(token=token) if logged: # user logged if not email == "": exists = database_helper.user_in_database(email=email) if exists: # target user exists database_helper.post_message(token=token, message=message, email=email) send_notification() return json.dumps({'success': True, 'message': 'Message posted'}) else: return json.dumps({'success': False, 'message': 'User not in the database'}) else: return database_helper.post_message(token=token, message=message, email=email) else: return json.dumps({'success': False, 'message': 'User not logged'}) #if __name__ == '__main__': # app.run(debug=True)
def post_message(): token = request.form['token'] message = request.form['message'] toEmail = request.form['email'] fromEmail = database_helper.get_email_by_token(token) toUser = database_helper.get_user_by_email(toEmail) #check if fromEmail is signed in if (fromEmail): if (toUser is None): return jsonify(success = False, message = "No such user.") else: try: database_helper.post_message(fromEmail[0], toEmail, message); # Update chart if (toEmail == fromEmail[0]): print "PM EQUALS............." live_data(fromEmail[0], {"id": "update_chart", "online": -1, "sent": database_helper.get_num_messages_sent(fromEmail[0])[0], "received": database_helper.get_num_messages_received(toEmail)[0]}) else: print "PM NO EQ............." live_data(fromEmail[0], {"id": "update_chart", "online": -1, "sent": database_helper.get_num_messages_sent(fromEmail[0])[0], "received":-1}) live_data(toEmail, {"id": "update_chart", "online":-1, "sent": -1, "received": database_helper.get_num_messages_received(toEmail)[0]}) return jsonify(success = True, message = "Message posted.") # Catching IntegrityError except sqlite3.IntegrityError: return jsonify(success = False, message = "This message is already posted.") else: return jsonify(success = False, message = "You are not logged in.")
def post_message(): email = request.form["email"] message = request.form["message"] user_email = request.form["user_email"] time_stamp = request.form["time"] blob = message + user_email + email if check_hash(blob, email, request.form["hash"], time_stamp): return json.dumps({ 'success': False, 'message': 'You are trying to hack a user. You should be ashamed of yourself!' }) if database_helper.check_email(user_email) is False: return json.dumps({ 'success': False, 'message': 'User does not exist!' }) token = database_helper.get_token(email) if token is None: return json.dumps({ 'success': False, 'message': 'User is not logged in' }) else: if message is "": return json.dumps({ 'success': False, 'message': 'Message cannot be empty' }) else: database_helper.post_message(email, user_email, message) return json.dumps({'success': True, 'message': 'Message posted'})
def post_message(token, message, email): if get_user_data_by_token(token) != None: message = html_escape(message) print message database_helper.post_message(token, message, email) jsonfile = json.dumps({"success": True, "Message": "Message send"}) else: jsonfile = json.dumps({"success": False, "Message": "token error"}) return jsonfile
def post_message(): body = json.loads(request.data.decode("utf-8")) token = body['token'] user = database_helper.email_from_token(token) if user == None: return _return_json_message(False, "User not signed in") database_helper.post_message(user['email'], body['email'], body['message']) _send_total_posts() return _return_json_message(True, "Successfully posted message")
def post_message(token, message, email): user = database_helper.user_signedin(token) if user is None: return json.dumps({"success": False, "message": "You are not signed in."}) if database_helper.user_exist(email) is None: return json.dumps({"success": False, "message": "No such user."}) database_helper.post_message(user[0], email, message) return json.dumps({"success": True, "message": "Message posted"})
def post_message(): token = request.form['token'] email = request.form['email'] message = request.form['message'] if token not in logged_in_users: return jsonify({"success": False, "message": "Not logged in!"}) else: if database_helper.userExist(email): database_helper.post_message(logged_in_users[token], email, message) return jsonify({"success": True, "message": "Message posted"}) else: return jsonify({"success": False, "message": "User don't exist"})
def post_message(): #token, message, toEmail token = request.headers.get('token') fromUser = get_email_by_token(token) #update form IDs toUser = request.form['email'] message = request.form['message'] if token in active_users: database_helper.post_message(toUser, fromUser, message) return json.dumps({"success": "true", "message": "Message posted."}) else: return json.dumps({"success": "false", "message": "User is not signed in."})
def post_message(): message = request.form["message"] token = request.form["token"] email = request.form["email"] if database_helper.get_logged_in(token): if database_helper.in_users(email): database_helper.post_message(token, message, email) return json.dumps({"success": True, "message": "Message posted."}) else: return json.dumps({"success": False, "message": "No such user."}) else: return json.dumps({"success": False, "message": "You are not signed in."})
def post_message(): message = request.form['message'] token = request.form['token'] email = request.form['email'] sender = database_helper.get_email(token)[0] if database_helper.get_logged_in(token): if database_helper.in_users(email): database_helper.post_message(message, token, sender, email) return json.dumps({"success": True, "message": "Message posted."}) else: return json.dumps({"success": False, "message": "No such user."}) else: return json.dumps({"success": False, "message": "You are not signed in."})
def post_message(token, message, email): user = database_helper.user_signedin(token) if user is None: return json.dumps({"success": False, "message": "You are not signed in."}) if database_helper.user_exist(email) is None: return json.dumps({"success": False, "message": "No such user."}) for item in userList: if item[1] == email: item[0].send(json.dumps({"sender": user[0], "content": message})) database_helper.post_message(user[0], email, message) return json.dumps({"success": True, "message": "Message posted"})
def post_message(): """Post message Posts a message to given other users wall or own wall """ data = request.get_json() token = request.headers.get('token') receiver = data['receiver'] message = data['postedMessage'] if message == None: res = jsonify({'success': False, 'message': 'No message'}) return res result = database_helper.post_message(token, receiver, message) if token is not None: if result == True: push_websocket_total_posts() res = jsonify({ 'success': True, 'message': 'Message posted', 'receiver': receiver }) print("successfully posted message: ", message, 'to receiver: ', receiver) else: res = jsonify({ 'success': False, 'message': 'Posting message failed!' }) print("result is false in post message") else: res = jsonify({'success': False, 'message': 'Invalid token!'}) return res
def post_message(token, content, toEmail): fromEmail = database_helper.token_to_email(token) if (fromEmail != ""): if (toEmail == ""): toEmail = fromEmail if(toEmail != ""): message = {"receiver": toEmail, "writer": fromEmail, "content": content} database_helper.post_message(message) #return {"success": "true", "message": "Message posted"} return "Message posted" else: #return {"success": "false", "message": "No such user."} return "No such user." else: #return {"success": "false", "message": "You are not signed in."} return "You are not signed in."
def post_message(): token = get_param_or_default("token") receiver = get_param_or_default("email") message = get_param_or_default("message") if db.is_connected(token): sender = db.get_email(token)[0] if db.find_user(receiver) != None: if message != "": db.post_message(sender, receiver, message) success(SUC_MESSAGE_POSTED) else: err(ERR_EMPTY_MESSAGE) else: err(ERR_USER_NOT_FOUND) else: err(ERR_USER_NOT_CONNECTED) return json.dumps(output)
def post_message(): message = request.form['message'] email = request.form['mail'] mailUser = request.form['mailUser'] timestamp = request.form['timestamp'] sender = mailUser if database_helper.get_logged_in_by_mail(mailUser): if database_helper.in_users(email): #Secure way to transmission of data if check_tok_post("postmessage",request): token = database_helper.get_token_by_mail(sender)[0] database_helper.post_message(message, token, sender, email) return json.dumps({"success": True, "message": "Message posted."}) else: return json.dumps({"success": False, "message": "Message not posted."}) else: return json.dumps({"success": False, "message": "You are not signed in."})
def post_message(): token = request.values.get('token') message = request.values.get('message') reciever = request.values.get('email') sender = database_helper.get_user_by_token(token) if(token != None and message != None and reciever != None): if len(sender) > 0: tmp = database_helper.get_user_by_email(reciever) if len(tmp) > 0: database_helper.post_message(sender[0][0], reciever, message) return jsonify(success = True, message = "Successfully posted message") else: return jsonify(success = False, message = "No such user") else: return jsonify(success = False, message = "You're not signed in") else: return jsonify(success = False, message = "Wrong input data")
def post_message(): token = request.values.get("token") message = request.values.get("message") reciever = request.values.get("email") sender = database_helper.get_user_by_token(token) if token != None and message != None and reciever != None: if len(sender) > 0: tmp = database_helper.get_user_by_email(reciever) if len(tmp) > 0: print "sender: " + sender[0][0] + " reciever: " + reciever + " message: " + message database_helper.post_message(sender[0][0], reciever, message, "no") return jsonify(success=True, message="Successfully posted message") else: return jsonify(success=False, message="No such user") else: return jsonify(success=False, message="You're not signed in") else: return jsonify(success=False, message="Wrong input data")
def post_message(): token = request.form.get('token') email = request.form.get('email') message = request.form.get('message') post = dh.post_message(token, email, message) if post is None: return json.dumps({"success": "false", "message": "No such user."}) else: return json.dumps({"success": "true", "message": "Message posted"})
def post_message(): token = request.form.get('token') email = request.form.get('email') message = request.form.get('message') post = dh.post_message(token, email, message) if post is None: return json.dumps({"success": "false", "message":"No such user."}) else: return json.dumps({"success": "true", "message": "Message posted"})
def post_message(): token = request.form['token'] message = request.form['message'] toEmail = request.form['email'] fromEmail = database_helper.get_email_by_token(token) toUser = database_helper.get_user_by_email(toEmail) #check if fromEmail is signed in if (fromEmail): if (toUser is None): return jsonify(success = False, message = "No such user.") else: try: database_helper.post_message(fromEmail[0], toEmail, message); return jsonify(success = True, message = "Message posted.") # Catching IntegrityError except sqlite3.IntegrityError: return jsonify(success = False, message = "This message is already posted.") else: return jsonify(success = False, message = "You are not logged in.")
def post_message(): data = request.get_json() token = request.headers.get('token') if token and 'content' in data and 'email' not in data and database_helper.check_token(token): email = database_helper.get_email_from_token(token) writer = email result = database_helper.post_message(email, writer, data['content']) if result == True: return json.dumps({"success": "true", "message": "Message posted"}), 200 else: return json.dumps({"success": "false", "message": "Something went wrong!"}), 500 elif token and 'email' in data and 'content' in data and database_helper.check_token(token): writer = database_helper.get_email_from_token(token) result = database_helper.post_message(data['email'], writer, data['content']) if result == True: return json.dumps({"success": "true", "message": "Message posted"}), 200 else: return json.dumps({"success": "false", "message": "Something went wrong!"}), 500 else: return json.dumps({"success": "false", "message": "Missing field"}), 400
def upload_file(): if request.method == "POST": print "[upload_file] entered" token = request.values.get("token") message = request.values.get("message") reciever = request.values.get("reciever") sender = database_helper.get_user_by_token(token) file = request.files["upload_file"] print "[upload_file] data retrieved" if token != None and reciever != None: if len(sender) > 0: tmp = database_helper.get_user_by_email(reciever) if len(tmp) > 0: characters = "abcdefghiklmnopqrstuvwwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890" name = "" for i in range(0, 35): name += characters[randint(0, len(characters) - 1)] print "[upload_file] name generated" print "[upload_file] message posted" if file and allowed_file(file.filename): print "[upload_file] inside if before split" print file.filename filetype = file.filename.rsplit(".", 1)[1] print filetype print "[upload_file] filename splitted" message = name + "." + filetype file.save(os.path.join(app.root_path, app.config["UPLOAD_FOLDER"], message)) print "[upload_file] save file" print "sender: " + sender[0][0] + " reciever: " + reciever + " message: " + message database_helper.post_message(sender[0][0], reciever, message, filetype) print "[upload_file] save to database" return jsonify(success=True, message="File uploaded and shared!") else: return jsonify(success=False, message="No such user") else: return jsonify(success=False, message="You're not signed in") else: return jsonify(success=False, message="Wrong input data") return ""
def post_message(): token = request.form['token'] email = request.form['email'] message = request.form['message'] if token not in logged_in_users: return jsonify({"success": False, "message": "Not logged in!"}) else: if database_helper.userExist(email): database_helper.post_message(logged_in_users[token], email, message) if email in active_sockets: return_data = { "type": "userdata", "views": database_helper.get_views(email), "usersonline": len(logged_in_users), "messagecount": len(database_helper.get_user_messages(email)) } active_sockets[email].send(json.dumps(return_data)) return jsonify({"success": True, "message": "Message posted"}) else: return jsonify({"success": False, "message": "User don't exist"})
def post_message(): response = {} data = request.json email = database_helper.get_email_by_token(data['token']) if email is None: response['success'] = False response['message'] = 'You are not signed in.' else: message = data['message'] target_email = data['email'] if target_email == 'own': target_email = email if database_helper.check_user(target_email,'','exist'): database_helper.post_message(email, target_email,message) response['success'] = True response['message'] = 'Message posted' send_live_data() else: response['success'] = False response['message'] = 'No such user.' return json.dumps(response)
def post_message(): token = request.form['token'] if list_token_id.has_key(token): message = request.form['message'] email = request.form['email'] result = database_helper.post_message(list_token_id.get(token),message,email) if result == False: return return_json(404,False,'unknown receiver') else: updateMessages(email) return return_json(200,True,'message sent') else: return return_json(403,False,'user not connect')
def post_message(): try: token = request.headers.get('token') data = request.get_json() except: return ("Could not get header token") try: email = data['email'] message = data['message'] except: #print(data['email'], " ", data['message']) return ("Could not get JSON-data") #return database_helper.post_message(token,email,message) user_exist = database_helper.exist_user(email) if (user_exist is not None and database_helper.exist_user_token(token)): #receiving_user = logged_in_users[email] if (user_exist): database_helper.post_message(token, email, message) return jsonify({"success": True, "message": "Message posted"}) else: return jsonify({"success": False, "message": "No such user."}) else: return jsonify({"success": False, "message": "You are not signed in."})
def sendmessage(): data = request.get_json() #have to send in token as json string for now senderToken = request.headers.get( 'token') # Got THROUGH request.header() instead reciever = data['reciever'] message = data['message'] emailSender = database_helper.get_email_by_token(senderToken) if emailSender is None: return jsonify(success=False, message="Cant find email with that token") if database_helper.post_message(message, reciever, emailSender): return jsonify(success=True, message="Sent message") else: return jsonify(success=False, message="Failed to send message")
def post_message(): req = request.get_json(force=True) token = req['token'] # Make sure token is valid from_user = database_helper.get_email(token) if from_user is None: return jsonify(success=False, message="Log in to post a message!") if not database_helper.post_message(req['message'], from_user, req['email']): return jsonify(success=False, message="Failed to post message!") if from_user == req['email']: send_stats(False, from_user) else: send_stats(False, from_user, req['email']) return jsonify(success=True, message="Message posted!")
def post_message(): token = request.form['token'] # Make sure token is valid from_user = database_helper.get_email(token) if from_user is None: return jsonify(success=False, message="Log in to post a message!") message_info = { 'message': request.form['message'], 'from_user': from_user, 'to_user': request.form['email'] } if not database_helper.post_message(message_info): return jsonify(success=False, message="Failed to post message!") return jsonify(success=True, message="Message posted!")
def post_message(): """Post message Posts a message to given other users wall or own wall """ token = request.headers.get('token') data = request.get_json() to = data['email'] message = data['message'] if message == None: res = jsonify({'success': False, 'message': 'No message'}) return res result = database_helper.post_message(token, to, message) if result == True: res = jsonify({'success': True, 'message': 'Message posted'}) return res res = jsonify({'success': False, 'message': 'Something went wrong!'}) return res
def user_post_message(): data = request.get_json() message = data['message'] email = data['email'] if 'Authorization' in request.headers: a_token = request.headers.get('Authorization') sender = database_helper.token_to_email(a_token) if (not database_helper.user_logged_in(a_token)): return create_response(False, 'You are not logged in') elif (not database_helper.user_exists(email)): return create_response(False, "No such user") else: result = database_helper.post_message(email, sender, message) if (result): return create_response(True, "Message posted") return create_response(False, "Something went wrong")
def post_message(): if request.method == 'POST' : token = request.form['token'] message = request.form['message'] receiver = request.form['username'] if database_helper.check_user_exists_token(token): writer = database_helper.get_username_from_token(token) if database_helper.post_message(receiver,writer,message): answer = {"success" : "True", "message" : "Sucessfully posted message " , "data": "" } return json.dumps(answer), 200 else: answer = {"success" : "False", "message" : "Unable to post message " , "data": "" } return json.dumps(answer), 200 else: answer = {"success" : "False", "message" : "You are not logged in anymore" , "data": "" } return json.dumps(answer), 200 else: abort(404)
def post_message(): token = request.headers.get('Token') data = request.get_json() if token is not None and "content" in data and "email" in data: if len(data['email']) <= 30 and len(data['content']) <= 120: result = database_helper.post_message(data['email'], data['content'], token) if result: return json.dumps({ "success": "true", "message": "Message posted to the wall!" }), 200 else: return json.dumps({ "success": "false", "message": "Something went wrong!" }), 500 else: return '', 400 else: return '', 400
def post_message(): data = request.get_json() current_user_token = data['token'] message = data['message'] dest_email = data['email'] if current_user_token != None and dest_email != None: sender_mail = database_helper.get_email_by_token(current_user_token) sender_mail = sender_mail[0] if database_helper.check_if_email_exists( sender_mail) and database_helper.check_if_email_exists( dest_email): success_post = database_helper.post_message( sender_mail, message, dest_email) if success_post: return jsonify({ 'success': True, 'message': "Message posted succesfully" }) else: return jsonify({ 'success': False, 'message': "Something went wrong posting the message" }) else: return jsonify({ 'success': False, 'message': "Provided token or email do not exist" }) else: return jsonify({ 'success': False, 'message': "Token and destination email cannot be void" })
def post_message(): if request.method == 'POST': token = request.form['token'] message = request.form['message'] email = request.form['email'] sender = database_helper.get_email(token) if sender == False: return json.dumps({ 'success': False, 'message': '''Token doesn't exists''' }) if database_helper.user_exists(email) == False: return json.dumps({ 'success': False, 'message': '''Receiver does not exists''' }) result = database_helper.post_message(sender, message, email) if result: return json.dumps({ 'success': True, 'message': '''Message posted successfully''' }) return json.dumps({'success': False, 'message': '''Invalid message'''})
def post_message(): if 'token' in session: #DATABASE check if token is logged in result = database_helper.check_logged_in_user(app, session['token']) if result['success']: token = session['token'] recipient = request.form['recipient'] ## if 36 chars, assuming token inserted. if len(recipient) == 36: recipient = database_helper.token_to_email(app,recipient) message = request.form['message'] result = database_helper.post_message(app, recipient, database_helper.token_to_email(app,token), message) return result["message"] else: return "NO TOKEN IN SESSION"
def post_message(): data = request.get_json() print(data) token = data['token'] message = data['message'] dest_email = data['email'] place = data['place'] public_key = data['publicKey'] authentication_data = database_helper.get_email_logged_user_new(public_key) stored_token = authentication_data['token'] sender_mail = database_helper.get_email_by_token(stored_token) sender_mail = sender_mail[0] equal_hashed_token = False ########################## Token verification ########################## # 1. Recreate the blob using the stored token blob = "" if dest_email != None: i = 0 while i < len(dest_email): blob = blob + dest_email[i] i = i + 3 i = 0 while i < len(message): blob = blob + message[i] i = i + 3 blob = stored_token + blob # 2. Hash it hash = hashlib.sha256(blob.encode()).hexdigest() # 3. Compare the two hashes if token == hash: equal_hashed_token = True print("Equal hashes get_users_data_by_token") ######################################################################## if dest_email == None: dest_email = sender_mail if stored_token != None and dest_email != None: if equal_hashed_token: if database_helper.check_if_email_exists( sender_mail) and database_helper.check_if_email_exists( dest_email): success_post = database_helper.post_message( sender_mail, message, dest_email, place) if success_post: return jsonify({ 'success': True, 'message': "Message posted succesfully" }) else: return jsonify({ 'success': False, 'message': "Something went wrong posting the message" }) else: return jsonify({ 'success': False, 'message': "Provided token or email do not exist" }) else: return jsonify({ 'success': False, 'message': "Hashes not equal in post_message" }) else: return jsonify({ 'success': False, 'message': "Token and destination email cannot be void" })
def post_message(): params = request.json return json.dumps(database_helper.post_message(params))
def post_message(token): email = request.json['email'] message = request.json['message'] dh.post_message(token, email, message) return status('', 'Post posted.', 201)
def post_message(): # Get data from form token = request.json['token'] receiver_email = request.json['receiverEmail'] message = request.json['message'] hashvalue = request.json['hashvalue'] # Create empty dictionary for storing return data data = {} # Check if user with given email exists dataset = database_helper.get_user(receiver_email) if (dataset == None): # Pass error data to dictionary data['success'] = False data['message'] = 'No user with email ' + receiver_email # return the dataset as json data return json.dumps(data) # Check if user is logged in if (is_logged_in(token) == True): # Get user logged_in_user = get_user_by_token(token) sender_email = logged_in_user['email'] privatekey = logged_in_user['privatekey'] # Compare hash values if (hashvalue != hash_data(privatekey + token + message + receiver_email)): data['success'] = False data['message'] = 'Error in hash value' return json.dumps(data) # Save message to database database_helper.post_message(sender_email, receiver_email, message) # Pass success data to dictionary data['success'] = True data['message'] = 'Successfully posted message' # chartjs: Send Update to User if is_logged_in_by_email(receiver_email): user = get_user_by_email(receiver_email) if ('websocket' in user): # Form Data Object chartjs = {} chartjs['success'] = True chartjs['message'] = 'MessageCountChanged' chartjs['data'] = database_helper.get_message_count(receiver_email) # Get Websocket and sent data websocket = user['websocket'] if websocket is not None: websocket.send(json.dumps(chartjs)) # if user is not logged in else: # Pass error data to dictionary data['success'] = False data['message'] = 'Not able to post message' # return the dataset as json data return json.dumps(data)
def post_message(): token = request.args.get('token') email = request.args.get('email') message = request.args.get('message') dh.post_message(token, email, message) return "You have posted a message"