Confirm link creation with Ruby (on Rails)
开发者_JAVA技巧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:
- What is the best way to generate such random links?
- What is the best way to map the click on such a random link to the address in my database?
Thanks :-).
It's also provided out of the box in Devise: https://github.com/plataformatec/devise
See confirmable
option.
Use AuthLogic. It does all this for you.
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:
- Set up a confirmations route
- Set up a confirmations model
- 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.
精彩评论