Renamed authenticable to authenticatable and added deprecation warnings.

This commit is contained in:
José Valim
2009-10-30 08:29:10 -02:00
parent 8c1bab4951
commit b28d7e8b1c
17 changed files with 61 additions and 46 deletions

View File

@@ -1,9 +1,9 @@
module Devise
ALL = [:authenticable, :confirmable, :recoverable, :rememberable, :validatable].freeze
ALL = [:authenticatable, :confirmable, :recoverable, :rememberable, :validatable].freeze
# Maps controller names to devise modules
CONTROLLERS = {
:sessions => :authenticable,
:sessions => :authenticatable,
:passwords => :recoverable,
:confirmations => :confirmable
}.freeze

View File

@@ -32,22 +32,22 @@ module Devise
#
# Examples:
#
# # include only authenticable module (default)
# # include only authenticatable module (default)
# devise
#
# # include authenticable + confirmable modules
# # include authenticatable + confirmable modules
# devise :confirmable
#
# # include authenticable + recoverable modules
# # include authenticatable + recoverable modules
# devise :recoverable
#
# # include authenticable + rememberable modules
# # include authenticatable + rememberable modules
# devise :rememberable
#
# # include authenticable + validatable modules
# # include authenticatable + validatable modules
# devise :validatable
#
# # include authenticable + confirmable + recoverable + rememberable + validatable
# # include authenticatable + confirmable + recoverable + rememberable + validatable
# devise :confirmable, :recoverable, :rememberable, :validatable
#
# # shortcut to include all modules (same as above)
@@ -59,9 +59,16 @@ module Devise
def devise(*modules)
options = modules.extract_options!
# TODO Remove me in a next release
if modules.include?(:authenticable)
modules.delete(:authenticable)
modules.unshift(:authenticatable)
ActiveSupport::Deprecation.warn "devise :authenticate is deprecated, use authenticatable instead"
end
modules = Devise::ALL if modules.include?(:all)
modules -= Array(options.delete(:except))
modules |= [:authenticable]
modules = [:authenticatable] | modules
modules.each do |m|
devise_modules << m.to_sym

View File

@@ -54,8 +54,8 @@ module Devise
# Example:
#
# Maps:
# User => :authenticable
# Admin => :authenticable
# User => :authenticatable
# Admin => :authenticatable
#
# Generated methods:
# authenticate_user! # Signs user in or redirect

View File

@@ -18,7 +18,7 @@ module Devise
# mapping.to #=> User
# # is the class to be loaded from routes, given in the route as :class_name.
#
# mapping.for #=> [:authenticable]
# mapping.for #=> [:authenticatable]
# # is the modules included in the class
#
class Mapping #:nodoc:

View File

@@ -2,7 +2,7 @@ module Devise
# Helpers to migration:
#
# create_table :accounts do |t|
# t.authenticable
# t.authenticatable
# t.confirmable
# t.recoverable
# t.rememberable
@@ -19,13 +19,20 @@ module Devise
# Creates email, encrypted_password and password_salt.
#
def authenticable(options={})
def authenticatable(options={})
null = options[:null] || false
string :email, :limit => 100, :null => null
string :encrypted_password, :limit => 40, :null => null
string :password_salt, :limit => 20, :null => null
end
# TODO Remove me in a next release.
#
def authenticable(*args)
ActiveSupport::Deprecation.warn "authenticable in migrations is deprecated, use authenticatable instead"
authenticatable(*args)
end
# Creates confirmation_token, confirmed_at and confirmation_sent_at.
#
def confirmable

View File

@@ -1,5 +1,5 @@
require 'digest/sha1'
require 'devise/strategies/authenticable'
require 'devise/strategies/authenticatable'
module Devise
module Models
@@ -24,7 +24,7 @@ module Devise
# User.authenticate('email@test.com', 'password123') # returns authenticated user or nil
# User.find(1).valid_password?('password123') # returns true/false
#
module Authenticable
module Authenticatable
def self.included(base)
base.class_eval do
extend ClassMethods
@@ -75,8 +75,8 @@ module Devise
# authenticated user if it's valid or nil.
# Attributes are :email and :password
def authenticate(attributes={})
authenticable = find_by_email(attributes[:email])
authenticable if authenticable.try(:valid_password?, attributes[:password])
authenticatable = find_by_email(attributes[:email])
authenticatable if authenticatable.try(:valid_password?, attributes[:password])
end
# Attempt to find a user by it's email. If not user is found, returns a

View File

@@ -19,7 +19,7 @@ module ActionController::Routing
# generate all needed routes for devise, based on what modules you have
# defined in your model.
# Examples: Let's say you have an User model configured to use
# authenticable, confirmable and recoverable modules. After creating this
# authenticatable, confirmable and recoverable modules. After creating this
# inside your routes:
#
# map.devise_for :users
@@ -27,7 +27,7 @@ module ActionController::Routing
# this method is going to look inside your User model and create the
# needed routes:
#
# # Session routes for Authenticable (default)
# # Session routes for Authenticatable (default)
# new_user_session GET /users/sign_in {:controller=>"sessions", :action=>"new"}
# user_session POST /users/sign_in {:controller=>"sessions", :action=>"create"}
# destroy_user_session GET /users/sign_out {:controller=>"sessions", :action=>"destroy"}
@@ -69,7 +69,7 @@ module ActionController::Routing
mapping = Devise::Mapping.new(resource, options)
Devise.mappings[mapping.name] = mapping
if mapping.authenticable?
if mapping.authenticatable?
with_options(:controller => 'sessions', :path_prefix => mapping.as) do |session|
session.send(:"new_#{mapping.name}_session", mapping.path_names[:sign_in], :action => 'new', :conditions => { :method => :get })
session.send(:"#{mapping.name}_session", mapping.path_names[:sign_in], :action => 'create', :conditions => { :method => :post })

View File

@@ -2,7 +2,7 @@ module Devise
module Strategies
# Default strategy for signing in a user, based on his email and password.
# Redirects to sign_in page if it's not authenticated
class Authenticable < Devise::Strategies::Base
class Authenticatable < Devise::Strategies::Base
# Authenticate a user based on email and password params, returning to warden
# success and the authenticated user if everything is okay. Otherwise redirect
@@ -43,4 +43,4 @@ module Devise
end
end
Warden::Strategies.add(:authenticable, Devise::Strategies::Authenticable)
Warden::Strategies.add(:authenticatable, Devise::Strategies::Authenticatable)

View File

@@ -3,7 +3,7 @@ module Devise
# Remember the user through the remember token. This strategy is responsible
# to verify whether there is a cookie with the remember token, and to
# recreate the user from this cookie if it exists. Must be called *before*
# authenticable.
# authenticatable.
class Rememberable < Devise::Strategies::Base
# A valid strategy for rememberable needs a remember token in the cookies.

View File

@@ -55,7 +55,7 @@ require 'devise/strategies/base'
# Adds Warden Manager to Rails middleware stack, configuring default devise
# strategy and also the controller who will manage not authenticated users.
Rails.configuration.middleware.use Warden::Manager do |manager|
manager.default_strategies :rememberable, :authenticable
manager.default_strategies :rememberable, :authenticatable
manager.failure_app = Devise::Failure
manager.silence_missing_strategies!
end