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)
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)
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)
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)
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))
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))
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)
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)
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))
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)
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))
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)
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)
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
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
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
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))