Created
September 1, 2013 16:45
-
-
Save AlexanderEkdahl/6405625 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
module Verifiable | |
extend ActiveSupport::Concern | |
def verification_key | |
ActiveSupport::MessageEncryptor | |
.new(Rails.application.config.secret_key_base) | |
.encrypt_and_sign("#{self.class} #{id}") | |
end | |
module ClassMethods | |
def find_by_verification_key(value) | |
class_name, id = ActiveSupport::MessageEncryptor | |
.new(Rails.application.config.secret_key_base) | |
.decrypt_and_verify(value).split | |
find(id) if class_name == self.name | |
rescue ActiveSupport::MessageVerifier::InvalidSignature | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment