Sorry about my incomplete post, I was in a serious hurry, off to a
company luncheon. So, here is the strategy I was hoping to convey.

First, I wouldn't put it in the User model personally, simply because it
doesn't really have anything to do with a User in the conventional OO
paradigm. It would be useful to have an method is_verified? that checks
a :verified attribute though. With that said, here's an updated
description of UserVerification (i prefer it to UserVerification for
disambiguation with common rails terms):




1. user_verification migration:
..
t.column :user_id, :integer # user id instead of username, id will not
change
t.column :hash, :string # SHA1 hash
t.column :salts, :text # serialized Array
t.column :created_at, :datetime
..




2. UserVerification model:
..
before_save :generate_hash
after_save :send_verification_email
after_destroy :make_user_valid
..
belongs_to :user
serialize :salts, Array
..
def user_valid?(hash_from_email)
  (self.hash == hash_from_email)
end
..
protected
def generate_hash
  self.hash = Digest::SHA1.hexdigest(self.salts.join)
end
..
def send_verification_email
  ... #send email to user with link:
domain.com/validate?hash=892he98hd...&[EMAIL PROTECTED]
end
..
def make_user_valid
   ...
   self.user.verified = true
   self.user.save
   ...
end


3. Then, when the user clicks the link in the email, you'll have a
verification method that says:
..
verify = UserVerification.find_by_hash(params[:hash])
if User.find_by_email(:params[:email]) == verify.user
  verify.destroy # user becomes valid
end
..


Hope this helps/makes sense!!

-Jordan


On 10/11/2006, "Patrick Crowley" <[EMAIL PROTECTED]> wrote:

>I'd prefer to keep this stuff in the User model, but I like the
>serialization trick, Jordan.
>
>Best,
>Patrick
>
>
>On Oct 11, 2006, at 12:22 PM, Nick Zadrozny wrote:
>
>> On 10/11/06, Nick Zadrozny <[EMAIL PROTECTED]> wrote:
>>> For that second step, wouldn't you have to know or hardcode the
>>> position of the username?
>>
>> Wait, I'm an idiot. You have the username in the UserValidation
>> migration. And I'm increasingly not sure that those columns have to be
>> in a separate model from your User object in the first place. I think
>> I figured out my own questions :-)
>>
>> --
>> Nick Zadrozny
>> _______________________________________________
>> Sdruby mailing list
>> [email protected]
>> http://lists.sdruby.com/mailman/listinfo/sdruby
>
>_______________________________________________
>Sdruby mailing list
>[email protected]
>http://lists.sdruby.com/mailman/listinfo/sdruby
_______________________________________________
Sdruby mailing list
[email protected]
http://lists.sdruby.com/mailman/listinfo/sdruby

Reply via email to