Welcome to the CHICKEN Scheme pasting service

single window web app added by mario-goulart on Tue Oct 25 20:15:55 2011

(use awful html-tags html-utils)

(enable-session #t)
(enable-ajax #t)
(valid-password? (lambda _ #t))

;; Store the window id in the session on successful login
(define-login-trampoline "/login-trampoline"
  hook: (lambda _
	  (and (sid) ($session-set! 'window-id ($ 'window-id)))))


;; Return the window id stored in the session
(define-page "/window-id"
  (lambda ()
    ($session 'window-id))
  no-template: #t)


;; The login page
(define-page (login-page-path)
  (lambda ()
    (add-javascript
     "var currentTime = new Date();"
     "var now = currentTime.getTime();"
     "self.window.name = now;"
     "$('#window-id').val(now);")

    (<form> action: "/login-trampoline" method: "post"
	    (hidden-input 'window-id "")
	    (<span> id: "user-container"
		    (<span> id: "user-label" "User")
		    (text-input 'user))
	    (<span> id: "password-container"
		    (<span> id: "password-label" "Password")
		    (password-input 'password))
	    (<input> type: "submit" id: "login-submit")))
  no-session: #t)


;; Page definer for pages that should check the window id
(define (define-same-window-page path content)
  (define-page path
    (lambda ()
      (add-javascript
       "$.get('/window-id', function(window_id) {
        if (!(window_id === self.window.name)) {
           $('body').html('');
           alert('This application does not support multiple windows/tabs.');
        }});")
      (content))))


;; The main page
(define-same-window-page (main-page-path)
  (lambda ()
    (link "/foo" "foo")))


;; A page
(define-same-window-page "/foo"
  (lambda ()
    "foo"))

Your annotation:

Enter a new annotation:

Your nick:
The title of your paste:
Your paste (mandatory) :
What's the operator to construct procedures?
Visually impaired? Let me spell it for you (wav file) download WAV