-
Notifications
You must be signed in to change notification settings - Fork 0
/
run-example.ss
60 lines (52 loc) · 2.03 KB
/
run-example.ss
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
#lang scheme/base
(require (for-syntax scheme/base)
scheme/runtime-path
web-server/servlet
web-server/servlet-env
"base.ss"
"idcheck.ss"
"test-configuration.ss")
; request -> void
(define (menu request)
; (listof binding)
(define bindings
(request-bindings request))
; (U string #f)
(define action
(and (exists-binding? 'do bindings)
(extract-binding/single 'do bindings)))
(show (cond [(equal? action "login") (login request)]
[(equal? action "logout") (logout request)]
[else request])))
; request -> request
(define (login request)
(idcheck-login request))
; request -> request
(define (logout request)
(idcheck-logout request))
; request -> void
(define (show request)
(send/finish
`(html (head (title "Successfully Logged In"))
(body (h1 "Successfully Logged In")
,@(let* ([key (get-key request)]
[info (and key (lookup-user key))]
[username (and info (get-username info))])
`((p "Action " (a ([href "?do=login"]) "Login")
" " (a ([href "?do=logout"]) "Logout"))
(p "Your IDCheck key is: ")
(blockquote (pre ,(or key "[none]")))
(p "Your details returned by IDCheck are: ")
(blockquote (pre ,(or info "[none]")))
(p "Your username is: ")
(blockquote (pre ,(or username "[none]")))))))))
; Main program body ------------------------------
(print-struct #t)
(serve/servlet
(lambda (request)
(parameterize ([idcheck-url test-idcheck-url]
[idcheck-redirect-url test-idcheck-redirect-url]
[base-url test-base-url]
[idcheck-cookie-domain test-idcheck-cookie-domain])
(menu request)))
#:port 5678)