Sha256: 88ef3a769d8b8c281976c06076d98d1242f2551906352c83640733a3593b8c8c
Contents?: true
Size: 981 Bytes
Versions: 17
Compression:
Stored size: 981 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: Mongoid::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 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
17 entries across 17 versions & 1 rubygems