2013-02-12 25 views
0

我使用PostgreSQL 設計商店的電子郵件中分貝downcase: config.case_insensitive_keys = [:郵箱]設計不區分大小寫電子郵件時登錄

但是,當我用大寫的電子郵件密碼 - 我有錯誤的電子郵件是錯誤。 我找到這個孤子,但有1個麻煩:

def self.find_for_authentication(conditions = {}) 
    # Allow to log in with case insensitive email 
    conditions[:email].downcase! 
end 

1)當我試圖用錯誤的大寫的電子郵件記錄在我的錯誤我與downcase電子郵件。 (以[email protected]登錄,得到[email protected],但我需要顯示[email protected])。我怎樣才能改變這種行爲?

回答

0

解決方案非常簡單。你需要的僅僅是複製params散列並且在登錄時改變這個散列中的電子郵件,但是當用戶得到異常時 - 我們只是用輸入的參數返回原始散列

def self.find_for_authentication(conditions = {}) 
    # Allow to log in with case insensitive email 
    new_hash = conditions.dup 
    new_hash[:email] = conditions[:email].downcase 
    where(new_hash).first 
end 
0

我不知道我得到你,但你應該能夠訪問你的

條件提供 原始電子郵件[:郵箱]

或者登錄後,你可以訪問登錄的電子郵件在用戶通過 self.email。

讓我知道這是否有幫助

相關問題