1

アプリに Basecamp スタイルのサブドメインを使用しています。Devise を使用して、User.rb で以下を使用して、ユーザーが自分のサブドメインのみにアクセスできるようにしています。

  def self.find_for_authentication(conditions={})
    conditions[:account_id] = Account.find_by_subdomain(conditions.delete(:subdomain)).id
    super(conditions)
  end

これにより、ログインしようとしているユーザーに関連付けられているアカウントがサブドメインと一致することが確認されます。それは正常に動作します。

私の問題は、関連付けられた「アカウント」を持たないスーパーユーザーもログインできるようにしたいということです。代わりに、同じ「ユーザー」モデルに「スーパーユーザー」ブール列があります。

正しいサブドメインまたは「スーパーユーザー」ステータスを確認する方法はありますか?

ありがとう!

4

1 に答える 1

0

すべてのスーパーユーザーのアカウントを作成した場合はどうなりますか? これが呼び出される認証プロセスの段階はわかりませんが、おそらくこれらの線に沿った何か..?

def self.find_for_authentication(conditions={})
  if subdomain = conditions.delete(:subdomain)
    conditions[:account_id] = Account.find_by_subdomain(subdomain).id
  elsif User.where(conditions).where(:superuser => true).length > 0
    conditions[:account_id] = 1 # 1 is account reserved for super users
  end

  super(conditions)
en
于 2012-04-24T22:17:05.297 に答える