mirror of
https://github.com/heartcombo/devise.git
synced 2022-11-09 12:18:31 -05:00
More configuration to validatable.
This commit is contained in:
parent
ea71be8d2a
commit
4b7a9204b8
1 changed files with 14 additions and 9 deletions
|
@ -11,17 +11,18 @@ module Devise
|
||||||
:validates_confirmation_of, :validates_length_of ].freeze
|
:validates_confirmation_of, :validates_length_of ].freeze
|
||||||
|
|
||||||
def self.included(base)
|
def self.included(base)
|
||||||
|
base.extend ClassMethods
|
||||||
assert_validations_api!(base)
|
assert_validations_api!(base)
|
||||||
|
|
||||||
base.class_eval do
|
base.class_eval do
|
||||||
validates_presence_of :email
|
validates_presence_of :email
|
||||||
validates_uniqueness_of :email, :scope => authentication_keys[1..-1], :allow_blank => true
|
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|
|
with_options :if => :password_required? do |v|
|
||||||
v.validates_presence_of :password
|
v.validates_presence_of :password
|
||||||
v.validates_confirmation_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
|
end
|
||||||
end
|
end
|
||||||
|
@ -35,14 +36,18 @@ module Devise
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
protected
|
protected
|
||||||
|
|
||||||
# Checks whether a password is needed or not. For validations only.
|
# 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
|
# Passwords are always required if it's a new record, or if the password
|
||||||
# or confirmation are being set somewhere.
|
# or confirmation are being set somewhere.
|
||||||
def password_required?
|
def password_required?
|
||||||
new_record? || !password.nil? || !password_confirmation.nil?
|
new_record? || !password.nil? || !password_confirmation.nil?
|
||||||
end
|
end
|
||||||
|
|
||||||
|
module ClassMethods
|
||||||
|
Devise::Models.config(self, :email_regexp, :password_length)
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in a new issue