From 6c46c0985eeeec4e9dfd31fd27b4634594d5a425 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jos=C3=A9=20Valim?= Date: Sun, 15 Nov 2009 03:32:22 -0200 Subject: [PATCH] Make validations based on authentication keys. --- lib/devise/models/validatable.rb | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/lib/devise/models/validatable.rb b/lib/devise/models/validatable.rb index e18d2d9b..11b28176 100644 --- a/lib/devise/models/validatable.rb +++ b/lib/devise/models/validatable.rb @@ -12,14 +12,18 @@ module Devise def self.included(base) base.class_eval do + attribute = authentication_keys.first - validates_presence_of :email - validates_uniqueness_of :email, :allow_blank => true - validates_format_of :email, :with => EMAIL_REGEX, :allow_blank => true + 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 :password, :if => :password_required? - validates_confirmation_of :password, :if => :password_required? - validates_length_of :password, :within => 6..20, :allow_blank => true, :if => :password_required? + with_options :if => :password_required? do |v| + v.validates_presence_of :password + v.validates_confirmation_of :password + v.validates_length_of :password, :within => 6..20, :allow_blank => true + end end end