From d26f90f72bb2f9652b365fcb5a008f6ae736d12f Mon Sep 17 00:00:00 2001 From: "Carlos A. da Silva" Date: Tue, 20 Oct 2009 00:52:31 -0200 Subject: [PATCH] Updating docs and TODO. --- README.rdoc | 17 +++++++++++++++-- TODO | 4 +++- lib/devise/active_record.rb | 7 +++++-- lib/devise/models/rememberable.rb | 15 ++++++++++++++- 4 files changed, 37 insertions(+), 6 deletions(-) diff --git a/README.rdoc b/README.rdoc index 06c747a8..85236a2f 100644 --- a/README.rdoc +++ b/README.rdoc @@ -12,6 +12,7 @@ Right now it's composed of four mainly modules: * Authenticable: responsible for encrypting password and validating authenticity of a user while signing in. * Confirmable: responsible for verifying whether an account is already confirmed to sign in, and to send emails with confirmation instructions. * Recoverable: takes care of reseting the user password and send reset instructions. +* Rememberable: manages generating and clearing token for remember the user from a saved cookie. * Validatable: creates all needed validations for email and password. It's totally optional, so you're able to to customize validations by yourself. == Dependencies @@ -49,6 +50,15 @@ We're assuming here you want a User model. First of all you have to setup a migr # required for recoverable t.string :reset_password_token + # required for rememberable + t.string :remember_token + +You may also want to add some indexes to improve performance: + + add_index :your_table, :email + add_index :your_table, :confirmation_token # for confirmable + add_index :your_table, :reset_password_token # for recoverable + Now let's setup a User model adding the devise line to have your authentication working: class User < ActiveRecord::Base @@ -66,8 +76,11 @@ This line adds devise authenticable automatically for you inside your User class # Include authenticable + recoverable devise :recoverable - # Include authenticable + confirmable + recoverable + validatable - devise :confirmable, :recoverable, :validatable + # Include authenticable + rememberable modules + devise :rememberable + + # Include authenticable + confirmable + recoverable + rememberable + validatable + devise :confirmable, :recoverable, :rememberable, :validatable # Same as above, include all of them devise :all diff --git a/TODO b/TODO index 98ee4f3f..58eb0175 100644 --- a/TODO +++ b/TODO @@ -1,4 +1,4 @@ -* Add remember me (with customizable time frame) +* Add customizable time frame for remember me * Create generators * Allow stretches and pepper per model @@ -32,3 +32,5 @@ * Add confirmation_sent_at for confirmable * Add confirmable filters * Sign user in automatically after confirming or changing it's password + +* Add remember me diff --git a/lib/devise/active_record.rb b/lib/devise/active_record.rb index 106c0b10..bbdee474 100644 --- a/lib/devise/active_record.rb +++ b/lib/devise/active_record.rb @@ -13,11 +13,14 @@ module Devise # # include authenticable + recoverable modules # devise :recoverable # + # # include authenticable + rememberable modules + # devise :rememberable + # # # include authenticable + validatable modules # devise :validatable # - # # include authenticable + confirmable + recoverable + validatable - # devise :confirmable, :recoverable, :validatable + # # include authenticable + confirmable + recoverable + rememberable + validatable + # devise :confirmable, :recoverable, :rememberable, :validatable # # # shortcut to include all modules (same as above) # devise :all diff --git a/lib/devise/models/rememberable.rb b/lib/devise/models/rememberable.rb index b98b5e00..e6a5c6c4 100644 --- a/lib/devise/models/rememberable.rb +++ b/lib/devise/models/rememberable.rb @@ -3,7 +3,20 @@ require 'digest/sha1' module Devise module Models - # Rememberable Module + # Rememberable manages generating and clearing token for remember the user + # from a saved cookie. Rememberable also has utility methods for dealing + # with serializing the user into the cookie and back from the cookie, trying + # to lookup the record based on the saved information. + # You probably wouldn't use rememberable methods directly, they are used + # mostly internally for handling the remember token. + # Examples: + # + # User.find(1).remember_me! # regenerating the token + # User.find(1).forget_me! # clearing the token + # # generating info to put into cookies + # User.serialize_into_cookie(user) + # # lookup the user based on the incoming cookie information + # User.serialize_from_cookie(cookie_string) module Rememberable def self.included(base)