user253291
user253291

Reputation:

Confirm link creation with Ruby (on Rails)

What I’d like to achieve is a typical use case: a user enters his email address into a form. After sending the form to my application an email with a random generated link should be sent out to the user which he has to click to confirm his email address. After clicking the link the address should be marked as valid in my application.

My main questions are:

  1. What is the best way to generate such random links?
  2. What is the best way to map the click on such a random link to the address in my database?

Thanks :-).

Upvotes: 1

Views: 790

Answers (3)

Filipe Miguel Fonseca
Filipe Miguel Fonseca

Reputation: 6436

Like @apneadiving and @Brian pointed out you have that feature in Devise and AuthLogic, but in case you need to roll out your what better way than to learn from them:

  1. Set up a confirmations route
  2. Set up a confirmations model
  3. Set up a confirmations controller

The logic is to generate a random token (md5, sha1, whatever..) store it and send it. When your confirmations controller is called you accept the confirmation for the token passed as param.

Upvotes: 2

apneadiving
apneadiving

Reputation: 115521

It's also provided out of the box in Devise: https://github.com/plataformatec/devise

See confirmable option.

Upvotes: 6

Brian Clapper
Brian Clapper

Reputation: 26211

Use AuthLogic. It does all this for you.

Upvotes: 3

Related Questions