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
12:- use_module(library(http/http_path)). 13http:location(pldoc, root('help/source'), [priority(10)]).
14
15:- doc_server(4040).
24:- http_handler('/', say_hi, []). 25
29server(Port) :-
30 http_server(http_dispatch, [port(Port)]).
31
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)