Example #1
0
	def displayProfile(self, username = None, psw = None, userToDisplay = None):
		
		#Get data from the data base
		currentUser = userDBCtrl.getCurrentUser()	

		#Communicate with the login server
		self.login()

		#Page loaded via a proper way
		if (currentUser[1] == psw and currentUser[2] == username):
			
			#The profile the user want to view is belong to himeself/herself, 
			#than just get the profile from data base		
			if(userToDisplay == currentUser[2]):
				profile = profileDBCtrl.getProfile(userToDisplay) #Get profile from database
				Page = webDesign.displayProfile(currentUser, profile, True)

			#If the user want to view other people's profile, go and ask for the profile first(for updating),
			#Then display it
			else:
				self.askForProfile(userToDisplay) #Ask for profile
				profile = profileDBCtrl.getProfile(userToDisplay) #Get profile from database
				Page = webDesign.displayProfile(currentUser, profile, False)
		
		#The page loaded in a wrong way
		else:
			Page = webDesign.assetErrorPage()
			
		return Page
Example #2
0
	def searchMessage(self, username = None, psw = None, userToShow = None):
		
		#Check if the page being loaded via long rather than loaded by tyre API directly
		#If the page loaded properly, display all the information, otherwise display a error message
		currentUser = userDBCtrl.getCurrentUser()

		#Communicate with the login server
		self.login()
		
		#Page loaded via a proper way
		if (currentUser[1] == psw and currentUser[2] == username):	
		
			#get all vee first
			allVee = messageDBCtrl.getMessagesHistory()

			if(userToShow == None):
				return webDesign.messageHistory(currentUser, allVee)	#If the user enter nothing, show all message

			else:
				#Select those relate to the user's search to return
				filtedVee = []
				for i in range(0, len(allVee), 1):
					if (allVee[i][0] == userToShow or allVee[i][1] == userToShow):
						filtedVee.append(allVee[i])
				
				return  webDesign.messageHistory(currentUser, filtedVee)

		else:
			return webDesign.assetErrorPage()
Example #3
0
	def userHome(self, username = None, psw = None):
		
		#Check if the page being loaded via long rather than loaded by tyre API directly
		#If the page loaded properly, display all the information, otherwise display a error message
		currentUser = userDBCtrl.getCurrentUser()
		
		#Page loaded via a proper way
		if (currentUser[1] == psw and currentUser[2] == username):	
			
			#Communicate with the login server
			self.login()
			
			#Update all signed up user
			self.getAllSigeUpUser()
			
			#Update online users
			self.getOnlineUser()
			onlineUsers = userDBCtrl.displayOnlineUser()
		
			#Check if there is new message(Vee)
			listOfVee = messageDBCtrl.getMessagesHistory()


			Page = webDesign.userHome(onlineUsers, currentUser, listOfVee)
		
		#The page loaded in a wrong way
		else:
			Page = webDesign.assetErrorPage()
			
		return Page
Example #4
0
    	def firstTimeLogin(self, username, psw, location):

		#In the case of the user enter nothing but still hit "login", it go to error page directly
		#Only call the login API when the user enter something
		if (username != "" and psw != ""):		

			#Hash the password 
			hash_object = hashlib.sha256(psw + "COMPSYS302-2017")
			hex_dig = hash_object.hexdigest()

			#Determind which IP address should return. (location = 0 means office(UG Lab) destop,
			#1 means office(Uni) wifi, 2 means external network
			ipAdd = "0.0.0.0"
			if (location == "0" or location == "1"):
				ipAdd = internalIPAddress
			else:	
				ipAdd = externalIPAddress
			
			print(internalIPAddress)
			#Tell login server to login			
			postdata = {"username": username, "password": hex_dig, "location": location, "ip": ipAdd, "port": listen_port}#Json encode
			dest = "http://cs302.pythonanywhere.com/report"	#Address
			fptr = urllib2.urlopen(dest, urllib.urlencode(postdata)) #Send
			receiveData = fptr.read() #Read what that API return
        		fptr.close()	
			
			#Save current user and check online users only when log in successfully and check who is online
			#If the database doesn't have the current user's profile, set up a profile for him/her
			if (receiveData[0] == "0"):
				userDBCtrl.updateCurrentUser(username, hex_dig, location, ipAdd, listen_port)
				raise cherrypy.HTTPRedirect("/userHome?username="******"&psw="+hex_dig)
	
			#If login is not success, return error code
			else:
				#Display what the API return to the screen
				Page = receiveData
				Page += webDesign.assetErrorPage()
				return Page

		#If the user enter nothing when login
		else:
			return webDesign.assetErrorPage()			
Example #5
0
	def removeUserFromBlacklist(self, username = None, psw = None, userToRemove = None):
		#Get currentUser's data from the data base
		currentUser = userDBCtrl.getCurrentUser()
	
		#Required correct user name and pasword to load the page
		if (currentUser[1] == psw and currentUser[2] == username):	
			#Remove from blacklist
			blacklistDBCtrl.removeFromBlacklist(currentUser[2], userToRemove)
			#return to the page
			raise cherrypy.HTTPRedirect("/displayBlacklist?username="******"&psw="+currentUser[1])

		else:
			return webDesign.assetErrorPage()
Example #6
0
	def displayBlacklist(self, username = None, psw = None):
		#Get currentUser's data from the data base
		currentUser = userDBCtrl.getCurrentUser()

		#Communicate with the login server
		self.login()
	
		#Required correct user name and pasword to load the page
		if (currentUser[1] == psw and currentUser[2] == username):	
			
			#Get the blacklist of this user	
			blacklist = blacklistDBCtrl.getBlacklist(currentUser[2])
			return webDesign.blacklistPage(currentUser, blacklist)

		else:
			return webDesign.assetErrorPage()