mirror of
https://github.com/heartcombo/devise.git
synced 2022-11-09 12:18:31 -05:00
Refactoring.
This commit is contained in:
parent
debb0956a8
commit
bb336150fe
4 changed files with 10 additions and 10 deletions
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -91,7 +91,7 @@ class AuthenticableTest < ActiveSupport::TestCase
|
|||
end
|
||||
|
||||
test 'should encrypt password using a sha1 hash' do
|
||||
digest_key = Devise::Authenticable::SECURE_AUTH_SITE_KEY = 'digest_key'
|
||||
digest_key = Devise::Authenticable::SECURE_AUTH_SITE_KEY
|
||||
user = create_user
|
||||
expected_password = ::Digest::SHA1.hexdigest("--#{user.password_salt}--#{digest_key}--#{12345}--")
|
||||
assert_equal expected_password, user.encrypted_password
|
||||
|
@ -103,7 +103,7 @@ class AuthenticableTest < ActiveSupport::TestCase
|
|||
assert_not user.valid_password?('54321')
|
||||
end
|
||||
|
||||
test 'should authenticate a valid user and return it' do
|
||||
test 'should authenticate a valid user with email and password and return it' do
|
||||
user = create_user
|
||||
authenticated_user = User.authenticate('test@email.com', '12345')
|
||||
assert_equal authenticated_user, user
|
||||
|
|
|
@ -14,7 +14,7 @@ ActiveRecord::Schema.define(:version => 1) do
|
|||
t.string :email, :null => false
|
||||
t.string :encrypted_password, :null => false
|
||||
t.string :password_salt, :null => false
|
||||
t.string :confirmation_token
|
||||
t.string :confirmation_token, :null => false
|
||||
t.datetime :confirmed_at
|
||||
end
|
||||
end
|
||||
|
|
Loading…
Reference in a new issue