Wednesday 18 August 2010

devise gem provides powerful rails authentication out of the box

I decided that it was time to switch over to authlogic now that I'm a bit more comfortable with ruby and rails, but I couldn't get past an annoying bug where my User.password virtual attribute couldn't be found, despite ensuring that I had the spelling correct for the authlogic "magic" column names, and confirming over and over that I defined attr_accessible :password

Then I stumbled upon a relatively new gem called devise, which comes with modules to satisfy all common project requirements such as automatic account locking, session timeouts, forgotten passwords and more.

After struggling with authlogic for an entire day, it was nice to have devise up and running in a matter of minutes, and see all the aforementioned functionality working out of the box.

One thing that I haven't been able to find online is a convenient reference of the attributes and methods that devise adds to your user model, so I compiled a crude one. It is not categorized by module, but it should be pretty evident by the names:

devise attributes:

confirmation_sent_at
confirmed_at
current_sign_in_ip
failed_attempts
last_sign_in_at
last_sign_in_ip
locked_at
locked_out_at
sign_in_count
unlock_token

devise methods:

access_locked?
active?
confirmation_required?
confirmed?
if_access_locked
lock!
lock_access!
locking_enabled?
lock_expired?
resend_unlock_token
reset_password!
send_reset_password_instructions
timedout?
unless_confirmed
unlock_access!