Esempio n. 1
0
def get_user_id(key):
	if key == "0":
		return 0

	uid = decode_key(key)

	people = core.people.People(key)
	userd = people.get(uid)
	
	if userd is None:
		return None
	
	return userd["id"]

	#userfid = webself.get_secure_cookie("user")
	#if userfid is None:
	#	return None
#
	#people = core.people.People(webself)
	#userd = people.get(userfid)
#
	#if userd is None:
	#	return None
#
	#return userd["id"]
	return "1"
Esempio n. 2
0
def is_authorized(key):
	#cookie = webself.get_secure_cookie("user")
	#if cookie is not None:
	if key == "0":
		return False

	key = decode_key(key)
	
	people = core.people.People(key)
	if people.get(key) is None:
		return False

	return True
Esempio n. 3
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
Esempio n. 4
0
	def handle_accounts(self, url):
	
		obj = None

		if url == "login": # email, pass
			email = self.get_argument("email", "0")
			passw = self.get_argument("pass", "0")

			if email == "0" or passw == "0":
				return obj

			r = login.login(email, passw)	
			
			if r != False:
				self.key = login.make_key(r)
				people = core.people.People(self.key)
				cuid = r
				userdata = people.get(str(cuid))
				if userdata is None:
					obj = {"result" : "error"}
					login.logout(self.key)
					return obj

				if "dp" in userdata:
					if userdata["dp"] == "":
						dp_s = ""
						dp_l = ""
					else:
						dp_s = "/static/cdn/full/" + userdata["dp"]
						dp_l = "/static/cdn/full/" + userdata["dp"]
				else:
					dp_s = ""
					dp_l = ""
				
				

				print userdata["fname"] + " " + userdata["lname"] + " logged in dp - " + dp_s
				obj = {"result" : "success", "key": self.key, "user": {"id": str(cuid), "dp_s": dp_s, "dp_l": dp_l, "uname": userdata["fname"] + " " + userdata["lname"]}}
			else:
				obj = {"result" : "error"}

			return obj


		elif url == "create_account":
			obj = {"result" : "error"}

			people = core.people.People(self.key)

			person =  {"fname"		 : self.get_argument("fname", ""),
					   "lname" 		 : self.get_argument("lname", ""),
					   "username" 	 : self.get_argument("username", ""),
					   "email" 		 : self.get_argument("email", ""),
					   "rating"	 	 : {"rating1" : 0, "rating2" : 0},
					   "password" 	 : self.get_argument("password", ""),
					   "location" 	 : {"name" : "Unknown Location", "type" : 0},
					   "coordinates" : [0, 0],
					   "description" : self.get_argument("description", ""),
					   "status" 	 : self.get_argument("status", "")}
			
			pcr = people.create(person)
			
			if pcr == 1:
				email = self.get_argument("email", "0")
				passw = self.get_argument("password", "0")

				if email == "0" or passw == "0":
					return obj

				r = login.login(email, passw)	
				
				if r != False:
					self.key = login.make_key(r)
					people = core.people.People(self.key)
					cuid = r
					userdata = people.get(str(cuid))
					if userdata is None:
						obj = {"result" : "error"}
						login.logout(self.key)
						return obj

					if "dp" in userdata:
						if userdata["dp"] == "":
							dp_s = ""
							dp_l = ""
						else:
							dp_s = "/static/cdn/full/" + userdata["dp"]
							dp_l = "/static/cdn/full/" + userdata["dp"]
					else:
						dp_s = ""
						dp_l = ""
				

					print userdata["fname"] + " " + userdata["lname"] + " logged in dp - " + dp_s
					obj = {"result" : "success", "key": self.key, "user": {"id": str(cuid), "dp_s": dp_s, "dp_l": dp_l, "uname": userdata["fname"] + " " + userdata["lname"]}}
				else:
					obj = {"result" : "error"}
		

		if url == "logout":
			r = login.logout(self.key)	
			
			if r == True:		
				obj = {"result" : "success"}
			else:
				obj = {"result" : "error"}

			return obj


		if url == "deactivate":
			obj = {"result" : "Not Implemented"}
			return obj

		return obj
Esempio n. 5
0
	def format(self, fromuser, type, mdata, last_fetch_timestamp):
		people = core.people.People(self)

		msg = {}
		userdata = people.get(str(fromuser))

		if userdata is None:
			return False

		dp_s = ""
		dp_l = ""

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


		msg["user"] = {"uid": str(fromuser), "fname": userdata["fname"], "lname": userdata["lname"], "dp_s": dp_s, "dp_l": dp_l}

		msg["marked"] = 0

		if "timestamp" in mdata:
			msg["timestamp"] = mdata["timestamp"]
			
			if last_fetch_timestamp != 0:
				if mdata["timestamp"] > last_fetch_timestamp:
					msg["marked"] = 1
		else:
			msg["timestamp"] = ""

		

		if type == self.notification_type_msg:
			msg["mtype"] = "message"
			msg["ctext"] = mdata["msg"]

		elif type == self.notification_type_friendship:
			msg["mtype"] = "friendship"
			msg["mode"] = mdata["mode"]

		elif type == self.notification_type_room_newpost:
			msg["mtype"] = "newpost"
			msg["roomid"] = ""
			msg["roomid"] = ""
			msg["convid"] = ""
			msg["postid"] = ""
			msg["noteid"] = "" 

		elif type == self.notification_type_conversation_reply:
			msg["mtype"] = "newnote"
			msg["roomid"] = ""
			msg["convid"] = ""
			msg["postid"] = ""
			msg["noteid"] = "" 

		elif type == self.notification_type_conversation_vote:
			msg["mtype"] = "upvote"
			msg["roomid"] = ""
			msg["convid"] = ""
			msg["postid"] = ""
			msg["noteid"] = "" 

		return msg