2013-02-17 79 views
0

我想知道是否有办法在设计登录时检查当前的URL。设计验证登录验证:在验证中包括当前的网址

假设我有一个带有field:url的用户模型,以及:email和:password,您还可以检查当前url是否与用户的url域匹配。

我想我应该在色器件的self.find_for_database_authentication方法做到这一点,我现在有这样的:

def self.find_for_database_authentication(warden_conditions) 
    conditions = warden_conditions.dup 
    if login = conditions.delete(:login).downcase 
     where(conditions).where('$or' => [{:username => /^#{Regexp.escape(login)}$/i}, {:email => /^#{Regexp.escape(login)}$/i}]).first 
    else 
     where(conditions).first 
    end 
    end 

,但我应该怎么添加到它,这样它会检查当前网址是什么?

注意:我正在使用mongoid

在此先感谢!

+0

只是好奇在这里:你为什么会想检查请求的网址?这不会使系统更安全。 – 2013-02-17 23:48:55

+0

我想模拟现有网站的登录系统:他们在注册时提供了一个URL登录名称,并使用该URL登录页面,然后使用您的电子邮件和密码通过表单登录。 – yretuta 2013-02-17 23:59:45

+0

如果你有另一种方法来检查我是否对其他解决方案非常开放:) – yretuta 2013-02-18 00:01:14

回答

0

您应该将网址直接添加到查询,像这样:

def self.find_for_database_authentication(warden_conditions) 
    conditions = warden_conditions.dup 
    login = conditions.delete(:login).downcase 
    url = conditions.delete(:url ).downcase 

    if login && url 
    where(conditions).where(
     :url => {"$eq" => url}, 
     '$or' => [ 
     {:username => /^#{Regexp.escape(login)}$/i}, 
     {:email => /^#{Regexp.escape(login)}$/i} 
     ] 
    ).first 
    else 
    where(conditions).first 
    end 
end 

其中散列是那种隐式“和”