Sha256: af4ab25cb238e3c17385bf66de96647c418ff4ae5177d74544432861c2b7a03e

Contents?: true

Size: 683 Bytes

Versions: 4

Compression:

Stored size: 683 Bytes

Contents

Warden::Strategies.add(:password) do
  def subdomain
    ActionDispatch::Http::URL.extract_subdomains(request.host, 1)
  end

  def json_params
    unless params.empty?
      params
    else
      @json ||= env['rack.input'].gets
      JSON.parse(@json)
    end
  end

  def valid?
    subdomain.present? && json_params["user"]
  end
  
  def authenticate!
    account = Cadenero::V1::Account.get_by_subdomain(subdomain)
    if account
      u = account.users.find_by_email(json_params["user"]["email"])
      if u.nil? || u.blank?
        fail!
      else
        u.authenticate(json_params["user"]["password"]) ? success!(u) : fail!
      end
    else
      fail!
    end
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
cadenero-0.0.2.b4 config/initializers/warden/strategies/password.rb
cadenero-0.0.2.b3 config/initializers/warden/strategies/password.rb
cadenero-0.0.2.b2 config/initializers/warden/strategies/password.rb
cadenero-0.0.2.b1 config/initializers/warden/strategies/password.rb