Refactoring.

This commit is contained in:
Carlos A. da Silva
2009-09-17 11:27:45 -03:00
parent debb0956a8
commit bb336150fe
4 changed files with 10 additions and 10 deletions

View File

@@ -74,8 +74,8 @@ module Devise
# authenticated user if it's valid or nil
#
def authenticate(email, password)
user = self.find_by_email(email)
user if user.valid_password?(password) unless user.nil?
authenticable = self.find_by_email(email)
authenticable if authenticable.valid_password?(password) unless authenticable.nil?
end
end
end

View File

@@ -41,13 +41,13 @@ module Devise
# If no user is found, returns a new user
# If the user is already confirmed, create an error for the user
def find_and_confirm(confirmation_token)
user = find_or_initialize_by_confirmation_token(confirmation_token)
unless user.new_record?
user.confirm!
confirmable = find_or_initialize_by_confirmation_token(confirmation_token)
unless confirmable.new_record?
confirmable.confirm!
else
user.errors.add(:confirmation_token, :invalid, :default => "invalid confirmation")
confirmable.errors.add(:confirmation_token, :invalid, :default => "invalid confirmation")
end
user
confirmable
end
end
end