(module special-prefs mzscheme
        (require "hwikireq.scm")
        (require "page.scm")
        (require "config.scm")
        (require "context.scm")
        (require "users.scm")
        (require "template.scm")
        (provide special:prefs)

         (this (special:prefs context))
         (supers (page-base))
          (define _template (template 'context context 'name "admin"))
          (define (get-template)  _template)
          (define (css)           (-> _template css))
          (define (title)         (_ "HWiki Preferences - Change Password"))

          (define (create-html)
            (if (not (-> context logged-in?))
                (-> supers not-autorized context 
                    `(p ,(_ "You must login to be able to set your preferences")))
                (let ((P (page context (-> context from-where))))
                  (debug "create-html:P:" (-> P name))
                  (let ((T (-> P get-template)))
                    (let ((form (lambda (url)
                                  (adjust-timeout! (form-timeout))
                                  (->  context make-response/xhtml
                                         ,(-> supers create-header context)
                                          (div ((class "prefs"))
                                               (h1 ,(_ "Change Password"))
                                               (form ((name "prefs") (action ,url) (method "post"))
                                                      (tr (td ,(_ "Password:") (td (input ((type "password") (name "pass1") (size "40"))))))
                                                      (tr (td ,(_ "Password again:") (td (input ((type "password") (name "pass2") (size "40"))))))
                                                      (tr  (td ((class "tdbutton")) (input ((type "submit") (name "submit") (value ,(_ "cancel")))))
                                                           (td ((class "tdbutton")) (input ((type "submit") (name "submit") (value ,(_ "ok"))))))))
                      (let ((bindings (request-bindings (send/suspend form))))
                        (let ((action (extract-binding/single 'submit bindings))
                              (pass1 (extract-binding/single 'pass1 bindings))
                              (pass2 (extract-binding/single 'pass2 bindings)))
                          (if (string-ci=? action (_ "ok"))
                              (if (string=? pass1 pass2)
                                  (let ((U (users context)))
                                    (-> U set-pass (-> context user) pass1)
                                    (-> context to-from-where))
                                  (-> this do-error (_ "Passwords differ from each other") create-html))
                              (-> context to-from-where)))))))

          (-> supers special!)

        (register-page "special:prefs" special:prefs)