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
|
||||
|
||||
* enhancements
|
||||
|
|
|
@ -5,8 +5,8 @@ class SessionsController < ApplicationController
|
|||
|
||||
# GET /resource/sign_in
|
||||
def new
|
||||
Devise::FLASH_MESSAGES.each do |message, type|
|
||||
set_now_flash_message type, message if params.key?(message)
|
||||
Devise::FLASH_MESSAGES.each do |message|
|
||||
set_now_flash_message :failure, message if params.try(:[], message) == "true"
|
||||
end
|
||||
build_resource
|
||||
end
|
||||
|
|
|
@ -2,7 +2,7 @@ class DeviseInstallGenerator < Rails::Generator::Base
|
|||
|
||||
def manifest
|
||||
record do |m|
|
||||
m.file "devise.rb", "config/initializers/devise.rb"
|
||||
m.template "devise.rb", "config/initializers/devise.rb"
|
||||
end
|
||||
end
|
||||
|
||||
|
|
|
@ -1,6 +1,11 @@
|
|||
# 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.
|
||||
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
|
||||
# the encrypted password. By default no pepper is used.
|
||||
# config.pepper = "rake secret output"
|
||||
|
|
|
@ -12,12 +12,9 @@ module Devise
|
|||
SERIALIZERS = [:authenticatable, :rememberable].freeze
|
||||
TRUE_VALUES = [true, 1, '1', 't', 'T', 'true', 'TRUE'].freeze
|
||||
|
||||
# Maps the messages types that comes from warden to a flash type.
|
||||
# This hash is not frozen, so you can add your messages as well.
|
||||
FLASH_MESSAGES = {
|
||||
:unauthenticated => :success,
|
||||
:unconfirmed => :failure
|
||||
}
|
||||
# Maps the messages types that are used in flash message. This array is not
|
||||
# frozen, so you can add messages from your own strategies.
|
||||
FLASH_MESSAGES = [ :unauthenticated, :unconfirmed, :invalid ]
|
||||
|
||||
# Declare encryptors length which are used in migrations.
|
||||
ENCRYPTORS_LENGTH = {
|
||||
|
@ -67,6 +64,10 @@ module Devise
|
|||
mattr_accessor :orm
|
||||
@@orm = :active_record
|
||||
|
||||
# Configure default options used in :all
|
||||
mattr_accessor :all
|
||||
@@all = Devise::ALL.dup
|
||||
|
||||
class << self
|
||||
# Default way to setup Devise. Run script/generate devise_install to create
|
||||
# a fresh initializer with all configuration values.
|
||||
|
@ -74,11 +75,6 @@ module Devise
|
|||
yield self
|
||||
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.
|
||||
def mailer_sender=(value)
|
||||
DeviseMailer.sender = value
|
||||
|
@ -122,6 +118,11 @@ module Devise
|
|||
def orm_class
|
||||
Devise::Orm.const_get(@@orm.to_s.camelize.to_sym)
|
||||
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
|
||||
|
||||
|
|
|
@ -83,7 +83,7 @@ module Devise
|
|||
def devise(*modules)
|
||||
options = modules.extract_options!
|
||||
|
||||
modules = Devise::ALL if modules.include?(:all)
|
||||
modules = Devise.all if modules.include?(:all)
|
||||
modules -= Array(options.delete(:except))
|
||||
modules = [:authenticatable] | modules
|
||||
|
||||
|
|
|
@ -42,7 +42,7 @@ module Devise
|
|||
# setted.
|
||||
def password=(new_password)
|
||||
@password = new_password
|
||||
self.password_salt = friendly_token
|
||||
self.password_salt = Devise.friendly_token
|
||||
self.encrypted_password = password_digest(@password)
|
||||
end
|
||||
|
||||
|
@ -59,11 +59,6 @@ module Devise
|
|||
encryptor.digest(password, stretches, password_salt, pepper)
|
||||
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
|
||||
# Authenticate a user based on email and password. Returns the
|
||||
# authenticated user if it's valid or nil.
|
||||
|
|
|
@ -119,7 +119,7 @@ module Devise
|
|||
# this token is being generated
|
||||
def generate_confirmation_token
|
||||
self.confirmed_at = nil
|
||||
self.confirmation_token = friendly_token
|
||||
self.confirmation_token = Devise.friendly_token
|
||||
self.confirmation_sent_at = Time.now.utc
|
||||
end
|
||||
|
||||
|
|
|
@ -42,7 +42,7 @@ module Devise
|
|||
|
||||
# Generates a new random token for reset password
|
||||
def generate_reset_password_token
|
||||
self.reset_password_token = friendly_token
|
||||
self.reset_password_token = Devise.friendly_token
|
||||
end
|
||||
|
||||
# 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.
|
||||
def remember_me!
|
||||
self.remember_token = friendly_token
|
||||
self.remember_token = Devise.friendly_token
|
||||
self.remember_created_at = Time.now.utc
|
||||
save(false)
|
||||
end
|
||||
|
|
Loading…
Reference in New Issue