def destroy(self): ssn = SessionStore.gql('WHERE sid=:1', self.sid_value) db.delete(ssn) self.delete_cache() expires = time.strftime("%a, %d-%b-%Y %H:%M:%S GMT", time.gmtime(0)) cookie_val = self.sid_name + '=null' + ';expires=' + expires self.res.headers.add_header('Set-Cookie', cookie_val)
def destroy(self): ssn = SessionStore.gql('WHERE sid=:1', self.sid_value) db.delete(ssn) self.delete_cache() expires = time.strftime("%a, %d-%b-%Y %H:%M:%S GMT", time.gmtime(0)) cookie_val = str(self.sid_name + '=null' + ';expires=' + expires) self.res.headers.add_header('Set-Cookie', cookie_val)
def new(self, user, ssl=False): random.seed() random_str = str(random.random()) + str(random.random()) random_str = random_str + str(time.time()) random_str = random_str + os.environ['REMOTE_ADDR'] self.sid_value = hashlib.sha256(random_str).hexdigest() self.set_cookie(ssl) old_ssn = SessionStore.gql('WHERE user_ref=:1 and last_access_time < :2', user.key(), datetime.now() - timedelta(days=7)) db.delete(old_ssn) ssn_db = SessionStore(sid=self.sid_value, user_ref=user, temporary=self.temporary) ssn_db.put() self.set_cache(ssn_db) return self.sid_value
def get_session(self): cache_key = self.get_cache_key() ssn = memcache.get(cache_key) if ssn is not None: return ssn ssn = SessionStore.gql('WHERE sid=:1', self.sid_value).get() if ssn: self.set_cache(ssn) now = datetime.now() if not ssn.last_access_time or ssn.last_access_time < now - timedelta(days=1): ssn.last_access_time = now ssn.put() return ssn
def get_session(self): cache_key = self.get_cache_key() ssn = memcache.get(cache_key) if ssn is not None: return ssn ssn = SessionStore.gql('WHERE sid=:1', self.sid_value).get() if ssn: self.set_cache(ssn) now = datetime.now() if not ssn.last_access_time or ssn.last_access_time < now - timedelta( days=1): ssn.last_access_time = now ssn.put() return ssn
def new(self, user, ssl=False): random.seed() random_str = str(random.random()) + str(random.random()) random_str = random_str + str(time.time()) random_str = random_str + os.environ['REMOTE_ADDR'] self.sid_value = hashlib.sha256(random_str).hexdigest() self.set_cookie(ssl) old_ssn = SessionStore.gql( 'WHERE user_ref=:1 and last_access_time < :2', user.key(), datetime.now() - timedelta(days=7)) db.delete(old_ssn) ssn_db = SessionStore(sid=self.sid_value, user_ref=user, temporary=self.temporary) ssn_db.put() self.set_cache(ssn_db) return self.sid_value