Permalink
Browse files

added callback for creating old_passwords at create

  • Loading branch information...
1 parent a635291 commit 8c05b3d807f8c7f34978d760aca6f7ea9c848da1 @fidel committed Oct 15, 2011
Showing with 9 additions and 0 deletions.
  1. +9 −0 lib/devise_security_extension/models/password_archivable.rb
@@ -11,6 +11,7 @@ def self.included(base) # :nodoc:
include InstanceMethods
has_many :old_passwords, :as => :password_archivable, :dependent => :destroy
before_update :archive_password
+ after_create :set_first_old_password
validate :validate_password_archive
end
end
@@ -62,6 +63,14 @@ def archive_password
end
end
+ def set_first_old_password
+ if self.respond_to?(:password_salt) and !self.password_salt.nil?
+ self.old_passwords.create! :encrypted_password => self.encrypted_password, :password_salt => self.password_salt
+ else
+ self.old_passwords.create! :encrypted_password => self.encrypted_password
+ end
+ end
+
module ClassMethods #:nodoc:
::Devise::Models.config(self, :password_archiving_count, :deny_old_passwords)
end

0 comments on commit 8c05b3d

Please sign in to comment.