Added Devise.all to freeze your app strategies and moved friendly_token to Devise module.
This commit is contained in:
parent
209d598241
commit
680cb0f95f
|
@ -1,3 +1,7 @@
|
||||||
|
* enhancements
|
||||||
|
* [#35] Moved friendly_token to Devise
|
||||||
|
* Added Devise.all, so you can freeze your app strategies
|
||||||
|
|
||||||
== 0.5.2
|
== 0.5.2
|
||||||
|
|
||||||
* enhancements
|
* enhancements
|
||||||
|
|
|
@ -5,8 +5,8 @@ class SessionsController < ApplicationController
|
||||||
|
|
||||||
# GET /resource/sign_in
|
# GET /resource/sign_in
|
||||||
def new
|
def new
|
||||||
Devise::FLASH_MESSAGES.each do |message, type|
|
Devise::FLASH_MESSAGES.each do |message|
|
||||||
set_now_flash_message type, message if params.key?(message)
|
set_now_flash_message :failure, message if params.try(:[], message) == "true"
|
||||||
end
|
end
|
||||||
build_resource
|
build_resource
|
||||||
end
|
end
|
||||||
|
|
|
@ -2,7 +2,7 @@ class DeviseInstallGenerator < Rails::Generator::Base
|
||||||
|
|
||||||
def manifest
|
def manifest
|
||||||
record do |m|
|
record do |m|
|
||||||
m.file "devise.rb", "config/initializers/devise.rb"
|
m.template "devise.rb", "config/initializers/devise.rb"
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
@ -1,6 +1,11 @@
|
||||||
# Use this hook to configure devise mailer, warden hooks and so forth. The first
|
# Use this hook to configure devise mailer, warden hooks and so forth. The first
|
||||||
# four configuration values can also be set straight in your models.
|
# four configuration values can also be set straight in your models.
|
||||||
Devise.setup do |config|
|
Devise.setup do |config|
|
||||||
|
# Configure the frameworks used by default. You should always set this value
|
||||||
|
# because if Devise add a new strategy, it won't be added to your application
|
||||||
|
# by default, unless you configure it here.
|
||||||
|
config.all = <%= Devise::ALL.inspect %>
|
||||||
|
|
||||||
# Invoke `rake secret` and use the printed value to setup a pepper to generate
|
# Invoke `rake secret` and use the printed value to setup a pepper to generate
|
||||||
# the encrypted password. By default no pepper is used.
|
# the encrypted password. By default no pepper is used.
|
||||||
# config.pepper = "rake secret output"
|
# config.pepper = "rake secret output"
|
||||||
|
|
|
@ -12,12 +12,9 @@ module Devise
|
||||||
SERIALIZERS = [:authenticatable, :rememberable].freeze
|
SERIALIZERS = [:authenticatable, :rememberable].freeze
|
||||||
TRUE_VALUES = [true, 1, '1', 't', 'T', 'true', 'TRUE'].freeze
|
TRUE_VALUES = [true, 1, '1', 't', 'T', 'true', 'TRUE'].freeze
|
||||||
|
|
||||||
# Maps the messages types that comes from warden to a flash type.
|
# Maps the messages types that are used in flash message. This array is not
|
||||||
# This hash is not frozen, so you can add your messages as well.
|
# frozen, so you can add messages from your own strategies.
|
||||||
FLASH_MESSAGES = {
|
FLASH_MESSAGES = [ :unauthenticated, :unconfirmed, :invalid ]
|
||||||
:unauthenticated => :success,
|
|
||||||
:unconfirmed => :failure
|
|
||||||
}
|
|
||||||
|
|
||||||
# Declare encryptors length which are used in migrations.
|
# Declare encryptors length which are used in migrations.
|
||||||
ENCRYPTORS_LENGTH = {
|
ENCRYPTORS_LENGTH = {
|
||||||
|
@ -67,6 +64,10 @@ module Devise
|
||||||
mattr_accessor :orm
|
mattr_accessor :orm
|
||||||
@@orm = :active_record
|
@@orm = :active_record
|
||||||
|
|
||||||
|
# Configure default options used in :all
|
||||||
|
mattr_accessor :all
|
||||||
|
@@all = Devise::ALL.dup
|
||||||
|
|
||||||
class << self
|
class << self
|
||||||
# Default way to setup Devise. Run script/generate devise_install to create
|
# Default way to setup Devise. Run script/generate devise_install to create
|
||||||
# a fresh initializer with all configuration values.
|
# a fresh initializer with all configuration values.
|
||||||
|
@ -74,11 +75,6 @@ module Devise
|
||||||
yield self
|
yield self
|
||||||
end
|
end
|
||||||
|
|
||||||
def mail_sender=(value) #:nodoc:
|
|
||||||
ActiveSupport::Deprecation.warn "Devise.mail_sender= is deprecated, use Devise.mailer_sender instead"
|
|
||||||
DeviseMailer.sender = value
|
|
||||||
end
|
|
||||||
|
|
||||||
# Sets the sender in DeviseMailer.
|
# Sets the sender in DeviseMailer.
|
||||||
def mailer_sender=(value)
|
def mailer_sender=(value)
|
||||||
DeviseMailer.sender = value
|
DeviseMailer.sender = value
|
||||||
|
@ -122,6 +118,11 @@ module Devise
|
||||||
def orm_class
|
def orm_class
|
||||||
Devise::Orm.const_get(@@orm.to_s.camelize.to_sym)
|
Devise::Orm.const_get(@@orm.to_s.camelize.to_sym)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
# Generate a friendly string randomically to be used as token.
|
||||||
|
def friendly_token
|
||||||
|
ActiveSupport::SecureRandom.base64(15).tr('+/=', '-_ ').strip.delete("\n")
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
@ -83,7 +83,7 @@ module Devise
|
||||||
def devise(*modules)
|
def devise(*modules)
|
||||||
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 = [:authenticatable] | modules
|
modules = [:authenticatable] | modules
|
||||||
|
|
||||||
|
|
|
@ -42,7 +42,7 @@ module Devise
|
||||||
# setted.
|
# setted.
|
||||||
def password=(new_password)
|
def password=(new_password)
|
||||||
@password = new_password
|
@password = new_password
|
||||||
self.password_salt = friendly_token
|
self.password_salt = Devise.friendly_token
|
||||||
self.encrypted_password = password_digest(@password)
|
self.encrypted_password = password_digest(@password)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -53,16 +53,11 @@ module Devise
|
||||||
end
|
end
|
||||||
|
|
||||||
protected
|
protected
|
||||||
|
|
||||||
# Digests the password using the configured encryptor
|
# Digests the password using the configured encryptor
|
||||||
def password_digest(password)
|
def password_digest(password)
|
||||||
encryptor.digest(password, stretches, password_salt, pepper)
|
encryptor.digest(password, stretches, password_salt, pepper)
|
||||||
end
|
end
|
||||||
|
|
||||||
# Generate a friendly string randomically to be used as token.
|
|
||||||
def friendly_token
|
|
||||||
ActiveSupport::SecureRandom.base64(15).tr('+/=', '-_ ').strip.delete("\n")
|
|
||||||
end
|
|
||||||
|
|
||||||
module ClassMethods
|
module ClassMethods
|
||||||
# Authenticate a user based on email and password. Returns the
|
# Authenticate a user based on email and password. Returns the
|
||||||
|
|
|
@ -119,7 +119,7 @@ module Devise
|
||||||
# this token is being generated
|
# this token is being generated
|
||||||
def generate_confirmation_token
|
def generate_confirmation_token
|
||||||
self.confirmed_at = nil
|
self.confirmed_at = nil
|
||||||
self.confirmation_token = friendly_token
|
self.confirmation_token = Devise.friendly_token
|
||||||
self.confirmation_sent_at = Time.now.utc
|
self.confirmation_sent_at = Time.now.utc
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
@ -42,7 +42,7 @@ module Devise
|
||||||
|
|
||||||
# Generates a new random token for reset password
|
# Generates a new random token for reset password
|
||||||
def generate_reset_password_token
|
def generate_reset_password_token
|
||||||
self.reset_password_token = friendly_token
|
self.reset_password_token = Devise.friendly_token
|
||||||
end
|
end
|
||||||
|
|
||||||
# Resets the reset password token with and save the record without
|
# Resets the reset password token with and save the record without
|
||||||
|
|
|
@ -43,7 +43,7 @@ module Devise
|
||||||
|
|
||||||
# Generate a new remember token and save the record without validations.
|
# Generate a new remember token and save the record without validations.
|
||||||
def remember_me!
|
def remember_me!
|
||||||
self.remember_token = friendly_token
|
self.remember_token = Devise.friendly_token
|
||||||
self.remember_created_at = Time.now.utc
|
self.remember_created_at = Time.now.utc
|
||||||
save(false)
|
save(false)
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in New Issue