Back to index

moin  1.9.0~rc2
Public Member Functions | Public Attributes | Private Member Functions
MoinMoin.web.session.FileSessionService Class Reference
Inheritance diagram for MoinMoin.web.session.FileSessionService:
Inheritance graph
[legend]
Collaboration diagram for MoinMoin.web.session.FileSessionService:
Collaboration graph
[legend]

List of all members.

Public Member Functions

def __init__
def get_session
def destroy_session
def finalize

Public Attributes

 cookie_name
 store

Private Member Functions

def _store_get

Detailed Description

This sample session service stores session information in a temporary
directory and identifies the session via a cookie in the request/response
cycle. It is based on werkzeug's FilesystemSessionStore, that implements
the whole logic for creating the actual session objects (which are
inherited from the builtin `dict`)

Definition at line 63 of file session.py.


Constructor & Destructor Documentation

def MoinMoin.web.session.FileSessionService.__init__ (   self,
  cookie_name = 'MOIN_SESSION' 
)

Definition at line 71 of file session.py.

00071 
00072     def __init__(self, cookie_name='MOIN_SESSION'):
00073         self.cookie_name = cookie_name
00074         self.store = None


Member Function Documentation

def MoinMoin.web.session.FileSessionService._store_get (   self,
  request 
) [private]

Definition at line 75 of file session.py.

00075 
00076     def _store_get(self, request):
00077         if self.store is None:
00078             path = request.cfg.session_dir
00079             try:
00080                 filesys.mkdir(path)
00081             except OSError:
00082                 pass
00083             self.store = FilesystemSessionStore(path=path, filename_template='%s', session_class=MoinSession)
00084         return self.store

Here is the caller graph for this function:

def MoinMoin.web.session.FileSessionService.destroy_session (   self,
  request,
  session 
)
Destroy an existing session (make it unusable). 

Reimplemented from MoinMoin.web.session.SessionService.

Definition at line 95 of file session.py.

00095 
00096     def destroy_session(self, request, session):
00097         session.clear()
00098         store = self._store_get(request)
00099         store.delete(session)

Here is the call graph for this function:

def MoinMoin.web.session.FileSessionService.finalize (   self,
  request,
  session 
)
If the service needs to do anything to the session and/or request,
before it is sent back to the client, he can chose to do so here.
Typical examples would be setting cookies for the client.

Reimplemented from MoinMoin.web.session.SessionService.

Definition at line 100 of file session.py.

00100 
00101     def finalize(self, request, session):
00102         if request.user.auth_method == 'setuid':
00103             userobj = request._setuid_real_user
00104             setuid = request.user.id
00105         else:
00106             userobj = request.user
00107             setuid = None
00108         logging.debug("finalize userobj = %r, setuid = %r" % (userobj, setuid))
00109         cfg = request.cfg
00110         cookie_path = cfg.cookie_path or request.script_root or '/'
00111         if userobj and userobj.valid:
00112             session['user.id'] = userobj.id
00113             session['user.auth_method'] = userobj.auth_method
00114             session['user.auth_attribs'] = userobj.auth_attribs
00115             if setuid:
00116                 session['setuid'] = setuid
00117             elif 'setuid' in session:
00118                 del session['setuid']
00119             logging.debug("after auth: storing valid user into session: %r" % userobj.name)
00120         else:
00121             logging.debug("after auth: user is invalid")
00122             if 'user.id' in session:
00123                 logging.debug("after auth: destroying session: %r" % session)
00124                 self.destroy_session(request, session)
00125                 logging.debug("after auth: deleting session cookie!")
00126                 request.delete_cookie(self.cookie_name, path=cookie_path, domain=cfg.cookie_domain)
00127 
00128         cookie_lifetime = _get_session_lifetime(request, userobj)
00129         if cookie_lifetime:
00130             cookie_expires = time.time() + cookie_lifetime
00131             # a secure cookie is not transmitted over unsecure connections:
00132             cookie_secure = (cfg.cookie_secure or  # True means: force secure cookies
00133                              cfg.cookie_secure is None and request.is_secure)  # None means: https -> secure cookie
00134             logging.debug("user: %r, setting session cookie: %r" % (userobj, session.sid))
00135             request.set_cookie(self.cookie_name, session.sid,
00136                                max_age=cookie_lifetime, expires=cookie_expires,
00137                                 path=cookie_path, domain=cfg.cookie_domain,
00138                                secure=cookie_secure, httponly=cfg.cookie_httponly)
00139 
00140             if session.should_save:
00141                 store = self._store_get(request)
00142                 logging.debug("saving session: %r" % session)
00143                 store.save(session)
00144 

Here is the call graph for this function:

def MoinMoin.web.session.FileSessionService.get_session (   self,
  request,
  sid = None 
)
Return a session object pertaining to the particular request.

Reimplemented from MoinMoin.web.session.SessionService.

Definition at line 85 of file session.py.

00085 
00086     def get_session(self, request, sid=None):
00087         if sid is None:
00088             sid = request.cookies.get(self.cookie_name, None)
00089         store = self._store_get(request)
00090         if sid is None:
00091             session = store.new()
00092         else:
00093             session = store.get(sid)
00094         return session

Here is the call graph for this function:


Member Data Documentation

Definition at line 72 of file session.py.

Definition at line 73 of file session.py.


The documentation for this class was generated from the following file: