Всем привет ! Возникла следующая проблема : есть контроллер отвечающий за авторизацию и создание сессии Код | class SessionsController < ApplicationController
protect_from_forgery :except => [] skip_before_filter :require_login, :only => [:new, :create]
def new end
def create logout_keeping_session! user = User.authenticate(params[:login], params[:password]) if user self.current_user = user new_cookie_flag = (params[:remember_me] == "1") handle_remember_cookie! new_cookie_flag redirect_back_or_default('/home') flash[:notice] = "Logged in successfully" else note_failed_signin @login = params[:login] @remember_me = params[:remember_me] render :action => 'new' end end
|
Принимает он очевидных два параметра - логин и пароль !!! Пробую зайти клиентом : Код | #!/usr/bin/ruby
require 'rubygems' require 'httpclient' require 'builder' require 'active_support'
def smp_request(http_method, url, options = {}) return nil if url.nil? || url.size == 0 p options if options.size > 0
clnt = HTTPClient.new http_method = "get" unless ["get", "post"].include?(http_method) puts "url is:#{url}" begin case http_method when "get" puts "Request get ..." request = clnt.get(url, options) puts "Request get ... executed" request.body when "post" puts "Request post ..." request = clnt.post(url, options) puts "Request post ... executed" request.body end rescue puts "There is error" return nil else puts "Request status = #{request.status}" return request end end
method = "post" host = "http://localhost:3000/sessions/create" data = { :login => "login", :password => "password" }
resp = smp_request(method, host, data)
|
В ответ сервер отвечает 442 статусом и выдает такой мусор в resp.body Код | {:password=>"password", :login=>"login"} url is:http://localhost:3000/sessions/create Request post ... Request post ... executed Request status = 422 <html xmlns="http://www.w3.org/1999/xhtml"> <head> <title>Action Controller: Exception caught</title> <style> body { background-color: #fff; color: #333; }
body, p, ol, ul, td { font-family: verdana, arial, helvetica, sans-serif; font-size: 13px; line-height: 18px; }
pre { background-color: #eee; padding: 10px; font-size: 11px; }
a { color: #000; } a:visited { color: #666; } a:hover { color: #fff; background-color:#000; } </style> </head> <body>
<h1> ActionController::InvalidAuthenticityToken in SessionsController#create </h1> <pre>ActionController::InvalidAuthenticityToken</pre>
<p><code>RAILS_ROOT: /home/gafas/ruby-prj/demo</code></p>
<div id="traces"> <a href="#" onclick="document.getElementById('Framework-Trace').style.display='none';document.getElementById('Full-Trace').style.display='none';document.getElementById('Application-Trace').style.display='block';; return false;">Application Trace</a> | <a href="#" onclick="document.getElementById('Application-Trace').style.display='none';document.getElementById('Full-Trace').style.display='none';document.getElementById('Framework-Trace').style.display='block';; return false;">Framework Trace</a> | <a href="#" onclick="document.getElementById('Application-Trace').style.display='none';document.getElementById('Framework-Trace').style.display='none';document.getElementById('Full-Trace').style.display='block';; return false;">Full Trace</a>
<div id="Application-Trace" style="display: block;"> <pre><code>/usr/lib/ruby/1.8/action_controller/request_forgery_protection.rb:79:in `verify_authenticity_token' /usr/lib/ruby/1.8/active_support/callbacks.rb:178:in `send' /usr/lib/ruby/1.8/active_support/callbacks.rb:178:in `evaluate_method' /usr/lib/ruby/1.8/active_support/callbacks.rb:166:in `call' /usr/lib/ruby/1.8/action_controller/filters.rb:225:in `call' /usr/lib/ruby/1.8/action_controller/filters.rb:629:in `run_before_filters' /usr/lib/ruby/1.8/action_controller/filters.rb:615:in `call_filters' /usr/lib/ruby/1.8/action_controller/filters.rb:610:in `perform_action_without_benchmark' /usr/lib/ruby/1.8/action_controller/benchmarking.rb:68:in `perform_action_without_rescue' /usr/lib/ruby/1.8/active_support/core_ext/benchmark.rb:17:in `ms' /usr/lib/ruby/1.8/benchmark.rb:308:in `realtime' /usr/lib/ruby/1.8/active_support/core_ext/benchmark.rb:17:in `ms' /usr/lib/ruby/1.8/action_controller/benchmarking.rb:68:in `perform_action_without_rescue' /usr/lib/ruby/1.8/action_controller/rescue.rb:160:in `perform_action_without_flash' /usr/lib/ruby/1.8/action_controller/flash.rb:146:in `perform_action' /usr/lib/ruby/1.8/action_controller/base.rb:532:in `send' /usr/lib/ruby/1.8/action_controller/base.rb:532:in `process_without_filters' /usr/lib/ruby/1.8/action_controller/filters.rb:606:in `process' /usr/lib/ruby/1.8/action_controller/base.rb:391:in `process' /usr/lib/ruby/1.8/action_controller/base.rb:386:in `call' /usr/lib/ruby/1.8/action_controller/routing/route_set.rb:437:in `call'</code></pre> </div> <div id="Framework-Trace" style="display: none;"> <pre><code>/usr/lib/ruby/1.8/action_controller/request_forgery_protection.rb:79:in `verify_authenticity_token' /usr/lib/ruby/1.8/active_support/callbacks.rb:178:in `send' /usr/lib/ruby/1.8/active_support/callbacks.rb:178:in `evaluate_method' /usr/lib/ruby/1.8/active_support/callbacks.rb:166:in `call' /usr/lib/ruby/1.8/action_controller/filters.rb:225:in `call' /usr/lib/ruby/1.8/action_controller/filters.rb:629:in `run_before_filters' /usr/lib/ruby/1.8/action_controller/filters.rb:615:in `call_filters' /usr/lib/ruby/1.8/action_controller/filters.rb:610:in `perform_action_without_benchmark' /usr/lib/ruby/1.8/action_controller/benchmarking.rb:68:in `perform_action_without_rescue' /usr/lib/ruby/1.8/active_support/core_ext/benchmark.rb:17:in `ms' /usr/lib/ruby/1.8/benchmark.rb:308:in `realtime' /usr/lib/ruby/1.8/active_support/core_ext/benchmark.rb:17:in `ms' /usr/lib/ruby/1.8/action_controller/benchmarking.rb:68:in `perform_action_without_rescue' /usr/lib/ruby/1.8/action_controller/rescue.rb:160:in `perform_action_without_flash' /usr/lib/ruby/1.8/action_controller/flash.rb:146:in `perform_action' /usr/lib/ruby/1.8/action_controller/base.rb:532:in `send' /usr/lib/ruby/1.8/action_controller/base.rb:532:in `process_without_filters' /usr/lib/ruby/1.8/action_controller/filters.rb:606:in `process' /usr/lib/ruby/1.8/action_controller/base.rb:391:in `process' /usr/lib/ruby/1.8/action_controller/base.rb:386:in `call' /usr/lib/ruby/1.8/action_controller/routing/route_set.rb:437:in `call' /usr/lib/ruby/1.8/action_controller/dispatcher.rb:87:in `dispatch' /usr/lib/ruby/1.8/action_controller/dispatcher.rb:121:in `_call' /usr/lib/ruby/1.8/action_controller/dispatcher.rb:130:in `build_middleware_stack' /usr/lib/ruby/1.8/active_record/query_cache.rb:29:in `call' /usr/lib/ruby/1.8/active_record/query_cache.rb:29:in `call' /usr/lib/ruby/1.8/active_record/connection_adapters/abstract/query_cache.rb:34:in `cache' /usr/lib/ruby/1.8/active_record/query_cache.rb:9:in `cache' /usr/lib/ruby/1.8/active_record/query_cache.rb:28:in `call' /usr/lib/ruby/1.8/active_record/connection_adapters/abstract/connection_pool.rb:361:in `call' /usr/lib/ruby/1.8/action_controller/string_coercion.rb:25:in `call' /usr/lib/ruby/1.8/rack/head.rb:9:in `call' /usr/lib/ruby/1.8/rack/methodoverride.rb:24:in `call' /usr/lib/ruby/1.8/action_controller/params_parser.rb:15:in `call' /usr/lib/ruby/1.8/action_controller/session/cookie_store.rb:93:in `call' /usr/lib/ruby/1.8/action_controller/failsafe.rb:26:in `call' /usr/lib/ruby/1.8/rack/lock.rb:11:in `call' /usr/lib/ruby/1.8/rack/lock.rb:11:in `synchronize' /usr/lib/ruby/1.8/rack/lock.rb:11:in `call' /usr/lib/ruby/1.8/action_controller/dispatcher.rb:114:in `call' /usr/lib/ruby/1.8/action_controller/reloader.rb:34:in `run' /usr/lib/ruby/1.8/action_controller/dispatcher.rb:108:in `call' /home/gafas/ruby-prj/demo/vendor/rails/railties/lib/rails/rack/static.rb:31:in `call' /usr/lib/ruby/1.8/rack/urlmap.rb:47:in `call' /usr/lib/ruby/1.8/rack/urlmap.rb:41:in `each' /usr/lib/ruby/1.8/rack/urlmap.rb:41:in `call' /home/gafas/ruby-prj/demo/vendor/rails/railties/lib/rails/rack/log_tailer.rb:17:in `call' /usr/lib/ruby/1.8/rack/content_length.rb:13:in `call' /usr/lib/ruby/1.8/rack/chunked.rb:15:in `call' /usr/lib/ruby/1.8/rack/handler/mongrel.rb:67:in `process' /usr/lib/ruby/1.8/rack/handler/mongrel.rb:38:in `run' /home/gafas/ruby-prj/demo/vendor/rails/railties/lib/commands/server.rb:111 /usr/lib/ruby/1.8/rubygems/custom_require.rb:31:in `gem_original_require' /usr/lib/ruby/1.8/rubygems/custom_require.rb:31:in `require' script/server:3</code></pre> </div> <div id="Full-Trace" style="display: none;"> <pre><code>/usr/lib/ruby/1.8/action_controller/request_forgery_protection.rb:79:in `verify_authenticity_token' /usr/lib/ruby/1.8/active_support/callbacks.rb:178:in `send' /usr/lib/ruby/1.8/active_support/callbacks.rb:178:in `evaluate_method' /usr/lib/ruby/1.8/active_support/callbacks.rb:166:in `call' /usr/lib/ruby/1.8/action_controller/filters.rb:225:in `call' /usr/lib/ruby/1.8/action_controller/filters.rb:629:in `run_before_filters' /usr/lib/ruby/1.8/action_controller/filters.rb:615:in `call_filters' /usr/lib/ruby/1.8/action_controller/filters.rb:610:in `perform_action_without_benchmark' /usr/lib/ruby/1.8/action_controller/benchmarking.rb:68:in `perform_action_without_rescue' /usr/lib/ruby/1.8/active_support/core_ext/benchmark.rb:17:in `ms' /usr/lib/ruby/1.8/benchmark.rb:308:in `realtime' /usr/lib/ruby/1.8/active_support/core_ext/benchmark.rb:17:in `ms' /usr/lib/ruby/1.8/action_controller/benchmarking.rb:68:in `perform_action_without_rescue' /usr/lib/ruby/1.8/action_controller/rescue.rb:160:in `perform_action_without_flash' /usr/lib/ruby/1.8/action_controller/flash.rb:146:in `perform_action' /usr/lib/ruby/1.8/action_controller/base.rb:532:in `send' /usr/lib/ruby/1.8/action_controller/base.rb:532:in `process_without_filters' /usr/lib/ruby/1.8/action_controller/filters.rb:606:in `process' /usr/lib/ruby/1.8/action_controller/base.rb:391:in `process' /usr/lib/ruby/1.8/action_controller/base.rb:386:in `call' /usr/lib/ruby/1.8/action_controller/routing/route_set.rb:437:in `call' /usr/lib/ruby/1.8/action_controller/dispatcher.rb:87:in `dispatch' /usr/lib/ruby/1.8/action_controller/dispatcher.rb:121:in `_call' /usr/lib/ruby/1.8/action_controller/dispatcher.rb:130:in `build_middleware_stack' /usr/lib/ruby/1.8/active_record/query_cache.rb:29:in `call' /usr/lib/ruby/1.8/active_record/query_cache.rb:29:in `call' /usr/lib/ruby/1.8/active_record/connection_adapters/abstract/query_cache.rb:34:in `cache' /usr/lib/ruby/1.8/active_record/query_cache.rb:9:in `cache' /usr/lib/ruby/1.8/active_record/query_cache.rb:28:in `call' /usr/lib/ruby/1.8/active_record/connection_adapters/abstract/connection_pool.rb:361:in `call' /usr/lib/ruby/1.8/action_controller/string_coercion.rb:25:in `call' /usr/lib/ruby/1.8/rack/head.rb:9:in `call' /usr/lib/ruby/1.8/rack/methodoverride.rb:24:in `call' /usr/lib/ruby/1.8/action_controller/params_parser.rb:15:in `call' /usr/lib/ruby/1.8/action_controller/session/cookie_store.rb:93:in `call' /usr/lib/ruby/1.8/action_controller/failsafe.rb:26:in `call' /usr/lib/ruby/1.8/rack/lock.rb:11:in `call' /usr/lib/ruby/1.8/rack/lock.rb:11:in `synchronize' /usr/lib/ruby/1.8/rack/lock.rb:11:in `call' /usr/lib/ruby/1.8/action_controller/dispatcher.rb:114:in `call' /usr/lib/ruby/1.8/action_controller/reloader.rb:34:in `run' /usr/lib/ruby/1.8/action_controller/dispatcher.rb:108:in `call' /home/gafas/ruby-prj/demo/vendor/rails/railties/lib/rails/rack/static.rb:31:in `call' /usr/lib/ruby/1.8/rack/urlmap.rb:47:in `call' /usr/lib/ruby/1.8/rack/urlmap.rb:41:in `each' /usr/lib/ruby/1.8/rack/urlmap.rb:41:in `call' /home/gafas/ruby-prj/demo/vendor/rails/railties/lib/rails/rack/log_tailer.rb:17:in `call' /usr/lib/ruby/1.8/rack/content_length.rb:13:in `call' /usr/lib/ruby/1.8/rack/chunked.rb:15:in `call' /usr/lib/ruby/1.8/rack/handler/mongrel.rb:67:in `process' /var/lib/gems/1.8/gems/mongrel-1.1.5/lib/mongrel.rb:159:in `process_client' /var/lib/gems/1.8/gems/mongrel-1.1.5/lib/mongrel.rb:158:in `each' /var/lib/gems/1.8/gems/mongrel-1.1.5/lib/mongrel.rb:158:in `process_client' /var/lib/gems/1.8/gems/mongrel-1.1.5/lib/mongrel.rb:285:in `run' /var/lib/gems/1.8/gems/mongrel-1.1.5/lib/mongrel.rb:285:in `initialize' /var/lib/gems/1.8/gems/mongrel-1.1.5/lib/mongrel.rb:285:in `new' /var/lib/gems/1.8/gems/mongrel-1.1.5/lib/mongrel.rb:285:in `run' /var/lib/gems/1.8/gems/mongrel-1.1.5/lib/mongrel.rb:268:in `initialize' /var/lib/gems/1.8/gems/mongrel-1.1.5/lib/mongrel.rb:268:in `new' /var/lib/gems/1.8/gems/mongrel-1.1.5/lib/mongrel.rb:268:in `run' /usr/lib/ruby/1.8/rack/handler/mongrel.rb:38:in `run' /home/gafas/ruby-prj/demo/vendor/rails/railties/lib/commands/server.rb:111 /usr/lib/ruby/1.8/rubygems/custom_require.rb:31:in `gem_original_require' /usr/lib/ruby/1.8/rubygems/custom_require.rb:31:in `require' script/server:3</code></pre> </div> </div>
<h2 style="margin-top: 30px">Request</h2> <p><b>Parameters</b>: <pre>{"login"=>"login", "password"=>"password"}</pre></p>
<p><a href="#" onclick="document.getElementById('session_dump').style.display='block'; return false;">Show session dump</a></p> <div id="session_dump" style="display:none"><pre class='debug_dump'>--- </pre></div>
<h2 style="margin-top: 30px">Response</h2> <p><b>Headers</b>: <pre>{"Content-Type"=>"", "Cache-Control"=>"no-cache"}</pre></p>
</body> </html>
|
Помогите разобраться в чем причина ! З.Ы. Данный пользователь в системе зарегистрирован и через браузер работает нормально !!! Если нужны еще какие то логи или код - предоставлю ! Это сообщение отредактировал(а) TimeBreak - 13.6.2011, 18:53
|