示例#1
0
	def mark(self, conversationid, postid, noteid, isup):
		cuid = login.get_user_fullid(self.key)

		mark_field = "marks_up"
		
		if isup == 1:
			isup = 1
		else:
			isup = -1
			mark_field = "marks_down"


		if noteid != "0": #note
			#   db.roadhouse.conversations.update({"_id": ObjectId(postid), "posts.id": str(noteid)}, {"$inc": {"posts.$.rating": isup}})
			cuid = login.get_user_fullid(self.key)
			cc = db.roadhouse.conversations.find_one({"_id": ObjectId(postid), "posts.id": str(noteid)}) #, "posts." + mark_field + ".id": {"$ne": str(cuid)}})
			if cc is None:
				return 0

			for post in cc["posts"]:
				if "id" in post:
					if post["id"] == str(noteid):
						print post
						for mks in post[mark_field]:
							if "id" in mks:
								if mks["id"] == str(cuid):
									return 0

			if cc is not None:
				db.roadhouse.conversations.update({"_id": ObjectId(postid), "posts.id": str(noteid)}, {"$inc": {"posts.$.rating": isup}})
				db.roadhouse.conversations.update({"_id": ObjectId(postid), "posts.id": str(noteid)}, {"$push" : {"posts.$." + mark_field : {  "id" : cuid, "status": 0}}})

			else:
				return 0

		elif postid != "0": #bump
			cuid = login.get_user_fullid(self.key)
			cc = db.roadhouse.conversations.find_one({"_id": ObjectId(conversationid), "posts.id": str(postid)}) #, "posts." + mark_field + ".id": {"$ne": str(cuid)}})
			if cc is None:
				return 0

			for post in cc["posts"]:
				if "id" in post:
					if post["id"] == str(postid):
						for mks in post[mark_field]:
							if "id" in mks:
								if mks["id"] == str(cuid):
									return 0
				
			
			if cc is not None:
				db.roadhouse.conversations.update({"_id": ObjectId(conversationid), "posts.id": str(postid)}, {"$inc": {"posts.$.rating": isup}})
				db.roadhouse.conversations.update({"_id": ObjectId(conversationid), "posts.id": str(postid)}, {"$push" : {"posts.$." + mark_field : {  "id" : cuid, "status": 0}}})

			else:
				return 0

		return 1
示例#2
0
	def update(self, data, password):

		userid = login.get_user_fullid(self.key)
		if userid:
			u = db.roadhouse.secure.find_one({"userfullid": ObjectId(userid)})

			if u is None:
				return None

			if len(data["fname"]) < 1:
				return None

			if len(data["lname"]) < 1:
				return None

			if len(data["email"]) < 5:
				return None


			if "password" in u:
				if str(u["password"]) == str(hashlib.sha256(password + "_rd").hexdigest()):
					db.roadhouse.people.update({"_id": ObjectId(userid)}, {"$set": {"fname" : data["fname"], "lname": data["lname"],
												"username": data["username"], "email": data["email"], "description": data["description"]}})


					if len(data["password"]) > 4:
						db.roadhouse.secure.update({"userfullid": ObjectId(userid)}, {"$set": {"email" : data["email"], "password" : data["password"]}})
					else:
						db.roadhouse.secure.update({"userfullid": ObjectId(userid)}, {"$set": {"email" : data["email"]}})

					print data["lname"] + "Account updated"
					return 1

		return None
示例#3
0
	def delete(self, password):
		userid = login.get_user_fullid(self.key)
		if userid:
			db.roadhouse.people.update({"_id": userid}, {"$set": {"accountactive" : 0}})
			login.logout(self.key)
			return 1
		return 0
示例#4
0
	def enter(self, roomid):
		cuid = login.get_user_fullid(self.key)
		db.roadhouse.rooms.update({"_id": ObjectId(roomid), "people.id" : {"$ne": str(cuid)}},
								  {"$push" : {"people" : {  "id" : cuid,
															"security": 0,
															"rating": 0}}})
		return 1
示例#5
0
	def unsubscribe(self, roomid):
		cuid = login.get_user_fullid(self.key)
		db.roadhouse.rooms.update({"_id": ObjectId(roomid)}, {"$pull" : {"subscribers" : {"id": str(cuid)}}})

		people = core.people.People(self.key)
		people.unsubscribe(roomid)
		return 1
示例#6
0
	def subscribe(self, roomid):
		cuid = login.get_user_fullid(self.key)
		db.roadhouse.rooms.update({"_id": ObjectId(roomid), "subscribers.id": {"$ne": str(cuid)}},
									{"$push" : {"subscribers" : {  "id" : cuid, "status": 0}}})

		people = core.people.People(self.key)
		people.subscribe(roomid)
		return 1
