Sha256: 6cf0592f87f083a34cfe6dd453d0cd6fcb107afd4dae1813a52325f751e1ef2c

Contents?: true

Size: 1.26 KB

Versions: 9

Compression:

Stored size: 1.26 KB

Contents

module SimpleAuth
  # Add a shortcut to Authorization::Config
  def self.setup(&block)
    yield SimpleAuth::Config if block_given?
  end

  class Config
    # Generate the password hash. The specified block should expected
    # the plain password and the password hash as block parameters.
    cattr_accessor :crypter
    @@crypter = proc do |password, salt|
      Digest::SHA256.hexdigest [password, salt].join("--")
    end

    # Generate the password salt. The specified block should expect
    # the ActiveRecord instance as block parameter.
    cattr_accessor :salt
    @@salt = proc do |record|
      Digest::SHA256.hexdigest [Time.to_s, ActiveSupport::SecureRandom.hex(32)].join("--")
    end

    # Set which attributes will be used for authentication.
    cattr_accessor :credentials
    @@credentials = [:email, :login]

    # Set the user model
    cattr_accessor :model
    @@model = :user

    # Set the current controller object
    cattr_accessor :controller
    @@controller = nil

    # Set the login url
    cattr_accessor :redirect_to
    @@redirect_to = proc { login_path }

    # Reset session before saving the user session
    cattr_accessor :reset_session
    @@reset_session = false

    def self.model_class
      model.to_s.classify.constantize
    end
  end
end

Version data entries

9 entries across 9 versions & 1 rubygems

Version Path
simple_auth-0.1.8 lib/simple_auth/config.rb
simple_auth-0.1.7 lib/simple_auth/config.rb
simple_auth-0.1.6 lib/simple_auth/config.rb
simple_auth-0.1.5 lib/simple_auth/config.rb
simple_auth-0.1.4 lib/simple_auth/config.rb
simple_auth-0.1.3 lib/simple_auth/config.rb
simple_auth-0.1.2 lib/simple_auth/config.rb
simple_auth-0.1.1 lib/simple_auth/config.rb
simple_auth-0.1.0 lib/simple_auth/config.rb