module Rodauth::Rails

Constants

Feature

Assign feature and feature configuration to constants for introspection.

FeatureConfiguration
LOCK
VERSION

Attributes

app[W]
middleware[W]

Public Class Methods

api_only?() click to toggle source
# File lib/rodauth/rails.rb, line 75
def api_only?
  ::Rails.application.config.api_only
end
app() click to toggle source
# File lib/rodauth/rails.rb, line 91
def app
  fail Rodauth::Rails::Error, "app was not configured" unless @app

  @app.constantize
end
authenticated(name = nil, &condition) click to toggle source

routing constraint that requires authentication

# File lib/rodauth/rails.rb, line 56
def authenticated(name = nil, &condition)
  lambda do |request|
    rodauth = request.env.fetch ["rodauth", *name].join(".")
    rodauth.require_authentication
    rodauth.authenticated? && (condition.nil? || condition.call(rodauth))
  end
end
configure() { |self| ... } click to toggle source
# File lib/rodauth/rails.rb, line 84
def configure
  yield self
end
middleware?() click to toggle source
# File lib/rodauth/rails.rb, line 97
def middleware?
  @middleware
end
model(name = nil, **options) click to toggle source
# File lib/rodauth/rails.rb, line 51
def model(name = nil, **options)
  Rodauth::Rails::Model.new(app.rodauth(name), **options)
end
rodauth(name = nil, query: nil, form: nil, account: nil, **options) click to toggle source
# File lib/rodauth/rails.rb, line 20
def rodauth(name = nil, query: nil, form: nil, account: nil, **options)
  auth_class = app.rodauth(name)

  unless auth_class
    fail ArgumentError, "undefined rodauth configuration: #{name.inspect}"
  end

  LOCK.synchronize do
    unless auth_class.features.include?(:internal_request)
      auth_class.configure { enable :internal_request }
      warn "Rodauth::Rails.rodauth requires the internal_request feature to be enabled. For now it was enabled automatically, but this behaviour will be removed in version 1.0."
    end
  end

  if query || form
    warn "The :query and :form keyword arguments for Rodauth::Rails.rodauth have been deprecated. Please use the :params argument supported by internal_request feature instead."
    options[:params] = query || form
  end

  if account
    options[:account_id] = account.id
  end

  instance = auth_class.internal_request_eval(options) do
    @account = account.attributes.symbolize_keys if account
    self
  end

  instance
end
secret_key_base() click to toggle source
# File lib/rodauth/rails.rb, line 65
def secret_key_base
  ::Rails.application.secret_key_base
end