def get_user_data_by_email(token, email): if token not in logged_in_users: return jsonify({"success": False, "message": "You're not signed in"}) else: if database_helper.userExist(email): data = database_helper.get_user_data(email) return jsonify({"success": True, "message": "Information retrieved", "data": data}) else: return jsonify({"success": False, "message": "User don't exist"})
def get_user_message_by_email(token, email): if token not in logged_in_users: return jsonify({"success": False, "message": "Not logged in!"}) else: if database_helper.userExist(email): data = database_helper.get_user_messages(email) return jsonify({"success": True, "message": "Messages retrieved", "data": data}) else: return jsonify({"success": False, "message": "User don't exist"})
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 sign_up(): email = request.form['email'] password = request.form['password'] first_name = request.form['first_name'] family_name = request.form['family_name'] gender = request.form['gender'] city = request.form['city'] country = request.form['country'] if database_helper.userExist(email): return jsonify({"success": False, "message": "User already exists!"}) else: database_helper.sign_up_user(email, password, first_name, family_name, gender, city, country) return jsonify({"success": True, "message": "User created!"})
def add_views(): user_token = request.form['token'] user_email = request.form['email'] if user_token in logged_in_users and database_helper.userExist(user_email): database_helper.add_view(user_email) if user_email in active_sockets: return_data = { "type": "userdata", "views": database_helper.get_views(user_email), "usersonline": len(logged_in_users), "messagecount": len(database_helper.get_user_messages(user_email)) } active_sockets[user_email].send(json.dumps(return_data)) return jsonify({"success": True, "messages": "Added view"}) else: return jsonify({"success": False, "messages": "Non added"})
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"})