Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- production.log:
- Processing UsersController#activate (for xx.xx.xx.xx at 2008-12-28 19:40:49) [GET]
- NoMethodError (undefined method `active?' for :false:Symbol):
- /app/controllers/users_controller.rb:37:in `activate'
- /usr/local/lib/ruby/gems/1.8/gems/actionpack-2.2.2/lib/action_controller/base.rb:1253:in `send'
- /usr/local/lib/ruby/gems/1.8/gems/actionpack-2.2.2/lib/action_controller/base.rb:1253:in `perform_action_without_filters'
- /usr/local/lib/ruby/gems/1.8/gems/actionpack-2.2.2/lib/action_controller/filters.rb:617:in `call_filters'
- /usr/local/lib/ruby/gems/1.8/gems/actionpack-2.2.2/lib/action_controller/filters.rb:610:in `perform_action_without_benchmark'
- /usr/local/lib/ruby/gems/1.8/gems/actionpack-2.2.2/lib/action_controller/benchmarking.rb:68:in `perform_action_without_rescue'
- /usr/local/lib/ruby/1.8/benchmark.rb:293:in `measure'
- /usr/local/lib/ruby/gems/1.8/gems/actionpack-2.2.2/lib/action_controller/benchmarking.rb:68:in `perform_action_without_rescue'
- /usr/local/lib/ruby/gems/1.8/gems/actionpack-2.2.2/lib/action_controller/rescue.rb:136:in `perform_action_without_caching'
- /usr/local/lib/ruby/gems/1.8/gems/actionpack-2.2.2/lib/action_controller/caching/sql_cache.rb:13:in `perform_action'
- /usr/local/lib/ruby/gems/1.8/gems/activerecord-2.2.2/lib/active_record/connection_adapters/abstract/query_cache.rb:34:in `cache'
- /usr/local/lib/ruby/gems/1.8/gems/activerecord-2.2.2/lib/active_record/query_cache.rb:8:in `cache'
- /usr/local/lib/ruby/gems/1.8/gems/actionpack-2.2.2/lib/action_controller/caching/sql_cache.rb:12:in `perform_action'
- /usr/local/lib/ruby/gems/1.8/gems/actionpack-2.2.2/lib/action_controller/base.rb:524:in `send'
- /usr/local/lib/ruby/gems/1.8/gems/actionpack-2.2.2/lib/action_controller/base.rb:524:in `process_without_filters'
- /usr/local/lib/ruby/gems/1.8/gems/actionpack-2.2.2/lib/action_controller/filters.rb:606:in `process_without_session_management_support'
- /usr/local/lib/ruby/gems/1.8/gems/actionpack-2.2.2/lib/action_controller/session_management.rb:134:in `process'
- /usr/local/lib/ruby/gems/1.8/gems/actionpack-2.2.2/lib/action_controller/base.rb:392:in `process'
- /usr/local/lib/ruby/gems/1.8/gems/actionpack-2.2.2/lib/action_controller/dispatcher.rb:183:in `handle_request'
- /usr/local/lib/ruby/gems/1.8/gems/actionpack-2.2.2/lib/action_controller/dispatcher.rb:110:in `dispatch_unlocked'
- /usr/local/lib/ruby/gems/1.8/gems/actionpack-2.2.2/lib/action_controller/dispatcher.rb:123:in `dispatch'
- /usr/local/lib/ruby/gems/1.8/gems/actionpack-2.2.2/lib/action_controller/dispatcher.rb:122:in `synchronize'
- /usr/local/lib/ruby/gems/1.8/gems/actionpack-2.2.2/lib/action_controller/dispatcher.rb:122:in `dispatch'
- /usr/local/lib/ruby/gems/1.8/gems/actionpack-2.2.2/lib/action_controller/dispatcher.rb:132:in `dispatch_cgi'
- /usr/local/lib/ruby/gems/1.8/gems/actionpack-2.2.2/lib/action_controller/dispatcher.rb:39:in `dispatch'
- /usr/local/lib/ruby/gems/1.8/gems/rails-2.2.2/lib/fcgi_handler.rb:101:in `process_request'
- /usr/local/lib/ruby/gems/1.8/gems/rails-2.2.2/lib/fcgi_handler.rb:151:in `with_signal_handler'
- /usr/local/lib/ruby/gems/1.8/gems/rails-2.2.2/lib/fcgi_handler.rb:99:in `process_request'
- /usr/local/lib/ruby/gems/1.8/gems/rails-2.2.2/lib/fcgi_handler.rb:76:in `process_each_request'
- /usr/local/lib/ruby/gems/1.8/gems/fcgi-0.8.7/lib/fcgi.rb:612:in `each_cgi'
- /usr/local/lib/ruby/gems/1.8/gems/fcgi-0.8.7/lib/fcgi.rb:609:in `each'
- /usr/local/lib/ruby/gems/1.8/gems/fcgi-0.8.7/lib/fcgi.rb:609:in `each_cgi'
- /usr/local/lib/ruby/gems/1.8/gems/rails-2.2.2/lib/fcgi_handler.rb:75:in `process_each_request'
- /usr/local/lib/ruby/gems/1.8/gems/rails-2.2.2/lib/fcgi_handler.rb:74:in `catch'
- /usr/local/lib/ruby/gems/1.8/gems/rails-2.2.2/lib/fcgi_handler.rb:74:in `process_each_request'
- /usr/local/lib/ruby/gems/1.8/gems/rails-2.2.2/lib/fcgi_handler.rb:49:in `process!'
- /usr/local/lib/ruby/gems/1.8/gems/rails-2.2.2/lib/fcgi_handler.rb:23:in `process!'
- dispatch.fcgi:24
- Rendering /home/jeffwal/qwikpc/public/500.html (500 Internal Server Error)
- controller:
- class UsersController < ApplicationController
- # Be sure to include AuthenticationSystem in Application Controller instead
- include AuthenticatedSystem
- # Protect these actions behind an admin login
- # before_filter :admin_required, :only => [:suspend, :unsuspend, :destroy, :purge]
- before_filter :find_user, :only => [:suspend, :unsuspend, :destroy, :purge]
- # render new.rhtml
- def new
- end
- def denied
- end
- def create
- cookies.delete :auth_token
- # protects against session fixation attacks, wreaks havoc with
- # request forgery protection.
- # uncomment at your own risk
- # reset_session
- @user = User.new(params[:user])
- @user.register! if @user.valid?
- if @user.errors.empty?
- # self.current_user = @user
- #redirect_back_or_default('/activate')
- redirect_to activate_path
- flash[:notice] = "Thanks for signing up!"
- else
- render :action => 'new'
- end
- end
- def activate
- self.current_user = User.find_by_activation_code(params[:id])
- self.current_user = params[:activation_code].blank? ? :false :
- User.find_by_activation_code(params[:activation_code])
- if logged_in? && !current_user.active?
- current_user.notify!
- current_user.activate!
- flash[:notice] = "Signup complete!"
- end
- redirect_back_or_default('/')
- end
- def suspend
- @user.suspend!
- redirect_to users_path
- end
- def unsuspend
- @user.unsuspend!
- redirect_to users_path
- end
- def destroy
- @user.delete!
- redirect_to users_path
- end
- def purge
- @user.destroy
- redirect_to users_path
- end
- protected
- def find_user
- @user = User.find(params[:id])
- end
- end
- model:
- require 'digest/sha1'
- class User < ActiveRecord::Base
- # Virtual attribute for the unencrypted password
- attr_accessor :password
- validates_presence_of :login, :email #:first_name, :last_name
- validates_presence_of :password, :if => :password_required?
- validates_presence_of :password_confirmation, :if => :password_required?
- validates_length_of :password, :within => 4..40, :if => :password_required?
- validates_confirmation_of :password, :if => :password_required?
- #validates_length_of :first_name, :within => 3..40
- #validates_length_of :last_name, :within => 3..40
- validates_length_of :login, :within => 3..40
- validates_length_of :email, :within => 3..100
- validates_uniqueness_of :login, :email, :case_sensitive => false
- before_save :encrypt_password
- # prevents a user from submitting a crafted form that bypasses activation
- # anything else you want your user to change should be added here.
- attr_accessible :login, :email, :password, :password_confirmation, :first_name, :last_name
- acts_as_state_machine :initial => :pending
- state :passive
- state :notified
- state :pending, :enter => :make_activation_code
- state :active, :enter => :do_activate
- state :suspended
- state :deleted, :enter => :do_delete
- event :register do
- transitions :from => :passive, :to => :pending, :guard => Proc.new {|u| !(u.crypted_password.blank? && u.password.blank?) }
- end
- event :notify do
- transitions :from => :pending, :to => :notified
- end
- event :activate do
- transitions :from => :notified, :to => :active
- end
- event :suspend do
- transitions :from => [:passive, :pending, :notified, :active], :to => :suspended
- end
- event :delete do
- transitions :from => [:passive, :pending, :notified, :active, :suspended], :to => :deleted
- end
- event :unsuspend do
- transitions :from => :suspended, :to => :active, :guard => Proc.new {|u| !u.activated_at.blank? }
- transitions :from => :suspended, :to => :pending, :guard => Proc.new {|u| !u.activation_code.blank? }
- transitions :from => :suspended, :to => :passive
- end
- # Authenticates a user by their login name and unencrypted password. Returns the user or nil.
- def self.authenticate(login, password)
- u = find_in_state :first, :active, :conditions => {:login => login} # need to get the salt
- u && u.authenticated?(password) ? u : nil
- end
- # Encrypts some data with the salt.
- def self.encrypt(password, salt)
- Digest::SHA1.hexdigest("--#{salt}--#{password}--")
- end
- # Encrypts the password with the user salt
- def encrypt(password)
- self.class.encrypt(password, salt)
- end
- def authenticated?(password)
- crypted_password == encrypt(password)
- end
- def remember_token?
- remember_token_expires_at && Time.now.utc < remember_token_expires_at
- end
- # These create and unset the fields required for remembering users between browser closes
- def remember_me
- remember_me_for 2.weeks
- end
- def remember_me_for(time)
- remember_me_until time.from_now.utc
- end
- def remember_me_until(time)
- self.remember_token_expires_at = time
- self.remember_token = encrypt("#{email}--#{remember_token_expires_at}")
- save(false)
- end
- def forget_me
- self.remember_token_expires_at = nil
- self.remember_token = nil
- save(false)
- end
- # Returns true if the user has just been activated.
- def recently_activated?
- @activated
- end
- protected
- # before filter
- def encrypt_password
- return if password.blank?
- self.salt = Digest::SHA1.hexdigest("--#{Time.now.to_s}--#{login}--") if new_record?
- self.crypted_password = encrypt(password)
- end
- def password_required?
- crypted_password.blank? || !password.blank?
- end
- def make_activation_code
- self.deleted_at = nil
- self.activation_code = Digest::SHA1.hexdigest( Time.now.to_s.split(//).sort_by {rand}.join )
- end
- def do_delete
- self.deleted_at = Time.now.utc
- end
- def do_activate
- @activated = true
- self.activated_at = Time.now.utc
- self.deleted_at = self.activation_code = nil
- end
- end
Add Comment
Please, Sign In to add comment