Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- def signin
- if request.post?
- begin
- session[:user] = User.authenticate(params[:username], params[:password]).id
- redirect_to :action => session[:intended_action], :controller => session[:intended_controller]
- rescue RuntimeError => boom
- flash[:notice] = boom
- redirect_to :action => :signin
- end
- end
- end
- ##user model
- require 'digest/sha2'
- class User < ActiveRecord::Base
- has_and_belongs_to_many :restaurants
- def password=(pass)
- salt = [Array.new(6){rand(256).chr}.join].pack("m").chomp
- self.password_salt, self.password_hash = salt, Digest::SHA256.hexdigest(pass + salt)
- end
- def self.authenticate(username, password)
- user = User.find(:first, :conditions => ['username = ?', username])
- if user.blank? || Digest::SHA256.hexdigest(password + user.password_salt) != user.password_hash
- raise "Username or password invalid"
- end
- user
- end
- end
- ##session dump
- ---
- :intended_action: index
- :intended_controller: restaurants
- :user: 1
- flash: !map:ActionController::Flash::FlashHash
- :notice: !ruby/exception:RuntimeError
- message: Username or password invalid
- ##full trace
- vendor/rails/actionpack/lib/action_controller/session/cookie_store.rb:91:in `close'
- /usr/local/lib/ruby/1.8/cgi/session.rb:330:in `close'
- vendor/rails/actionpack/lib/action_controller/base.rb:1221:in `close_session'
- vendor/rails/actionpack/lib/action_controller/base.rb:1265:in `process_cleanup_without_flash'
- vendor/rails/actionpack/lib/action_controller/flash.rb:180:in `process_cleanup_without_session_management_support'
- vendor/rails/actionpack/lib/action_controller/session_management.rb:132:in `process_cleanup_without_components'
- vendor/rails/actionpack/lib/action_controller/components.rb:161:in `process_cleanup'
- vendor/rails/actionpack/lib/action_controller/base.rb:502:in `process_without_filters'
- vendor/rails/actionpack/lib/action_controller/filters.rb:747:in `process_without_session_management_support'
- vendor/rails/actionpack/lib/action_controller/session_management.rb:122:in `process'
- vendor/rails/actionpack/lib/action_controller/base.rb:346:in `process'
- vendor/rails/railties/lib/dispatcher.rb:39:in `dispatch'
- /usr/local/lib/ruby/gems/1.8/gems/mongrel-1.0.1/lib/mongrel/rails.rb:78:in `process'
- /usr/local/lib/ruby/gems/1.8/gems/mongrel-1.0.1/lib/mongrel/rails.rb:76:in `process'
- /usr/local/lib/ruby/gems/1.8/gems/mongrel-1.0.1/lib/mongrel.rb:618:in `process_client'
- /usr/local/lib/ruby/gems/1.8/gems/mongrel-1.0.1/lib/mongrel.rb:617:in `process_client'
- /usr/local/lib/ruby/gems/1.8/gems/mongrel-1.0.1/lib/mongrel.rb:736:in `run'
- /usr/local/lib/ruby/gems/1.8/gems/mongrel-1.0.1/lib/mongrel.rb:736:in `run'
- /usr/local/lib/ruby/gems/1.8/gems/mongrel-1.0.1/lib/mongrel.rb:720:in `run'
- /usr/local/lib/ruby/gems/1.8/gems/mongrel-1.0.1/lib/mongrel/configurator.rb:271:in `run'
- /usr/local/lib/ruby/gems/1.8/gems/mongrel-1.0.1/lib/mongrel/configurator.rb:270:in `run'
- /usr/local/lib/ruby/gems/1.8/gems/mongrel-1.0.1/bin/mongrel_rails:127:in `run'
- /usr/local/lib/ruby/gems/1.8/gems/mongrel-1.0.1/lib/mongrel/command.rb:211:in `run'
- /usr/local/lib/ruby/gems/1.8/gems/mongrel-1.0.1/bin/mongrel_rails:243
- vendor/rails/activesupport/lib/active_support/dependencies.rb:488:in `load'
- vendor/rails/activesupport/lib/active_support/dependencies.rb:342:in `new_constants_in'
- vendor/rails/activesupport/lib/active_support/dependencies.rb:488:in `load'
- vendor/rails/railties/lib/commands/servers/mongrel.rb:64
- /usr/local/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:27:in `require'
- vendor/rails/activesupport/lib/active_support/dependencies.rb:495:in `require'
- vendor/rails/activesupport/lib/active_support/dependencies.rb:342:in `new_constants_in'
- vendor/rails/activesupport/lib/active_support/dependencies.rb:495:in `require'
- vendor/rails/railties/lib/commands/server.rb:39
- script/server:3
- ##log
- Processing HomeController#signin (for 127.0.0.1 at 2007-06-18 14:10:02) [POST]
- Session ID: BAh7CToUaW50ZW5kZWRfYWN0aW9uIgppbmRleDoYaW50ZW5kZWRfY29udHJv%0AbGxlciIQcmVzdGF1cmFudHM6CXVzZXJpBiIKZmxhc2hJQzonQWN0aW9uQ29u%0AdHJvbGxlcjo6Rmxhc2g6OkZsYXNoSGFzaHsABjoKQHVzZWR7AA%3D%3D--dc0e44157f47130094778e3423e343ebbae55a17
- Parameters: {"commit"=>"Sign in", "/home/signin"=>nil, "username"=>"chad", "action"=>"signin", "controller"=>"home", "password"=>""}
- CGI::Session::CookieStore::CookieOverflow (CGI::Session::CookieStore::CookieOverflow):
- /vendor/rails/actionpack/lib/action_controller/session/cookie_store.rb:91:in `close'
- /usr/local/lib/ruby/1.8/cgi/session.rb:330:in `close'
- /vendor/rails/actionpack/lib/action_controller/base.rb:1221:in `close_session'
- /vendor/rails/actionpack/lib/action_controller/base.rb:1265:in `process_cleanup_without_flash'
- /vendor/rails/actionpack/lib/action_controller/flash.rb:180:in `process_cleanup_without_session_management_support'
- /vendor/rails/actionpack/lib/action_controller/session_management.rb:132:in `process_cleanup_without_components'
- /vendor/rails/actionpack/lib/action_controller/components.rb:161:in `process_cleanup'
- /vendor/rails/actionpack/lib/action_controller/base.rb:502:in `process_without_filters'
- /vendor/rails/actionpack/lib/action_controller/filters.rb:747:in `process_without_session_management_support'
- /vendor/rails/actionpack/lib/action_controller/session_management.rb:122:in `process'
- /vendor/rails/actionpack/lib/action_controller/base.rb:346:in `process'
- /vendor/rails/railties/lib/dispatcher.rb:39:in `dispatch'
- /usr/local/lib/ruby/gems/1.8/gems/mongrel-1.0.1/lib/mongrel/rails.rb:78:in `process'
- /usr/local/lib/ruby/gems/1.8/gems/mongrel-1.0.1/lib/mongrel/rails.rb:76:in `process'
- /usr/local/lib/ruby/gems/1.8/gems/mongrel-1.0.1/lib/mongrel.rb:618:in `process_client'
- /usr/local/lib/ruby/gems/1.8/gems/mongrel-1.0.1/lib/mongrel.rb:617:in `process_client'
- /usr/local/lib/ruby/gems/1.8/gems/mongrel-1.0.1/lib/mongrel.rb:736:in `run'
- /usr/local/lib/ruby/gems/1.8/gems/mongrel-1.0.1/lib/mongrel.rb:736:in `run'
- /usr/local/lib/ruby/gems/1.8/gems/mongrel-1.0.1/lib/mongrel.rb:720:in `run'
- /usr/local/lib/ruby/gems/1.8/gems/mongrel-1.0.1/lib/mongrel/configurator.rb:271:in `run'
- /usr/local/lib/ruby/gems/1.8/gems/mongrel-1.0.1/lib/mongrel/configurator.rb:270:in `run'
- /usr/local/lib/ruby/gems/1.8/gems/mongrel-1.0.1/bin/mongrel_rails:127:in `run'
- /usr/local/lib/ruby/gems/1.8/gems/mongrel-1.0.1/lib/mongrel/command.rb:211:in `run'
- /usr/local/lib/ruby/gems/1.8/gems/mongrel-1.0.1/bin/mongrel_rails:243
- /vendor/rails/activesupport/lib/active_support/dependencies.rb:488:in `load'
- /vendor/rails/activesupport/lib/active_support/dependencies.rb:342:in `new_constants_in'
- /vendor/rails/activesupport/lib/active_support/dependencies.rb:488:in `load'
- /vendor/rails/railties/lib/commands/servers/mongrel.rb:64
- /usr/local/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:27:in `require'
- /vendor/rails/activesupport/lib/active_support/dependencies.rb:495:in `require'
- /vendor/rails/activesupport/lib/active_support/dependencies.rb:342:in `new_constants_in'
- /vendor/rails/activesupport/lib/active_support/dependencies.rb:495:in `require'
- /vendor/rails/railties/lib/commands/server.rb:39
- script/server:3
Add Comment
Please, Sign In to add comment