brain.rbinstance_missing
In the last post we added some functionality to our authentication system. We added a “Remember me” functionality to allow users to log in using a cookie and we also added an activation process that authenticates the email address we get from the user.
On this post, i’ll cover password resets:
The logic behind a password reset process is rather simple, basically it is very similar to the activation process we did before.
First, we are going to add a field that will contain that reset token, and a method to generate it when required:
That’s basically it.
We need to add a few actions:
#update action because we need a little different behavior that i think is enough to justify a separate action: First we need to find the user record based on a token not by id and second, we need to use our logout_keeping_session to make sure no malicious changes are made to a logged in user if it exists.The process will work like that:
UsersController#forgot_password.UsersController#send_password_reset will generate a new reset token and send the user with reset instructions.UsersController#reset_password that will match the reset token from the URI to a specific user on the system and allow the user to enter a new password if matched.Here’s the current UsersController:
Source for the UsersController#forgot_password view, UsersController#send_password_reset view, “UserMailer model”http://gist.github.com/325983, Reset instructions mail template and UsersController#reset_password added.
Again, it seems that we tackled most of the problems we had with Mongoid in the early stages and practically nothing bothered us too much since the first part of this series.
I keep the implementation of a background processor until a bit later, it is not that important at this stage so we’ll get back to it later.
| Variable | Value |
|---|---|
| GITHUB | |
| WWR | { :working_with_rails => 'http://www.workingwithrails.com/person/5844-elad-meidar' } |
| IRC | { 'irc.freenode.net' => [ '#rubyonrails', '#railsbridge', '#ruby', '#mootools' ]} |
| SKYPE | eladmeidar |
You're seeing this error because I think it is funny.