Sha256: 166d8d77e62433b36c2c2cf2b9e8e3229fbd88ac6797a2ffe5d918de9fcf95bc
Contents?: true
Size: 977 Bytes
Versions: 10
Compression:
Stored size: 977 Bytes
Contents
# frozen_string_literal: true # # API tokenable, support for the api token in user, but also may be applied elsewhere # module ApiTokenable extend ActiveSupport::Concern def self.included(base) base.class_eval do # store api token field :api_token, type: String # if the api token should be reset field :reset_api_token, type: Boolean, default: true field :last_authenticated_at, type: Time field :last_authenticated_ip, type: String # call back to reset the api token. before_save :assign_api_token, if: :reset_api_token # set the index on api token index({ api_token: 1 }, background: true) def cycle_api_token self.set api_token: SecureRandom.urlsafe_base64 api_token end private # # set the api token # def assign_api_token self.reset_api_token = false self.api_token = SecureRandom.urlsafe_base64 end end end end
Version data entries
10 entries across 10 versions & 1 rubygems