Skip to content

Commit

Permalink
Adding symbols only on validate
Browse files Browse the repository at this point in the history
  • Loading branch information
Rodrigo Flores committed Mar 13, 2012
1 parent 68de34c commit 033e91b
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 7 deletions.
6 changes: 5 additions & 1 deletion lib/devise/models/authenticatable.rb
Expand Up @@ -78,6 +78,10 @@ def valid_for_authentication?
block_given? ? yield : true
end

def unauthenticated_message
:invalid
end

def active_for_authentication?
true
end
Expand Down Expand Up @@ -214,4 +218,4 @@ def generate_token(column)
end
end
end
end
end
9 changes: 8 additions & 1 deletion lib/devise/models/lockable.rb
Expand Up @@ -92,14 +92,21 @@ def valid_for_authentication?
self.failed_attempts += 1
if attempts_exceeded?
lock_access! unless access_locked?
return :locked
else
save(:validate => false)
end
false
end
end

def unauthenticated_message
if self.respond_to?(:failed_attempts) && attempts_exceeded?
:locked
else
super
end
end

protected

def attempts_exceeded?
Expand Down
3 changes: 2 additions & 1 deletion lib/devise/models/token_authenticatable.rb
Expand Up @@ -56,6 +56,7 @@ def ensure_authentication_token!
def after_token_authentication
end


module ClassMethods
def find_for_token_authentication(conditions)
find_for_authentication(:authentication_token => conditions[token_authentication_key])
Expand All @@ -70,4 +71,4 @@ def authentication_token
end
end
end
end
end
14 changes: 10 additions & 4 deletions lib/devise/strategies/authenticatable.rb
Expand Up @@ -23,14 +23,20 @@ def validate(resource, &block)
result = resource && resource.valid_for_authentication?(&block)

case result
when String, Symbol
when Symbol, String
ActiveSupport::Deprecation.warn "valid_for_authentication should return a boolean value"
fail!(result)
false
when TrueClass
return false
end

if result
decorate(resource)
true
else
result
if resource
fail!(resource.unauthenticated_message)
end
false
end
end

Expand Down

0 comments on commit 033e91b

Please sign in to comment.