email confirmation

0 views
Skip to first unread message

Divia

unread,
May 28, 2009, 6:12:58 PM5/28/09
to weblocks
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. Any help would
be much appreciated, thanks,

Divia

Leslie P. Polzer

unread,
May 29, 2009, 3:41:38 AM5/29/09
to webl...@googlegroups.com

Divia wrote:

> 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.

Divia

unread,
Jun 19, 2009, 2:58:39 AM6/19/09
to weblocks
Thank you so much for this incredibly helpful response. I've been
struggling with trying to get the dispatcher work (and I am still
using the old nav system). The other example code that I've been
trying to get to run is from http://teddyb.org/rlp/tiki-index.php?page=Learning+About+Weblocks.

The error I've been getting has been

SIMPLE-ERROR: There is no class named CONTENTREES::DISPATCHER.
(contentrees is the name of my app)

Here's my code, for reference:

(make-instance
'dispatcher
:on-dispatch (lambda (widget url-bits)
(declare (ignore widget))
(cond
((string= (first url-bits) "main-page")
(make-main-page))
((string= (first url-bits) "account-page")
(if (current-user)
(make-account-page)
"You must sign in to see the account page."))
((not url-bits)
(make-main-page)))))

I tried using 'hunnchentoot::dispatcher instead, but that didn't seem
to work either.

The example code from the same page with selector hasn't been working
either, but it didn't give me an error, just didn't appear to actually
create any working urls.

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. Thanks,

Divia



On May 29, 12:41 am, "Leslie P. Polzer" <s...@viridian-project.de>
wrote:

Leslie P. Polzer

unread,
Jun 19, 2009, 3:48:16 AM6/19/09
to webl...@googlegroups.com

Divia wrote:
>
> Thank you so much for this incredibly helpful response. I've been
> struggling with trying to get the dispatcher work (and I am still
> using the old nav system).

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

Reply all
Reply to author
Forward
0 new messages