示例#7
0
	def create(self, roomdata):
		cuid = login.get_user_fullid(self.key)
		roomdata["admins"] = [{"id": cuid, "status": 0}]
		
		roomdata["subscribers"] = [];	
		roomdata["people"] = [];

		roomfullid = db.roadhouse.rooms.insert(roomdata)
		return roomfullid
示例#8
0
	def add_friend(self, id, iid):




		iuserid = login.get_user_id(self.key)
		userid = login.get_user_fullid(self.key)
		ouserid = ObjectId(userid)

		userdata = self.get(login.get_user_fullid(self.key))
		if userdata is not None:
			if "friends" in userdata:
				for frnd in userdata["friends"]:
					if frnd["fid"] == ouserid:
						print "Trying to add an existing contact"
						return 1


		fdata = {"id": iid, "fid": ObjectId(id), "rating": 0, "since": datetime.datetime.utcnow(), "conversation": None}
		db.roadhouse.people.update({"_id": ObjectId(userid)}, {"$push": {"friends": fdata}}, True)
		fdata2 = {"id": iuserid, "fid": ObjectId(userid), "rating": 0, "since": datetime.datetime.utcnow(), "conversation": None}
		db.roadhouse.people.update({"_id": ObjectId(id)}, {"$push": {"friends": fdata2}}, True)
		return 1
示例#9
0
	def handle_notifications(self, url):
	
		obj = None
		notifications = core.notifications.Notifications(self.key)

		if url == "get":
			uid = login.get_user_fullid(self.key)

			obj = notifications.get_history(uid)
			return obj


		elif url == "send_message": # uid, msg (+body)
			fromuser = login.get_user_fullid(self.key)
			uid = self.get_argument("uid", "0")
			msg = self.get_argument("msg", "")
			if self.request.body is not None:
				msg = msg + self.request.body

			notifications.send_to_user(uid, fromuser, notifications.notification_type_msg, {"msg": msg, "timestamp": ""})
			return obj
		

		elif url == "send_friend_request": # uid
			fromuser = login.get_user_fullid(self.key)
			uid = self.get_argument("uid", "0")
			r = notifications.send_to_user(uid, fromuser, notifications.notification_type_friendship, {"mode": 0, "timestamp": ""})

			if r == True:		
				obj = {"result" : "success"}
			else:
				obj = {"result" : "error"}

			return obj

		return obj
示例#10
0
	def get_friends(self, userid):
		try: userid = int(userid)
		except: return None
		
		if userid != 0:
			userdata = self.get(userid)
			if userdata is not None:
				if "friends" in userdata:
					return self.get_friend_detailset(userdata["friends"])
			return None
		else:
			userdata = self.get(login.get_user_fullid(self.key))
			if userdata is not None:
				if "friends" in userdata:
					return self.get_friend_detailset(userdata["friends"])
			return None
示例#11
0
	def get_subscriptions(self):
		userid = login.get_user_fullid(self.key)
		userdata = self.get(userid)
		if userdata is None:
			return None


		objr = []
		rooms = core.rooms.Rooms(self.key)
		
		if "subscriptions" in userdata:
			subids = userdata["subscriptions"]
			for subid in subids:
				if "id" in subid:
					o = rooms.get_info(subid["id"])
					rooms.format_room(o)
					rooms.strip_secure_details(o)
					objr.append(o)


			return objr

		else:
			return None
