2011-07-04 14 views
3

私は、クッキーなどの投票アプリケーションで匿名ユーザーを追跡する方法に関する一般的な記事を見てきました。しかし具体的には、restful_authenticationを修正してIP +ユーザエージェント(ハッシュ)を使って匿名ユーザを追跡する方法を教えてください。ありがとう。Railsでrestful_authenticationプラグインを使用して匿名ユーザーを追跡する最善の方法は何ですか?

答えて

0

lib/authenticated_system.rbに以下のようにメソッドlogin_from_anonymousが作成されました。このメソッドはcurrent_userメソッドとも呼ばれ、以下に示します。

def login_from_anonymous 
    user = User.new({"new_profile_attributes"=>         
         { "country_code"=>"", "zip"=>"", "first_name"=>"Anonymous", 
         "last_name"=>"User", "affiliation_id"=>"1" 
         }, 
        "password"    => "anonymous123", 
        "password_confirmation" => "anonymous123", 
        #"invitation_token"  => "", 
        "invitation_limit"  => 0,       
        "login"     => "anonymous_#{Time.now.strftime("%m-%d-%y+%I:%M:%S%p")}", 
        "email"     => "[email protected]", 
        "current_ip"    => request.env['REMOTE_ADDR']})  
    user.send(:create_without_callbacks) 
    self.current_user = user 
    handle_remember_cookie! true # freshen cookie token (keeping date) 
    self.current_user 
end 

def current_user  
    @current_user ||= (login_from_session || login_from_basic_auth || login_from_cookie || login_from_anonymous) unless @current_user == false 
end 
0

私は落ち着いた認証がそこに役立つとは思わない?私はあなたのために独自の方法を作成する必要があると思う。

なぜIPとUser-Agentを結合したいのですか? IPアドレスだけで十分ですか?

関連する問題