Sha256: a5a2a1bc8e671e3dd8937e12314526ae52db6151b7f59e01048a10e15083ef9a

Contents?: true

Size: 746 Bytes

Versions: 10

Compression:

Stored size: 746 Bytes

Contents

require 'active_model'
require 'active_support'

# :nodoc: namespace
module Authpwn

# :nodoc: namespace
module UserExtensions

# Augments the User model with a password virtual attribute.
module ApiTokenField
  extend ActiveSupport::Concern

  # Credentials::Password instance associated with this user.
  def api_token_credential
    credentials.find { |c| c.instance_of?(Tokens::Api) }
  end

  # The code from the user's API token credential.
  #
  # Creates an API token if the user doesn't already have one.
  def api_token
    credential = self.api_token_credential || Tokens::Api.random_for(self)
    credential.code
  end
end  # module Authpwn::UserExtensions::ApiTokenField

end  # module Authpwn::UserExtensions

end  # module Authpwn

Version data entries

10 entries across 10 versions & 1 rubygems

Version Path
authpwn_rails-0.23.0 lib/authpwn_rails/user_extensions/api_token_field.rb
authpwn_rails-0.22.1 lib/authpwn_rails/user_extensions/api_token_field.rb
authpwn_rails-0.22.0 lib/authpwn_rails/user_extensions/api_token_field.rb
authpwn_rails-0.21.1 lib/authpwn_rails/user_extensions/api_token_field.rb
authpwn_rails-0.21.0 lib/authpwn_rails/user_extensions/api_token_field.rb
authpwn_rails-0.20.0 lib/authpwn_rails/user_extensions/api_token_field.rb
authpwn_rails-0.19.0 lib/authpwn_rails/user_extensions/api_token_field.rb
authpwn_rails-0.18.2 lib/authpwn_rails/user_extensions/api_token_field.rb
authpwn_rails-0.18.1 lib/authpwn_rails/user_extensions/api_token_field.rb
authpwn_rails-0.18.0 lib/authpwn_rails/user_extensions/api_token_field.rb