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: August 2020

Summary of exported operations:

sessionDataDir :: String   
The name of the local directory where the session data, e.g., cookie information, is stored.
inSessionDataDir :: String -> String   
Prefix a file name with the directory where session data, e.g., cookie information, is stored.
doesSessionExist :: IO Bool   
Checks whether the current user session is initialized, i.e., whether a session cookie has been already set.
sessionCookie :: IO PageParam   
Creates a cookie to hold the current session id.
withSessionCookie :: HtmlPage -> IO HtmlPage   
Decorates an HTML page with session cookie.
withSessionCookieInfo :: HtmlPage -> IO HtmlPage   
Decorates an HTML page with session cookie and shows an information page when the session cookie is not set.
emptySessionStore :: SessionStore a   
An initial value for the empty session store.
getSessionMaybeData :: Global (SessionStore a) -> IO (Maybe a)   
Retrieves data for the current user session stored in a session store.
getSessionData :: Global (SessionStore a) -> a -> IO a   
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 :: Global (SessionStore a) -> a -> IO ()   
Stores data related to the current user session in a session store.
updateSessionData :: Global (SessionStore a) -> a -> (a -> a) -> IO ()   
Updates the data of the current user session.
removeSessionData :: Global (SessionStore a) -> IO ()   
Removes data related to the current user session from a session store.

Exported datatypes:


SessionStore

The type of a session store that holds particular data used in a session. A session store 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:


Exported operations:

sessionDataDir :: String   

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   

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

doesSessionExist :: IO Bool   

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

sessionCookie :: IO PageParam   

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   

Decorates an HTML page with session cookie.

withSessionCookieInfo :: HtmlPage -> IO HtmlPage   

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

emptySessionStore :: SessionStore a   

An initial value for the empty session store.

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

getSessionMaybeData :: Global (SessionStore a) -> IO (Maybe a)   

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

getSessionData :: Global (SessionStore a) -> a -> IO a   

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 :: Global (SessionStore a) -> a -> IO ()   

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

updateSessionData :: Global (SessionStore a) -> a -> (a -> a) -> IO ()   

Updates the data of the current user session.

removeSessionData :: Global (SessionStore a) -> IO ()   

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