1:- module(login_testing, []).    2:- use_module(library(http/thread_httpd)).    3:- use_module(library(http/http_dispatch)).    4:- use_module(library(http/http_error)).    5:- use_module(library(http/html_write)).    6:- use_module(library(http/http_session)).    7:- use_module(login_box).    8
    9
   10% Just so we can read the pldocs
   11%
   12:- use_module(library(http/http_path)).   13http:location(pldoc, root('help/source'), [priority(10)]).
   14
   15:- doc_server(4040).
   21% Declare a handler, binding an HTTP path to a predicate.
   22% Here our path is / (the root) and the goal we'll query will be
   23% say_hi. The third argument is for options
   24:- http_handler('/', say_hi, []).   25
   26% The predicate server(+Port) starts the server. It simply creates a
   27% number of Prolog threads and then returns to the toplevel, so you can
   28% (re-)load code, debug, etc.
   29server(Port) :-
   30        http_server(http_dispatch, [port(Port)]).
   31
   32/* The implementation of /. The single argument provides the request
   33details, which we ignore for now. Our task is to write a CGI-Document:
   34a number of name: value -pair lines, followed by two newlines, followed
   35by the document content, The only obligatory header line is the
   36Content-type: <mime-type> header.
   37Printing is done with print_html, which takes a list of tokens and
   38prints them. It attempts to 'reasonably' format html when it recognizes
   39tags. */
   40
   41say_hi(_Request) :-
   42	phrase(
   43	       html(html(
   44		[head(title('Howdy')),
   45		 body([h1('A Simple Web Page'),
   46		       div(class=container,[\login_box([])]),
   47		       p('With some text')])])),
   48	       TokenizedHtml,
   49	       []),
   50        format('Content-type: text/html~n~n'),
   51	print_html(TokenizedHtml).
   57:- http_handler('/control', control, []).   58
   59control(_Request):-
   60	(http_in_session(_), http_session_data(user(Name)))
   61	-> logged(Name)
   62	; (phrase(
   63	       html(html(
   64		[head(title('Sorry')),
   65		 body([h1('Members only')])])),
   66			 TokenizedHtml,
   67			 []),
   68	 format('Content-type: text/html~n~n'),
   69	 print_html(TokenizedHtml)
   70	).
   71
   72logged(Name) :-
   73	phrase(
   74	       html(html(
   75		[head(title('Super Secret Page')),
   76		 body([h1(['Welcome ', Name])])])),
   77			 TokenizedHtml,
   78			 []),
   79	 format('Content-type: text/html~n~n'),
   80	 print_html(TokenizedHtml)