> I'd like to set up email confirmation for my app (user signs up with
> an email address, receives an email with a link to click on to confirm
> that the email address actually belongs to the person who signed up),
> but I'm confused about how to do this with Weblocks.
Generating a confirmation code:
(defun confirmation-hash (email)
(sha1 (concatenate 'string email "salt")))
Installing a confirmation hash (substitute your own storage
mechanism for this):
(defvar *confirmation-hashes* (make-hash-table :test #'equalp))
(defun register-confirmation-hash (email hash)
(setf (gethash email *confirmation-hashes*) hash))
(defun confirmation-hash-correct-p (email hash)
(equalp (gethash email *confirmation-hashes*) hash))
Generating a confirmation link:
(defun make-confirmation-link (email)
(apply #'format nil "http://myhost/confirm-user/~A/~A"
(mapcar #'url-encode (list email (confirmation-hash email)))))
Installing a matching dispatcher (old nav system):
(defwidget top-navigation (navigation)
())
(defmethod selector-on-dispatch ((selector top-navigation) tokens)
(if (and (eql (length tokens) 3)
(equalp (first tokens "confirm-user")))
(let ((email (second tokens))
(hash (third tokens)))
(cond
((confirmation-hash-correct-p email hash)
(confirm-email email)
(values "You got it!" tokens nil))
(t
(values "Uh, sorry... :/" tokens nil))))
(call-next-method))) ; defer to static navigation
(defun init-user-session (root)
(setf (widget-children root)
(list (init-navigation (make-instance 'top-navigation :name "Main nav")
...))))
Untested.
You're welcome!
> The error I've been getting has been
>
> SIMPLE-ERROR: There is no class named CONTENTREES::DISPATCHER.
> (contentrees is the name of my app)
>
> [...]
>
> I tried using 'hunnchentoot::dispatcher instead, but that didn't seem
> to work either.
No, the dispatcher class I was referring to should be supplied by
Weblocks.
What version of Weblocks are you using (or upload your tree
somewhere)?
Looks like yours is *very* old. :)
> I've been reading the navigation code, and while I definitely
> understand it better than I did before, I can't figure out what I'm
> doing wrong. Any tips would be extremely helpful, but if you think
> the new navigation is stable enough that I should just upgrade to
> that, then maybe it makes more sense for me to do so and invest any
> further effort in understanding that code.
The new navigation is pretty stable apart from one bug which
isn't solved yet. This bug only affects you if you're trying
to swap in a navigation in an AJAX request:
;; example 1
(with-flow (root-composite)
(yield (make-login ...))
(yield (make-navigation ...)))
;; example 2
(render-link (lambda (&rest args)
(setf (composite-widgets my-composite)
(list (make-navigation ...))))
"Nav it")
If you're not doing anything like this then I suggest
upgrading to the latest -dev.
Otherwise I'll help you getting your work done with
the version of Weblocks you are using right now.
Cheers!
Leslie