2013-02-12 24 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。

让我知道这是否有帮助

相关问题