Example #1
0
 def __init__(self, id):
     Session.__init__(self, id)
     self.dirty = False
     
     self.user = None
     self.results = []
     self.breadcrumbs = []
     
     self.wantedit = False               # true if the user wants to edit things
Example #2
0
 def start_request(self):
     """
     This is called from the main object publishing loop whenever
     we start processing a new request.  Obviously, this is a good
     place to track the number of requests made.  (If we were
     interested in the number of *successful* requests made, then
     we could override finish_request(), which is called by
     the publisher at the end of each successful request.)
     """
     Session.start_request(self)
     self.num_requests += 1
Example #3
0
	def start_request (self):
		Session.start_request(self)

		request = get_request()
		t = time.time()
		request.response.set_charset('utf-8')
		# Determine IP of originator, keep Squid in mind :-)
		try:
			self.ip = request.environ['HTTP_X_FORWARDED_FOR']
		except:
			self.ip = request.environ['REMOTE_ADDR']
		self.port = request.environ['REMOTE_PORT']


		#session = sessions.setdefault(ip,
		#	configlets.Holder(
		#		firstaccess=t,
		#		user=None,
		#		phone='',
		#		language='en',
		#		level=-1,		# Try to auto-login, based on IP
		#	))

		# level==-1 means we should auto-login
		# This works by searching for the first CfgOptUser configlet where
		# the 'pc' variable matches the request originating IP:
		if self.level == -1:
			# Only try auto-login once, so set it to lowest level
			self.level = 0

			users = backend.getConfiglets(name="CfgOptUser")
			if len(users) == 0:
				# be Admin if there are no users configured
				self.user  = "programmer"
				self.level = 4
				self.language = 'en'
				sys.stderr.write ("[%s] Logging in with user 'programmer' from ip %s, port %s\n" % (time.asctime(time.localtime()), self.ip, self.port))
			else:
				for user in users:
					if user.pc == self.ip:
						self.user = user.name
						self.level = int(user.level)
						self.phone = user.phone
						self.language = user.language
						break
						
		language.setLanguage(self.language)				
Example #4
0
    def has_info(self):
        """
        Overriding has_info() is essential but non-obvious.  The
        session manager uses has_info() to know if it should hang on
        to a session object or not: if a session is "dirty", then it
        must be saved.  This prevents saving sessions that don't need
        to be saved, which is especially important as a defensive
        measure against clients that don't handle cookies: without it,
        we might create and store a new session object for every
        request made by such clients.  With has_info(), we create the
        new session object every time, but throw it away unsaved as
        soon as the request is complete.

        (Of course, if you write your session class such that
        has_info() always returns true after a request has been
        processed, you're back to the original problem -- and in fact,
        this class *has* been written that way, because num_requests
        is incremented on every request, which makes has_info() return
        true, which makes SessionManager always store the session
        object.  In a real application, think carefully before putting
        data in a session object that causes has_info() to return
        true.)
        """
        return (self.num_requests > 0) or Session.has_info(self)
Example #5
0
	def has_info(self):
		return Session.has_info(self)
Example #6
0
	def __init__(self, id):
		Session.__init__(self, id)
		self.level = -1
		self.language = 'en'
Example #7
0
 def __init__(self, session_id):
     Session.__init__(self, session_id)
     self.n = 0
Example #8
0
 def _set_access_time (self, resolution):
     Session._set_access_time(self, resolution)
     self._dirty = 1
Example #9
0
 def __init__ (self, request, id):
     Session.__init__(self, request, id)
     self.messages = ''
     self._dirty = 0
     self._form_tokens = []
Example #10
0
 def __init__(self, id):
     Session.__init__(self, id)
     self.num_requests = 0
Example #11
0
 def has_info(self):
     return self.user is not None or \
            (self.results is not None and len(self.results) != 0) or \
            self.breadcrumbs or \
            Session.has_info(self)
Example #12
0
 def start_request(self):
     Session.start_request(self)
Example #13
0
 def __init__(self, id):
     Session.__init__(self, id)
     self.user = {}
Example #14
0
 def __init__(self,id):
     #super(MySession,self).__init__(id)
     Session.__init__(self,id)  #old-style class
     self.token = None