1
0
Fork 0
mirror of https://github.com/heartcombo/devise.git synced 2022-11-09 12:18:31 -05:00

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

@ -4,6 +4,7 @@
* deprecations
* Renamed confirm_in to confirm_within
* [#14] Do not send confirmation messages when user changes his e-mail
* [#13] Renamed authenticable to authenticatable and added deprecation warnings
== 0.2.3

View file

@ -9,7 +9,7 @@ Devise is a flexible authentication solution for Rails based on Warden. It:
Right now it's composed of five mainly modules:
* Authenticable: responsible for encrypting password and validating authenticity of a user while signing in.
* Authenticatable: 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.
@ -51,7 +51,7 @@ Devise must be setted up within the model (or models) you want to use, and devis
We're assuming here you want a User model. First of all you have to setup a migration with the following fields:
create_table :users do
t.authenticable
t.authenticatable
t.confirmable
t.recoverable
t.rememberable
@ -70,17 +70,17 @@ Now let's setup a User model adding the devise line to have your authentication
devise
end
This line adds devise authenticable automatically for you inside your User class. Devise don't rely on _attr_accessible_ or _attr_protected_ inside its modules, so be sure to setup what attributes are accessible or protected in your model.
This line adds devise authenticatable automatically for you inside your User class. Devise don't rely on _attr_accessible_ or _attr_protected_ inside its modules, so be sure to setup what attributes are accessible or protected in your model.
You could also include the other devise modules as below:
# Same as using only devise, authenticable is activated by default
devise :authenticable
# Same as using only devise, authenticatable is activated by default
devise :authenticatable
# Include authenticable + confirmable
# Include authenticatable + confirmable
devise :confirmable
# Include authenticable + recoverable + rememberable
# Include authenticatable + recoverable + rememberable
devise :recoverable, :rememberable
# Include all of them
@ -123,7 +123,7 @@ The next step after setting up your model is to configure your routes for devise
This is going to look inside you 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"}
@ -191,7 +191,7 @@ Devise let's you setup as many roles as you want, so let's say you already have
# Create a migration with the required fields
create_table :admins do |t|
t.authenticable
t.authenticatable
end
# Inside your Admin model

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

View file

@ -54,38 +54,38 @@ class ActiveRecordTest < ActiveSupport::TestCase
end
end
test 'include by default authenticable only' do
assert_include_modules Authenticable, :authenticable
test 'include by default authenticatable only' do
assert_include_modules Authenticable, :authenticatable
assert_not_include_modules Authenticable, :confirmable, :recoverable, :rememberable, :validatable
end
test 'add confirmable module only' do
assert_include_modules Confirmable, :authenticable, :confirmable
assert_include_modules Confirmable, :authenticatable, :confirmable
assert_not_include_modules Confirmable, :recoverable, :rememberable, :validatable
end
test 'add recoverable module only' do
assert_include_modules Recoverable, :authenticable, :recoverable
assert_include_modules Recoverable, :authenticatable, :recoverable
assert_not_include_modules Recoverable, :confirmable, :rememberable, :validatable
end
test 'add rememberable module only' do
assert_include_modules Rememberable, :authenticable, :rememberable
assert_include_modules Rememberable, :authenticatable, :rememberable
assert_not_include_modules Rememberable, :confirmable, :recoverable, :validatable
end
test 'add validatable module only' do
assert_include_modules Validatable, :authenticable, :validatable
assert_include_modules Validatable, :authenticatable, :validatable
assert_not_include_modules Validatable, :confirmable, :recoverable, :rememberable
end
test 'add all modules' do
assert_include_modules Devisable,
:authenticable, :confirmable, :recoverable, :rememberable, :validatable
:authenticatable, :confirmable, :recoverable, :rememberable, :validatable
end
test 'configure modules with except option' do
assert_include_modules Exceptable, :authenticable, :confirmable
assert_include_modules Exceptable, :authenticatable, :confirmable
assert_not_include_modules Exceptable, :recoverable, :rememberable, :validatable
end

View file

@ -57,13 +57,13 @@ class MapTest < ActiveSupport::TestCase
test 'magic predicates' do
mapping = Devise.mappings[:user]
assert mapping.authenticable?
assert mapping.authenticatable?
assert mapping.confirmable?
assert mapping.recoverable?
assert mapping.rememberable?
mapping = Devise.mappings[:admin]
assert mapping.authenticable?
assert mapping.authenticatable?
assert_not mapping.confirmable?
assert_not mapping.recoverable?
assert_not mapping.rememberable?

View file

@ -1,7 +1,7 @@
require 'test/test_helper'
require 'digest/sha1'
class AuthenticableTest < ActiveSupport::TestCase
class AuthenticatableTest < ActiveSupport::TestCase
def encrypt_password(user, pepper=nil, stretches=1)
user.class_eval { define_method(:stretches) { stretches } } if stretches

View file

@ -17,7 +17,7 @@ ActiveRecord::Base.establish_connection(:adapter => "sqlite3", :database => ":me
ActiveRecord::Schema.define(:version => 1) do
[:users, :admins].each do |table|
create_table table do |t|
t.authenticable :null => table == :admins
t.authenticatable :null => table == :admins
if table == :users
t.confirmable