2012-04-24 63 views
1

我對應用程序使用Basecamp風格的子域名。使用設計,我可以讓用戶通過使用User.rb以下僅訪問他們的子域名:設計,子域名和超級用戶

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

此檢查,以確保與用戶嘗試登錄相關帳戶的子域匹配。它工作正常。

我的問題是,我想允許超級用戶登錄太...誰不會有一個關聯的'帳戶'。他們反而會產生「超級用戶」布爾列在同一個‘用戶’模式。

有沒有一種方法來檢查正確的子域或‘超級用戶’狀態?

謝謝!

回答

0

如果你爲所有的超級用戶開立賬戶,我不知道這個被稱爲什麼階段的Auth過程,但也許是沿着這些線路的東西..?

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