user1222136
user1222136

Reputation: 553

Adding confirmed to a nearly complete rails application

I am coming to the end of my rails project now and I have done everything I wish to do apart from confirm the users account through email before creating it. I already have it to send an email to the user but I want the user to contain a link. It's far too late to add devise now as I already have a users table etc.

I have heard of having a confirmed field in the users table and having it set to false and then true on user confirmation, but I have no idea on how to implement this. Any ideas?

If anyone else has some other solutions or links to tutorials showing how to add such feature then that would be outstanding. The end is so close yet so far.

Upvotes: 0

Views: 127

Answers (1)

Sergio Tulentsev
Sergio Tulentsev

Reputation: 230386

It's never too late to add devise. If I were you, I'd do exactly this.

But, if I were to implement confirmation functionality myself, this is how I would go about this:

  1. For each user, make a hash (as in MD5 hash). There are many ways: 1) for each user generate its own and store in a dedicated table column; 2) make one out of password salt, user id and (optionally) some static strings; 3) something else.

  2. Send a user an email with a link, which contains his id and that hash.

  3. When someone hits your confirmation url, you extract user id and hash from query string, and compare them with what you have. If they match, then you mark user as confirmed.

Upvotes: 1

Related Questions