1
0
Fork 0
mirror of https://github.com/heartcombo/devise.git synced 2022-11-09 12:18:31 -05:00

Email is always required in validatable.

This commit is contained in:
José Valim 2009-12-06 17:21:18 -02:00
parent 2d772733e7
commit 45a5d2b416
2 changed files with 5 additions and 7 deletions

View file

@ -63,7 +63,7 @@ module Devise
module ClassMethods
# Authenticate a user based on configured attribute keys. Returns the
# authenticated user if it's valid or nil. Attributes are by default
# :email and :password, the latter is always required.
# :email and :password, but the latter is always required.
def authenticate(attributes={})
return unless authentication_keys.all? { |k| attributes[k].present? }
conditions = attributes.slice(*authentication_keys)

View file

@ -18,12 +18,10 @@ module Devise
assert_validations_api!(base)
base.class_eval do
attribute = authentication_keys.first
validates_presence_of attribute
validates_uniqueness_of attribute, :allow_blank => true
validates_format_of attribute, :with => EMAIL_REGEX, :allow_blank => true,
:scope => authentication_keys[1..-1]
validates_presence_of :email
validates_uniqueness_of :email, :allow_blank => true
validates_format_of :email, :with => EMAIL_REGEX, :allow_blank => true,
:scope => authentication_keys[1..-1]
with_options :if => :password_required? do |v|
v.validates_presence_of :password