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

Merge branch 'master' of github.com:plataformatec/devise

This commit is contained in:
José Valim 2009-12-08 18:29:49 -02:00
commit 5735b21c77
12 changed files with 56 additions and 34 deletions

View file

@ -1,3 +1,12 @@
== 0.7.0
* deprecations
* :authenticatable is not included by default anymore
* enhancements
* Improve loading process
* Extract SessionSerializer from Authenticatable
== 0.6.3 == 0.6.3
* bug fix * bug fix
@ -19,7 +28,7 @@
== 0.6.0 == 0.6.0
* deprecations * deprecations
* :authenticatable is not included by default anymore * :authenticatable is still included by default, but yields a deprecation warning
* enhancements * enhancements
* Added DataMapper support * Added DataMapper support

View file

@ -223,9 +223,7 @@ Take a look at our locale file to check all available messages.
== Test helpers == Test helpers
Devise includes some tests helpers for functional specs. To use them, you just Devise includes some tests helpers for functional specs. To use them, you just need to include Devise::TestHelpers in your test class and use the sign_in and sign_out method. Such methods have the same signature as in controllers:
need to include Devise::TestHelpers in your test class and use the sign_in and
sign_out method. Such methods have the same signature as in controllers:
sign_in :user, @user # sign_in(scope, resource) sign_in :user, @user # sign_in(scope, resource)
sign_in @user # sign_in(resource) sign_in @user # sign_in(resource)
@ -233,13 +231,14 @@ sign_out method. Such methods have the same signature as in controllers:
sign_out :user # sign_out(scope) sign_out :user # sign_out(scope)
sign_out @user # sign_out(resource) sign_out @user # sign_out(resource)
You can include the Devise Test Helpers in all of your tests by adding the You can include the Devise Test Helpers in all of your tests by adding the following to the bottom of your test/test_helper.rb or spec/spec_helper.rb file:
following to the bottom of your test/test_helper.rb or spec/spec_helper.rb file:
class ActionController::TestCase class ActionController::TestCase
include Devise::TestHelpers include Devise::TestHelpers
end end
Do not use such helpers for integration tests like Cucumber, Webrat... Just fill in the form or explicitly set the user in session. For more tips, check the wiki (http://wiki.github.com/plataformatec/devise).
== Migrating from other solutions == Migrating from other solutions
Devise implements encryption strategies for Clearance, Authlogic and Restful-Authentication. To make use of it set the desired encryptor in the encryptor initializer config option. You might also need to rename your encrypted password and salt columns to match Devises's one (encrypted_password and password_salt). Devise implements encryption strategies for Clearance, Authlogic and Restful-Authentication. To make use of it set the desired encryptor in the encryptor initializer config option. You might also need to rename your encrypted password and salt columns to match Devises's one (encrypted_password and password_salt).

View file

@ -150,6 +150,5 @@ Warden::Manager.default_scope = nil
require 'devise/controllers' require 'devise/controllers'
require 'devise/encryptors' require 'devise/encryptors'
require 'devise/strategies/base' require 'devise/orm'
require 'devise/serializers/base'
require 'devise/rails' require 'devise/rails'

View file

@ -1,5 +1,14 @@
module Devise module Devise
module Models module Models
autoload :Authenticatable, 'devise/models/authenticatable'
autoload :Confirmable, 'devise/models/confirmable'
autoload :Recoverable, 'devise/models/recoverable'
autoload :Rememberable, 'devise/models/rememberable'
autoload :SessionSerializer, 'devise/models/authenticatable'
autoload :Timeoutable, 'devise/models/timeoutable'
autoload :Trackable, 'devise/models/trackable'
autoload :Validatable, 'devise/models/validatable'
# Creates configuration values for Devise and for the given module. # Creates configuration values for Devise and for the given module.
# #
# Devise::Models.config(Devise::Authenticable, :stretches, 10) # Devise::Models.config(Devise::Authenticable, :stretches, 10)
@ -69,19 +78,13 @@ module Devise
# devise :all, :except => :recoverable # devise :all, :except => :recoverable
# #
def devise(*modules) def devise(*modules)
# TODO Add this check in future versions raise "You need to give at least one Devise module" if modules.empty?
# raise "You need to give at least one Devise module" if modules.empty?
options = modules.extract_options! options = modules.extract_options!
modules = Devise.all if modules.include?(:all) modules = Devise.all if modules.include?(:all)
modules -= Array(options.delete(:except)) modules -= Array(options.delete(:except))
modules = Devise::ALL & modules modules = Devise::ALL & modules
if !modules.include?(:authenticatable)
modules = [:authenticatable] | modules
ActiveSupport::Deprecation.warn ":authenticatable won't be included by default in devise in future versions, please add it", caller[0,10]
end
Devise.orm_class.included_modules_hook(self, modules) do Devise.orm_class.included_modules_hook(self, modules) do
modules.each do |m| modules.each do |m|
devise_modules << m.to_sym devise_modules << m.to_sym

View file

@ -3,6 +3,19 @@ require 'devise/serializers/authenticatable'
module Devise module Devise
module Models module Models
module SessionSerializer
# Hook to serialize user into session. Overwrite if you want.
def serialize_into_session(record)
[record.class, record.id]
end
# Hook to serialize user from session. Overwrite if you want.
def serialize_from_session(keys)
klass, id = keys
raise "#{self} cannot serialize from #{klass} session since it's not its ancestors" unless klass <= self
klass.find(:first, :conditions => { :id => id })
end
end
# Authenticable Module, responsible for encrypting password and validating # Authenticable Module, responsible for encrypting password and validating
# authenticity of a user while signing in. # authenticity of a user while signing in.
@ -32,6 +45,7 @@ module Devise
def self.included(base) def self.included(base)
base.class_eval do base.class_eval do
extend ClassMethods extend ClassMethods
extend SessionSerializer
attr_reader :password attr_reader :password
attr_accessor :password_confirmation attr_accessor :password_confirmation
@ -71,18 +85,6 @@ module Devise
valid_for_authentication(resource, attributes) if resource valid_for_authentication(resource, attributes) if resource
end end
# Hook to serialize user into session. Overwrite if you want.
def serialize_into_session(record)
[record.class, record.id]
end
# Hook to serialize user from session. Overwrite if you want.
def serialize_from_session(keys)
klass, id = keys
raise "#{self} cannot serialize from #{klass} session since it's not its ancestors" unless klass <= self
klass.find(:first, :conditions => { :id => id })
end
# Returns the class for the configured encryptor. # Returns the class for the configured encryptor.
def encryptor_class def encryptor_class
@encryptor_class ||= ::Devise::Encryptors.const_get(encryptor.to_s.classify) @encryptor_class ||= ::Devise::Encryptors.const_get(encryptor.to_s.classify)

7
lib/devise/orm.rb Normal file
View file

@ -0,0 +1,7 @@
module Devise
module Orm
autoload :ActiveRecord, 'devise/orm/active_record'
autoload :DataMapper, 'devise/orm/data_mapper'
autoload :MongoMapper, 'devise/orm/mongo_mapper'
end
end

View file

@ -79,11 +79,6 @@ module ActionController::Routing
def devise_for(*resources) def devise_for(*resources)
options = resources.extract_options! options = resources.extract_options!
if singular = options.delete(:singular)
ActiveSupport::Deprecation.warn ":singular is deprecated in devise_for, use :scope instead."
options[:scope] = singular
end
resources.map!(&:to_sym) resources.map!(&:to_sym)
resources.each do |resource| resources.each do |resource|
mapping = Devise::Mapping.new(resource, options.dup) mapping = Devise::Mapping.new(resource, options.dup)

View file

@ -1,3 +1,5 @@
require 'devise/serializers/base'
module Devise module Devise
module Serializers module Serializers
class Authenticatable < Warden::Serializers::Session class Authenticatable < Warden::Serializers::Session

View file

@ -1,3 +1,5 @@
require 'devise/strategies/base'
module Devise module Devise
module Serializers module Serializers
module Base module Base

View file

@ -1,3 +1,5 @@
require 'devise/serializers/base'
module Devise module Devise
module Serializers module Serializers
class Rememberable < Warden::Serializers::Cookie class Rememberable < Warden::Serializers::Cookie

View file

@ -1,3 +1,5 @@
require 'devise/strategies/base'
module Devise module Devise
module Strategies module Strategies
# Default strategy for signing in a user, based on his email and password. # Default strategy for signing in a user, based on his email and password.

View file

@ -1,3 +1,3 @@
module Devise module Devise
VERSION = "0.6.3".freeze VERSION = "0.7.0".freeze
end end