Поиск:

Ответ в темуСоздание новой темы Создание опроса
> Немогу пройти авторизицию ! 
:(
    Опции темы
TimeBreak
Дата 13.6.2011, 18:39 (ссылка) | (нет голосов) Загрузка ... Загрузка ... Быстрая цитата Цитата


Новичок



Профиль
Группа: Участник
Сообщений: 12
Регистрация: 18.3.2009

Репутация: нет
Всего: -2



Всем привет ! 
Возникла следующая проблема : есть контроллер отвечающий за авторизацию и создание сессии 
Код

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>{&quot;login&quot;=&gt;&quot;login&quot;,
 &quot;password&quot;=&gt;&quot;password&quot;}</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>{&quot;Content-Type&quot;=&gt;&quot;&quot;,
 &quot;Cache-Control&quot;=&gt;&quot;no-cache&quot;}</pre></p>

</body>
</html>

Помогите разобраться в чем причина !
З.Ы.
Данный пользователь в системе зарегистрирован и через браузер работает нормально !!!
Если нужны еще какие то логи или код - предоставлю !


Это сообщение отредактировал(а) TimeBreak - 13.6.2011, 18:53
PM MAIL   Вверх
source777
Дата 14.6.2011, 22:10 (ссылка) | (нет голосов) Загрузка ... Загрузка ... Быстрая цитата Цитата


Эксперт
***


Профиль
Группа: Завсегдатай
Сообщений: 1878
Регистрация: 12.3.2007

Репутация: 12
Всего: 56



Цитата(TimeBreak @  13.6.2011,  18:39 Найти цитируемый пост)
В ответ сервер отвечает 442 статусом и выдает такой мусор в resp.body

Не мусор, а backtrace, в котором подробно описано в чём проблема. Если вкратце, то это встроенная в Rails защита предотвращает доступ твоего бота к отправке формы. Подробнее читай в Ruby On Rails Security Guide.


--------------------
Если бы программистам платили за то, чтобы убирать код из программы вместо того, чтобы добавлять его, программы были бы намного лучше © Николас Негропонте
PM MAIL   Вверх
  
Ответ в темуСоздание новой темы Создание опроса
Правила форума "Ruby on Rails"
source777
  • С чего начать? начинаем
  • Документацию смотрим тут
  • Обязательно следуйте правилам Vingrad.
  • Пожалуйста, прочитайте рекомендации по работе в форуме и навигации по Vingrad.
  • Для вставки кодов Ruby используйте тег: [code=ruby]код[/code]. Когда в будущем подсветка синтаксиса для Ruby будет реализована, весь исходных код преобразится.
  • Используйтe чекбокс "Транслит" (возле кнопок кодов), если у Вас нет русских шрифтов.
  • Помните, для каждого вопроса должна быть своя тема.

Если Вам понравилась атмосфера форума, заходите к нам чаще! С уважением, source777.

 
1 Пользователей читают эту тему (1 Гостей и 0 Скрытых Пользователей)
0 Пользователей:
« Предыдущая тема | Ruby On Rails | Следующая тема »


 




[ Время генерации скрипта: 0.0670 ]   [ Использовано запросов: 21 ]   [ GZIP включён ]


Реклама на сайте     Информационное спонсорство

 
По вопросам размещения рекламы пишите на vladimir(sobaka)vingrad.ru
Отказ от ответственности     Powered by Invision Power Board(R) 1.3 © 2003  IPS, Inc.