def io(): user_id = request.args.get("user_id") ret_data = [] data = get_p_ip(int(user_id)) for d in data: complex_obj = DObject() complex_obj.id = d.id complex_obj.title = d.title complex_obj.content = d.content ret_data.append(complex_obj.__dict__) return json.dumps(ret_data)
def PostComment(): content = request.json print content CommentObj = DObject() CommentObj.content = content["content"] CommentObj.user_id = decode_auth_token(content['token']) CommentObj.post_id = content["postId"] res, id = InsertComment(CommentObj) print res if res: return json.dumps({"success": True, "id": id}) else: return json.dumps({"success": False, "id": 0})
def PostIntraPost(): content = request.json IntraPostObj = DObject() IntraPostObj.title = content["title"] IntraPostObj.category = content['category'] IntraPostObj.content = content["content"] IntraPostObj.timestamp = datetime.datetime.now() IntraPostObj.user_id = decode_auth_token(content['token']) IntraPostObj.community_id = content["communityId"] IntraPostObj.image_ids = content['image_ids'] #IntraPostObj.post_type = content["postType"] InsertIntraPost(IntraPostObj) return json.dumps({"success": True})
def ForgotPassword(p_uuid=None): if request.method == 'POST': content = request.json user = getUserByEmail(content['email']) if user is not None: ForgotPasswordObj = DObject() ForgotPasswordObj.uuid = uuid.uuid4() ForgotPasswordObj.timestamp = datetime.datetime.now() ForgotPasswordObj.user_id = user.id ForgotPasswordObj.used = False if not InsertForgotPassword(ForgotPasswordObj): return json.dumps({"success": False, "uuid": None}) else: return json.dumps({ "success": True, "uuid": str(ForgotPasswordObj.uuid) }) else: return json.dumps({"success": False, "message": "No such user"}) else: forgotPassword = GetForgotPassword(p_uuid) if not forgotPassword: return json.dumps({"exist": False, "expired": False}) else: time_today = datetime.datetime.now() delta = time_today - forgotPassword.timestamp delta_hours = delta.days * 24 + delta.seconds / 3600.0 if delta_hours >= 1: return json.dumps({"exist": True, "expired": True}) else: return json.dumps({"exist": True, "expired": False})
def pd(): admin_id = request.args.get("admin_id") ret_data = [] data = get_pending_users(int(admin_id)) for d in data: complex_obj = DObject() complex_obj.id = d.id complex_obj.f_name = d.first_name complex_obj.l_name = d.last_name complex_obj.email = d.email complex_obj.phone = d.phone_number ret_data.append(complex_obj.__dict__) return json.dumps(ret_data)
def Decode(): content = request.json user_id = decode_auth_token(content['token']) duser = getUserById(user_id) user = DObject() user.id = duser.id user.first_name = duser.first_name user.last_name = duser.last_name user.community_id = duser.community_id user.image = "https://d19rpgkrjeba2z.cloudfront.net/e82de29ec673c6fa/static/nextdoorv2/images/avatars/avatar-" + duser.first_name[ 0].lower() + ".png" return json.dumps({ "userId": decode_auth_token(content['token']), 'user': user.__dict__ })
def PostMessage(): content = request.json MessageObj = DObject() MessageObj.title = "" MessageObj.content = content["content"] #MessageObj.timestamp = content["timestamp"] MessageObj.from_user_id = content["from_user_id"] MessageObj.to_user_id = content["to_user_id"] if InsertMessage(MessageObj): return json.dumps({"success": True}) else: return json.dumps({"success": False})
def GetComment(): post_id = request.args.get('post_id') data = GetCommentsByPostId(post_id) if not data: return json.dumps([]) else: ret_comments = [] for d in data: comment = d[0] user = d[1] dcomment = DObject() dcomment.id = comment.id dcomment.content = comment.content dcomment.user_id = comment.user_id dcomment.post_id = comment.post_id dcomment.first_name = user.first_name dcomment.last_name = user.last_name ret_comments.append(dcomment.__dict__) return json.dumps(ret_comments)
def getMessagesFromUser(): to_user_id = request.args.get('to_user_id') from_user_id = request.args.get('from_user_id') data = GetMessages(from_user_id, to_user_id) ret_messages = [] if not data: return json.dumps([]) for d in data: message = d complex_obj = DObject() complex_obj.title = message.title complex_obj.content = message.content complex_obj.timestamp = str(message.timestamp) complex_obj.from_user_id = message.from_user_id complex_obj.to_user_id = message.to_user_id ret_messages.append(complex_obj.__dict__) return json.dumps(ret_messages)
def getCommunityById(): community_id = request.args.get('community_id') data = GetCommunitiesById(community_id) ret_messages = [] if not data: return json.dumps([]) for d in data: c = d[0] g = d[1] complex_obj = DObject() complex_obj.id = c.id complex_obj.name = c.name complex_obj.lat = g.lat complex_obj.lon = g.lon ret_messages.append(complex_obj.__dict__) return json.dumps(ret_messages)
def GetUsers(): c_id = request.args.get('community_id') users = GetUsersByCommunityId(int(c_id)) if len(users) == 0: return json.dumps({ "message": "No Users in this community", "success": False }) else: ret_users = [] for duser in users: user = DObject() user.id = duser.id user.first_name = duser.first_name user.last_name = duser.last_name user.image = "https://d19rpgkrjeba2z.cloudfront.net/e82de29ec673c6fa/static/nextdoorv2/images/avatars/avatar-" + duser.first_name[ 0].lower() + ".png" ret_users.append(user.__dict__) return json.dumps(ret_users)
def GetMessageUsers(): to_user_id = request.args.get('to_user_id') data = GetUsersByToUserId(to_user_id) ret_messages = [] if not data: return json.dumps([]) x = [] for d in data: user = d[1] if user.id in x: continue x.append(user.id) complex_obj = DObject() complex_obj.id = user.id complex_obj.first_name = user.first_name complex_obj.last_name = user.last_name complex_obj.image = "https://d19rpgkrjeba2z.cloudfront.net/e82de29ec673c6fa/static/nextdoorv2/images/avatars/avatar-" + user.first_name[ 0].lower() + ".png" ret_messages.append(complex_obj.__dict__) return json.dumps(ret_messages)
def GetIntraPostUserId(): user_id = request.args.get('user_id') data = GetIntraPostsByUserId(user_id) ret_data = [] if data is None: return json.dumps([]) user = getUserById(user_id) for p in data: print p obj = DObject() obj.user_id = user.id obj.post_id = p[0].id obj.first_name = user.first_name obj.last_name = user.last_name obj.community_name = p[1].name obj.title = p[0].title obj.message = p[0].content obj.category = p[0].category obj.timestamp = str(p[0].timestamp) if p[0].file_id: k = get_file_obj(p[0].file_id).key if k is None: obj.file_id = None else: file_id = (k).split(",")[0] obj.file_id = "https://s3.amazonaws.com/s3-cmpe-281/" + file_id else: obj.file_id = None obj.image = "https://d19rpgkrjeba2z.cloudfront.net/e82de29ec673c6fa/static/nextdoorv2/images/avatars/avatar-" + user.first_name[ 0].lower() + ".png" ret_data.append(obj.__dict__) return json.dumps(ret_data)
def getInterPost(): community_id = request.args.get('community_id') offset = request.args.get('offset') limit = request.args.get('limit') filter_category = request.args.get('category') if filter_category: posts = GetIntraPostsByCommunityId(community_id, limit, offset, filter_category) else: posts = GetIntraPostsByCommunityId(community_id, limit, offset) post_obj = [] for p in posts: print p obj = DObject() obj.user_id = p[0].id obj.post_id = p[1].id obj.first_name = p[0].first_name obj.last_name = p[0].last_name obj.community_name = p[2].name obj.title = p[1].title obj.message = p[1].content obj.category = p[1].category obj.timestamp = str(p[1].timestamp) if p[1].file_id: k = get_file_obj(p[1].file_id).key if k is None: obj.file_id = None else: file_id = (k).split(",")[0] obj.file_id = "https://s3.amazonaws.com/s3-cmpe-281/" + file_id else: obj.file_id = None obj.image = "https://d19rpgkrjeba2z.cloudfront.net/e82de29ec673c6fa/static/nextdoorv2/images/avatars/avatar-" + p[ 0].first_name[0].lower() + ".png" post_obj.append(obj.__dict__) if filter_category: posts = GetInterPostsByCommunityId(community_id, filter_category, limit, offset) else: posts = GetInterPostsByCommunityId(community_id, None, limit, offset) for p in posts: print p obj = DObject() obj.user_id = p[0].id obj.post_id = p[1].id obj.first_name = p[0].first_name obj.last_name = p[0].last_name obj.community_name = (GetCommunity(p[0].community_id)).name obj.title = p[1].title obj.message = p[1].content obj.category = p[1].category obj.timestamp = str(p[1].timestamp) if p[1].file_id: k = get_file_obj(p[1].file_id).key if k is None: obj.file_id = None else: file_id = (k).split(",")[0] obj.file_id = "https://s3.amazonaws.com/s3-cmpe-281/" + file_id else: obj.file_id = None obj.image = "https://d19rpgkrjeba2z.cloudfront.net/e82de29ec673c6fa/static/nextdoorv2/images/avatars/avatar-" + p[ 0].first_name[0].lower() + ".png" post_obj.append(obj.__dict__) return json.dumps(post_obj)
def PostInterPost(): content = request.json for c_id in content["communityIds"].split(','): InterPostObj = DObject() InterPostObj.title = content["title"] InterPostObj.content = content["content"] InterPostObj.category = content['category'] InterPostObj.timestamp = datetime.datetime.now() InterPostObj.image_ids = content['image_ids'] InterPostObj.user_id = decode_auth_token(content['token']) InterPostObj.community_id = c_id #InterPostObj.post_type = content["postType"] InterPostObj.admin_approved = False InterPostObj.image_ids = content['image_ids'] InsertInterPost(InterPostObj) return json.dumps({"success": True})