Module HTML.Session

This module implements the management of sessions. In particular, it defines a cookie that must be sent to the client in order to enable the handling of sessions. Based on sessions, this module also defines a session store that can be used by various parts of the application in order to hold some session-specific data.

Author: Michael Hanus

Version: May 2021

Summary of exported operations:

sessionDataDir :: String  Deterministic 
The name of the local directory where the session data, e.g., cookie information, is stored.
inSessionDataDir :: String -> String  Deterministic 
Prefix a file name with the directory where session data, e.g., cookie information, is stored.
doesSessionExist :: IO Bool  Deterministic 
Checks whether the current user session is initialized, i.e., whether a session cookie has been already set.
sessionCookie :: IO PageParam  Deterministic 
Creates a cookie to hold the current session id.
withSessionCookie :: HtmlPage -> IO HtmlPage  Deterministic 
Decorates an HTML page with session cookie.
withSessionCookieInfo :: HtmlPage -> IO HtmlPage  Deterministic 
Decorates an HTML page with session cookie and shows an information page when the session cookie is not set.
emptySessionData :: SessionData a  Deterministic 
An initial value for the empty session data.
sessionStore :: (Read a, Show a) => String -> GlobalP (SessionData a)  Deterministic 
A session store contains readable and showable data kept in a store with a given name.
getSessionMaybeData :: (Read a, Show a) => GlobalP (SessionData a) -> FormReader (Maybe a)  Deterministic 
Retrieves data for the current user session stored in a session store.
getSessionData :: (Read a, Show a) => GlobalP (SessionData a) -> a -> FormReader a  Deterministic 
Retrieves data for the current user session stored in a session store where the second argument is returned if there is no data for the current session.
putSessionData :: (Read a, Show a) => GlobalP (SessionData a) -> a -> IO ()  Deterministic 
Stores data related to the current user session in a session store.
modifySessionData :: (Read a, Show a) => GlobalP (SessionData a) -> a -> (a -> a) -> IO ()  Deterministic 
Modifies the data of the current user session.
removeSessionData :: (Read a, Show a) => GlobalP (SessionData a) -> IO ()  Deterministic 
Removes data related to the current user session from a session store.

Exported datatypes:


SessionData

The type of session data which represents the data used in a session. The session data consists of a list of data items for each session in the system together with the clock time of the last access. The clock time is used to remove old data in the store.

Constructors:


SessionStore

The type of a session store is a persistent global entity containing a session store with some data.

Type synonym: SessionStore a = GlobalP (SessionData a)


Exported operations:

sessionDataDir :: String  Deterministic 

The name of the local directory where the session data, e.g., cookie information, is stored. For security reasons, the directory should be non-public readable.

Further infos:
  • solution complete, i.e., able to compute all solutions

inSessionDataDir :: String -> String  Deterministic 

Prefix a file name with the directory where session data, e.g., cookie information, is stored.

doesSessionExist :: IO Bool  Deterministic 

Checks whether the current user session is initialized, i.e., whether a session cookie has been already set.

sessionCookie :: IO PageParam  Deterministic 

Creates a cookie to hold the current session id. This cookie should be sent to the client together with every HTML page.

withSessionCookie :: HtmlPage -> IO HtmlPage  Deterministic 

Decorates an HTML page with session cookie.

withSessionCookieInfo :: HtmlPage -> IO HtmlPage  Deterministic 

Decorates an HTML page with session cookie and shows an information page when the session cookie is not set.

emptySessionData :: SessionData a  Deterministic 

An initial value for the empty session data.

Further infos:
  • solution complete, i.e., able to compute all solutions

sessionStore :: (Read a, Show a) => String -> GlobalP (SessionData a)  Deterministic 

A session store contains readable and showable data kept in a store with a given name. The name is used as a file name in the directory containing all session data.

getSessionMaybeData :: (Read a, Show a) => GlobalP (SessionData a) -> FormReader (Maybe a)  Deterministic 

Retrieves data for the current user session stored in a session store. Returns Nothing if there is no data for the current session.

getSessionData :: (Read a, Show a) => GlobalP (SessionData a) -> a -> FormReader a  Deterministic 

Retrieves data for the current user session stored in a session store where the second argument is returned if there is no data for the current session.

putSessionData :: (Read a, Show a) => GlobalP (SessionData a) -> a -> IO ()  Deterministic 

Stores data related to the current user session in a session store.

modifySessionData :: (Read a, Show a) => GlobalP (SessionData a) -> a -> (a -> a) -> IO ()  Deterministic 

Modifies the data of the current user session.

removeSessionData :: (Read a, Show a) => GlobalP (SessionData a) -> IO ()  Deterministic 

Removes data related to the current user session from a session store.