示例#1
0
	def registerUser(self,email,username):
		"""
		Register a user.
		"""
		if(not self.memc): return
		cacheku = util.sanitize_cache_key(username)
		cacheke = util.sanitize_cache_key(email)
		self.memc.set(("user(%s).email" % (cacheke)),True)
		self.memc.set(("user(%s).username" % (cacheku)),True)
		self.setUsernameStatus(username,EXISTS)
		self.setEmailStatus(email,EXISTS)
		self.setTotalTagsForUsername(username,0)
示例#2
0
	def unregisterUser(self,email,username):
		"""
		Unregister a user
		"""
		if(not self.memc): return
		cacheku = util.sanitize_cache_key(username)
		cacheke = util.sanitize_cache_key(email)
		self.memc.delete("user(%s).email" % (cacheke))
		self.memc.delete("user(%s).username" % (cacheku))
		self.setUsernameStatus(username,NOT_EXISTS)
		self.setEmailStatus(email,NOT_EXISTS)
		self.clearTotalTagsForUsername(username)
		self.clearUserInfoForUsername(username)
示例#3
0
	def setUsernameStatus(self,username,status):
		"""
		Set the username status.
		"""
		if(not self.memc): return
		cachek = util.sanitize_cache_key(username)
		self.memc.set("user(%s).username" % (cachek), status)
示例#4
0
	def setTotalTagsForUsername(self,username,val):
		"""
		Set the total tag count for a username.
		"""
		if(not self.memc): return
		cachek = util.sanitize_cache_key(username)
		self.memc.set("user(%s).totalTags" % (cachek),val)
示例#5
0
	def userIdForUsername(self,username):
		"""
		Get a userId for a username.
		"""
		if(not self.memc): return -1
		cachek = util.sanitize_cache_key(username)
		return self.memc.get("user(%s).userId" % (cachek))
示例#6
0
	def clearUserInfoForUsername(self,username):
		"""
		Clear cached user info for a username.
		"""
		if(not self.memc): return
		cachek = util.sanitize_cache_key(username)
		self.memc.delete("user(%s).info" % (cachek))
示例#7
0
	def setUserIdForUsername(self,username,userId):
		"""
		Set a user id for their username.
		"""
		if(not self.memc): return
		cachek = util.sanitize_cache_key(username)
		self.memc.set("user(%s).userId" % (cachek), userId)
示例#8
0
	def setUserInfoForUsername(self,username,info):
		"""
		Set user info for a username.
		"""
		if(not self.memc): return
		cachek = util.sanitize_cache_key(username)
		self.memc.set("user(%s).info" % (cachek), info)
示例#9
0
	def clearTotalTagsForUsername(self,username):
		"""
		Delete the total tags count for a username.
		"""
		if(not self.memc): return
		cachek = util.sanitize_cache_key(username)
		self.memc.delete("user(%s).totalTags" % (cachek))
示例#10
0
	def setAuthentication(self,username,password):
		"""
		Set authentication in cache.
		"""
		if(not self.memc): return
		cachek = util.sanitize_cache_key(username)
		self.memc.set("user(%s).auth" % (cachek),password)
示例#11
0
	def doesEmailExist(self,email):
		"""
		Check whether or not an email exists.
		"""
		if(not self.memc): return 0
		cachek = util.sanitize_cache_key(email)
		return self.memc.get("user(%s).email" % (cachek))
示例#12
0
	def setEmailStatus(self,email,status):
		"""
		Set the email status.
		"""
		if(not self.memc): return
		cachek = util.sanitize_cache_key(email)
		self.memc.set("user(%s).email" % (cachek), status)
示例#13
0
	def incrementTotalTagsForUsername(self,username):
		"""
		Increment the total tags for a username.
		"""
		if(not self.memc): return
		cachek = util.sanitize_cache_key(username)
		self.memc.incr("user(%s).totalTags" % (cachek))
		self.clearUserInfoForUsername(username)
示例#14
0
	def getUserInfoForUsername(self,username):
		"""
		Get user info for a username.
		"""
		if(not self.memc): return
		cachek = util.sanitize_cache_key(username)
		res = self.memc.get("user(%s).info" % (cachek))
		return 
示例#15
0
	def totalTagsForUsername(self,username):
		"""
		Get the total tag cound for a username.
		"""
		if(not self.memc): return -1
		cachek = util.sanitize_cache_key(username)
		res = self.memc.get("user(%s).totalTags" % (cachek))
		if(not res): return -1
		return res
示例#16
0
	def doesUsernameExist(self,username):
		"""
		Check whether or not a username exists.
		"""
		if(not self.memc): return 0
		cachek = util.sanitize_cache_key(username)
		res = self.memc.get("user(%s).username" % (cachek))
		if(not res): return NO_KEY
		return res
示例#17
0
	def authenticate(self,username,password):
		"""
		Check authencitation from cache.
		"""
		if(not self.memc): return False
		cachek = util.sanitize_cache_key(username)
		passwd = self.memc.get("user(%s).auth" % (cachek))
		if(not passwd): return False
		if(passwd == password): return True
		self.memc.delete("user(%s).auth" % (cachek))