persistent sessions #486

This commit is contained in:
Martijn Voncken 2008-09-25 19:08:43 +00:00
parent 5457cdcd80
commit c67bfe74a7
4 changed files with 21 additions and 14 deletions

View File

@ -363,6 +363,7 @@ class Core(
'upload_rate':float(), 'upload_rate':float(),
'num_connections':int(), 'num_connections':int(),
'dht_nodes',int(), 'dht_nodes',int(),
'free_space':float()
'max_num_connections':int(), 'max_num_connections':int(),
'max_download':float(), 'max_download':float(),
'max_upload':float() 'max_upload':float()
@ -374,6 +375,7 @@ class Core(
"upload_rate":self.session.status().payload_upload_rate, "upload_rate":self.session.status().payload_upload_rate,
"num_connections":self.session.num_connections(), "num_connections":self.session.num_connections(),
"dht_nodes":self.session.status().dht_nodes, "dht_nodes":self.session.status().dht_nodes,
"free_space":deluge.common.free_space(self.config["download_location"]),
#max config values: #max config values:
"max_download":self.config["max_download_speed"], "max_download":self.config["max_download_speed"],
"max_upload":self.config["max_upload_speed"], "max_upload":self.config["max_upload_speed"],

View File

@ -48,7 +48,7 @@ def check_session(func):
#check session: #check session:
vars = web.input(redir_after_login = None) vars = web.input(redir_after_login = None)
ck = cookies() ck = cookies()
if ck.has_key("session_id") and ck["session_id"] in utils.SESSIONS: if ck.has_key("session_id") and ck["session_id"] in utils.config.get("sessions"):
return func(self, name) #check_session:ok return func(self, name) #check_session:ok
elif vars.redir_after_login: elif vars.redir_after_login:
utils.seeother(url("/login",redir=self_url())) utils.seeother(url("/login",redir=self_url()))

View File

@ -68,15 +68,19 @@ def setcookie(key, val):
return w_setcookie(key, val , expires=2592000) return w_setcookie(key, val , expires=2592000)
#really simple sessions, to bad i had to implement them myself. #really simple sessions, to bad i had to implement them myself.
SESSIONS = []
def start_session(): def start_session():
session_id = str(random.random()) session_id = str(random.random())
SESSIONS.append(session_id) config.set("sessions", config.get("sessions") + [session_id])
if len(config.get("sessions")) > 30: #store a max of 20 sessions.
config.set("sessions",config["sessions"][:-20])
setcookie("session_id", session_id) setcookie("session_id", session_id)
config.save()
def end_session(): def end_session():
session_id = getcookie("session_id") session_id = getcookie("session_id")
setcookie("session_id","") setcookie("session_id","")
if session_id in config.get("sessions"):
config.set("sessions", config.get("sessions").append(session_id))
#/sessions #/sessions
def seeother(url, *args, **kwargs): def seeother(url, *args, **kwargs):

View File

@ -60,5 +60,6 @@ CONFIG_DEFAULTS = {
"cache_templates":True, "cache_templates":True,
"daemon":"http://localhost:58846", "daemon":"http://localhost:58846",
"base":"", "base":"",
"disallow":{} "disallow":{},
"sessions":[]
} }