Skip to content

Commit

Permalink
added callback for creating old_passwords at create
Browse files Browse the repository at this point in the history
  • Loading branch information
fidel committed Oct 15, 2011
1 parent a635291 commit 8c05b3d
Showing 1 changed file with 9 additions and 0 deletions.
9 changes: 9 additions & 0 deletions lib/devise_security_extension/models/password_archivable.rb
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ def self.included(base) # :nodoc:
include InstanceMethods include InstanceMethods
has_many :old_passwords, :as => :password_archivable, :dependent => :destroy has_many :old_passwords, :as => :password_archivable, :dependent => :destroy
before_update :archive_password before_update :archive_password
after_create :set_first_old_password
validate :validate_password_archive validate :validate_password_archive
end end
end end
Expand Down Expand Up @@ -62,6 +63,14 @@ def archive_password
end end
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: module ClassMethods #:nodoc:
::Devise::Models.config(self, :password_archiving_count, :deny_old_passwords) ::Devise::Models.config(self, :password_archiving_count, :deny_old_passwords)
end end
Expand Down

0 comments on commit 8c05b3d

Please sign in to comment.