More configuration to validatable.
This commit is contained in:
parent
ea71be8d2a
commit
4b7a9204b8
|
@ -11,17 +11,18 @@ module Devise
|
|||
:validates_confirmation_of, :validates_length_of ].freeze
|
||||
|
||||
def self.included(base)
|
||||
base.extend ClassMethods
|
||||
assert_validations_api!(base)
|
||||
|
||||
base.class_eval do
|
||||
validates_presence_of :email
|
||||
validates_uniqueness_of :email, :scope => authentication_keys[1..-1], :allow_blank => true
|
||||
validates_format_of :email, :with => Devise.email_regexp, :allow_blank => true
|
||||
validates_format_of :email, :with => email_regexp, :allow_blank => true
|
||||
|
||||
with_options :if => :password_required? do |v|
|
||||
v.validates_presence_of :password
|
||||
v.validates_confirmation_of :password
|
||||
v.validates_length_of :password, :within => Devise.password_length, :allow_blank => true
|
||||
v.validates_length_of :password, :within => password_length, :allow_blank => true
|
||||
end
|
||||
end
|
||||
end
|
||||
|
@ -35,14 +36,18 @@ module Devise
|
|||
end
|
||||
end
|
||||
|
||||
protected
|
||||
protected
|
||||
|
||||
# Checks whether a password is needed or not. For validations only.
|
||||
# Passwords are always required if it's a new record, or if the password
|
||||
# or confirmation are being set somewhere.
|
||||
def password_required?
|
||||
new_record? || !password.nil? || !password_confirmation.nil?
|
||||
end
|
||||
# Checks whether a password is needed or not. For validations only.
|
||||
# Passwords are always required if it's a new record, or if the password
|
||||
# or confirmation are being set somewhere.
|
||||
def password_required?
|
||||
new_record? || !password.nil? || !password_confirmation.nil?
|
||||
end
|
||||
|
||||
module ClassMethods
|
||||
Devise::Models.config(self, :email_regexp, :password_length)
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
Loading…
Reference in New Issue