;;; Create a session if one doesn't already exist.

<require-session
 missing = <prog
	     <set-var anonymous=anonymous>
	     <create-session anonymous allow-multiple>

	     ;;; Create an empty shopping basket
	     <set-var basket::current-item=0>

	     <set-session-timeout 60>>

 timeout = <prog
	     <set-var SID="">
	     <if <get-var mhtml::cookie-compatible>
		 <replace-page <get-var mhtml::current-doc>>
	       <redirect <get-var mhtml::full-url-sans-sid>>>>>

;;; If a page is being loaded as a result of a POST, then we
;;; set the session variable "user-name" to the value that
;;; the user typed in to the input form.
<when <get-var posted::user-name>>
  <set-session-var user-name=<get-var posted::user-name>>
</when>

;;; When this function is called, if a user has not already
;;; logged in, then they're presented with a form to type
;;; their name. If they've already logged in, then an 
;;; appropriate greeting is printed.
<defsubst set-user-name>
  <when <not <get-session-var user-name>>>
    Howdy, stranger. Why don't you take a second and introduce yourself.
    <form method="POST" action="<get-var mhtml::full-url>">
      User Name:<input type=text value="" name="user-name" size=40>
      <input type=submit value="Login">
    </form>
  </when>

  <when <get-session-var user-name>>
    Hello, <b><get-session-var user-name></b>!
  </when>
</defsubst>
