Permalink
Browse files

Added Devise.all to freeze your app strategies and moved friendly_tok…

…en to Devise module.
  • Loading branch information...
1 parent 209d598 commit 680cb0f95f85bc48164d5a592e8313ede892b37c @josevalim josevalim committed Nov 18, 2009
View
@@ -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"
View
@@ -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,18 +64,17 @@ def self.encryptor=(value)
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.
def setup
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 @@ def configure_warden_manager(manager) #:nodoc:
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
View
@@ -83,7 +83,7 @@ def #{accessor}=(value)
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 @@ def self.included(base)
# 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
@@ -53,16 +53,11 @@ def valid_password?(incoming_password)
end
protected
-
+
# Digests the password using the configured encryptor
def password_digest(password)
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
@@ -119,7 +119,7 @@ def unless_confirmed
# 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 @@ def send_reset_password_instructions
# 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 @@ def self.included(base)
# 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

0 comments on commit 680cb0f

Please sign in to comment.