aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord/lib/active_record/secure_token.rb
diff options
context:
space:
mode:
authorWojciech Wnętrzak <w.wnetrzak@gmail.com>2015-02-12 22:05:43 +0100
committerWojciech Wnętrzak <w.wnetrzak@gmail.com>2015-02-12 22:05:45 +0100
commit0817bb06f72bac456a7225645caf18ae9dc8c040 (patch)
treed5582f834b4f74aa99aa2d66e1657458545eff1d /activerecord/lib/active_record/secure_token.rb
parentb03b09dc8660e26ed23a851ebda2bcbcb47d7d0a (diff)
downloadrails-0817bb06f72bac456a7225645caf18ae9dc8c040.tar.gz
rails-0817bb06f72bac456a7225645caf18ae9dc8c040.tar.bz2
rails-0817bb06f72bac456a7225645caf18ae9dc8c040.zip
Do not overwrite secret token value when already present.
``` user = User.create(token: "custom-secure-token") user.token # => "custom-secure-token" ```
Diffstat (limited to 'activerecord/lib/active_record/secure_token.rb')
-rw-r--r--activerecord/lib/active_record/secure_token.rb3
1 files changed, 1 insertions, 2 deletions
diff --git a/activerecord/lib/active_record/secure_token.rb b/activerecord/lib/active_record/secure_token.rb
index 07031b6371..0990f815a7 100644
--- a/activerecord/lib/active_record/secure_token.rb
+++ b/activerecord/lib/active_record/secure_token.rb
@@ -27,7 +27,7 @@ module ActiveRecord
# Load securerandom only when has_secure_token is used.
require 'active_support/core_ext/securerandom'
define_method("regenerate_#{attribute}") { update! attribute => self.class.generate_unique_secure_token }
- before_create { self.send("#{attribute}=", self.class.generate_unique_secure_token) }
+ before_create { self.send("#{attribute}=", self.class.generate_unique_secure_token) unless self.send("#{attribute}?")}
end
def generate_unique_secure_token
@@ -36,4 +36,3 @@ module ActiveRecord
end
end
end
-