示例#12
0
	def handle_people(self, url):
	
		obj = None
		people = core.people.People(self.key)
		
		if url == "get":
			obj = people.get(self.get_argument("id", "0"))
			if obj is not None:
				people.format_details(obj)
				people.strip_secure_details(obj)
				
		elif url == "get_friends":
			obj = people.get_friends(self.get_argument("id", "0"))

			if obj is None:
				obj = {"result" : "error", "message" : "No friends found"}
				return 0

			#p = []
			#for fid in obj:
			#	if fid is not None and fid != 0:
			#		pd = people.get(fid["id"])
			#		people.strip_secure_details(pd)
			#		p.append(pd)

			#obj = p

			
		elif url == "send_message":
			obj = {"message" : "under construction"}
			
		elif url == "follow":
			obj = people.follow(str(self.get_argument("id", "0")))
			
		elif url == "delete":
			obj = people.delete(str(self.get_argument("id", "0")))
			
		elif url == "update":
			person =  {"fname"		 : self.get_argument("fname", ""),
					   "lname" 		 : self.get_argument("lname", ""),
					   "username" 	 : self.get_argument("username", ""),
					   "email" 		 : self.get_argument("email", ""),
					   "password" 	 : self.get_argument("password", ""),
					   "description" : self.get_argument("description", "", "")}

			if people.update(person, self.get_argument("cpassword", "")) is not None:
				obj = {"result" : "success"}
			else:
				obj = {"result" : "error"}

			return obj

		elif url == "report":
			obj = {"message" : "under construction"}

		elif url == "get_subscriptions":
			obj = people.get_subscriptions()
			
		elif url == "set_location":
			obj = people.set_location(str(self.get_argument("lat", "0")), str(self.get_argument("long", "0")))

		elif url == "add_friend":
			#v = people.add_friend(str(self.get_argument("id", "0")), str(self.get_argument("iid", "0")))
			#if v == 0:
				return {"result" : "error"}
			#else:
			#	return {"result" : "success"}
			#return obj

		elif url == "respond_to_friend_request":

			uid = self.get_argument("uid", "0")
			accepted = self.get_argument("accepted", "1")

			cuid = login.get_user_fullid(self.key)
			notifications = core.notifications.Notifications(self.key)
			rreq = notifications.accept_friend(cuid, uid)

			if rreq == False:
				return {"result": "error"}

			v = 1

			if accepted != 0:
				v = people.add_friend(uid, 0)

			if v == 0:
				return {"result" : "error"}
			else:
				return {"result" : "success"}
			return obj

		elif url == "search_simple":
			oc = people.search_simple(self.get_argument("q", "0"), 0, 0)
			obj = []

			for o in oc:
				if "_id" in o:
					dp_s = ""
					dp_l = ""

					if "dp" in o:
						if o["dp"] != "":
							dp_s = "/cdn/full/" + o["dp"]
							dp_l = "/cdn/full/" + o["dp"]

					uname = o["fname"] + " " + o["lname"]

					obj.append({"id": str(o["_id"]), "name": uname, "status": o["description"], "dp_s": dp_s, "dp_l": dp_l, "username": o["username"]})

			#people.strip_secure_details(obj)

		return obj
示例#13
0
 def open(self, key):
     userdata = login.get_user_fullid(self.key)
     self.uid = str(userdata)
     ChatSocketHandler.waiters.add(self)
示例#14
0
	def leave(self, roomid):
		cuid = login.get_user_fullid(self.key)
		db.roadhouse.rooms.update({"_id": ObjectId(roomid)}, {"$pull" : {"people" : {"id" : str(cuid)}}})
		return 1
示例#15
0
	def handle_rooms(self, url):
	
		obj = None
		rooms = core.rooms.Rooms(self.key)

		if url == "create":

			lat = 0.0
			lng = 0.0
			rsize = 5

			try:
				rsize = int(self.get_argument("size"))
				lat = float(self.get_argument("lat"))
				lng = float(self.get_argument("long"))
			except:
				return obj

			room   =  {"name"		 : str(self.get_argument("name")),
					   "dsc" 		 : str(self.get_argument("dsc")),
					   "address" 	 : str(self.get_argument("address")),
					   "status" 	 : "",
					   "size"        : rsize,
					   "type"        : rooms.room_type_place,
					   "security"    : {"type": rooms.security_level_open, "password": ""},
					   "locname"	 : "",
					   "loc" 		 : [lat, lng],
					   "event" 		 : {"start": 0, "end": 0},
					   "ratings" 	 : {"rating1" : 0, "rating2" : 0},
					   "tickets"	 : {"message" : "", "url": "", "price": ""},
					   "conversation": None}


			oid = rooms.create(room)
			obj = {"result" : "success", "objid" : str(oid)}

			if obj is not None:
				rooms.strip_secure_details(obj)
				
		elif url == "get":
			cuid = login.get_user_fullid(self.key)
			oc = rooms.get(self.get_argument("lat", "0"), self.get_argument("long", "0"), self.get_argument("rad", "100"), None, None)
			
			if oc is None:
				obj = {"result" : "error", "message" : "No rooms around."}
				return 0
			
			obj = []
			for o in oc:
				rooms.strip_secure_details(o)
				rooms.format_room(o)
				o["subscribed"] = rooms.is_subscribed(o, cuid)
				o["intheroom"] = rooms.is_intheroom(o, cuid)
				

				obj.append(o)


		elif url == "get_info":
			cuid = login.get_user_fullid(self.key)

			o = rooms.get_info(self.get_argument("id", "0"))
			
			if o is None:
				obj = {"result" : "error", "message" : "No rooms around."}
				return obj
			
			rooms.strip_secure_details(o)
			rooms.format_room(o)
			o["subscribed"] = rooms.is_subscribed(o, cuid)
			o["intheroom"] = rooms.is_intheroom(o, cuid)
			obj = o


		elif url == "enter":
			id = self.get_argument("id", "0")
			
			if id == "0":
				return 0

			oc = rooms.enter(id)
			if oc == 1:
				obj = {"result" : "success"}


		elif url == "leave":
			id = self.get_argument("id", "0")
			
			if id == "0":
				return 0

			oc = rooms.leave(id)
			if oc == 1:
				obj = {"result" : "success"}


		elif url == "subscribe":
			id = self.get_argument("id", "0")
			
			if id == "0":
				return 0

			oc = rooms.subscribe(id)
			if oc == 1:
				obj = {"result" : "success"}


		elif url == "unsubscribe":
			id = self.get_argument("id", "0")
			
			if id == "0":
				return 0

			oc = rooms.unsubscribe(id)
			if oc == 1:
				obj = {"result" : "success"}

		elif url == "get_conversation":
			id    = str(self.get_argument("id", "0"))
			pid   = str(self.get_argument("pid", "0"))
			skip  = str(self.get_argument("skip", "0"))
			count = str(self.get_argument("count", "7"))
			noteskip  = str(self.get_argument("noteskip", "0"))
			notecount = str(self.get_argument("notecount", "5"))
			
			obj = {"result" : "error"}
			
			if id == "0":
				return obj

			try:
				skip = int(skip)
			except:
				skip = 0

			try:
				count = int(count)
			except:
				count = 1

			try:
				noteskip = int(noteskip)
			except:
				noteskip = 0

			try:
				notecount = int(notecount)
			except:
				notecount = 5

			oc = rooms.get_conversation(id)
			if oc is not None:
				conversations = core.conversations.Conversations(self.key)
				obj = conversations.get(conversations.get_default, oc, pid, skip, count, noteskip, notecount)


		return obj
