Sha256: 2ce62920163ec5a9291d673d94900b2978eccea90a1f1c8be1095b6cfaf2fa6a

Contents?: true

Size: 769 Bytes

Versions: 4

Compression:

Stored size: 769 Bytes

Contents

require 'devise/strategies/authenticatable'

module Devise
  module Strategies
    class SubdomainLogin < Authenticatable
    
      def subdomain
        request.subdomain
      end
      
      def valid?
        subdomain.present? && params["user"]
      end
      
      def authenticate!
        return fail!('Invalid email or password.') unless account = Mtdevise::Account.find_by(subdomain: subdomain)
        return fail!('Invalid email or password.') unless user = account.users.find_by(email: params["user"]["email"])
        return fail!('Invalid email or password.') unless user.valid_password?(params["user"]["password"])
        success! user
      end
    
    end
  end 
end

Warden::Strategies.add(:subdomain_login, Devise::Strategies::SubdomainLogin)

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
mtdevise-3.10.1 config/initializers/devise/strategies/subdomain.rb
mtdevise-3.10.0 config/initializers/devise/strategies/subdomain.rb
mtdevise-3.9.1 config/initializers/devise/strategies/subdomain.rb
mtdevise-3.9.0 config/initializers/devise/strategies/subdomain.rb