示例#16
0
	def post(self, conversationid, postid, text, tags, data, type):
		retid = 1
		
		if tags == 0:
			tags = None
			
		if data == 0:
			data = None
		
		if postid == "0": # full post
			if type == self.post_type_text or type == self.post_type_link:
			
				if type == self.post_type_text:
					data = None
				
				parent_conv = db.roadhouse.conversations.find_one({"_id": ObjectId(conversationid)})

				if parent_conv is None:
					return None
				
				associate_id   = parent_conv["associate"]["id"]
				associate_type = parent_conv["associate"]["type"]

				postinfo = {"type": self.type_post, "parent": str(conversationid), "associate": {"id": associate_id, "type": associate_type}, "posts": []}

				postfullid = db.roadhouse.conversations.insert(postinfo)
					
				post = {"userid": login.get_user_fullid(self.key), "type": type, "text": text, "rating": 0, "dp": "",
						"data": data, "tags": [], "marks_up": [], "marks_down": [], "time": datetime.datetime.utcnow(), "notes": None, "id": str(postfullid)}
						
				if tags is not None:
					post["tags"] = tags
						
				db.roadhouse.conversations.update({"_id": ObjectId(conversationid)}, {"$push" : {"posts" : post}})
				retid = postfullid
				
			elif type == self.post_type_album:
				
				x = 1
				# [todo]
			
		else: #note
			if type == self.post_type_text:

				if type == self.post_type_text:
					data = None
				
				post = {"userid": login.get_user_fullid(self.key), "type": type, "text": text, "rating": 0,
						"data": data, "tags": [], "marks_up": [], "marks_down": [], "time": datetime.datetime.utcnow(), "id": str(ObjectId())}
						
				if tags is not None:
					post["tags"] = tags
						
				db.roadhouse.conversations.update({"_id": ObjectId(postid)}, {"$push" : {"posts" : post}})
				
				return 1
				
		# send notifications
		# send websocket notifications
				
		return retid
示例#17
0
	def unsubscribe(self, roomid):
		userid = login.get_user_fullid(self.key)
		db.roadhouse.people.update({"_id": ObjectId(userid)}, {"$pull" : {"subscriptions" : {"id" : str(roomid)}}})
		return None
示例#18
0
	def subscribe(self, roomid):
		userid = login.get_user_fullid(self.key)
		print "SUBSCRIBING -----------------" + userid
		fdata = {"id": roomid, "since": datetime.datetime.utcnow()}
		db.roadhouse.people.update({"_id": ObjectId(userid)}, {"$push": {"subscriptions": fdata}}, True)
		return None