Guest User

Untitled

a guest
May 30th, 2018
141
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 10.03 KB | None | 0 0
  1. production.log:
  2.  
  3. Processing UsersController#activate (for xx.xx.xx.xx at 2008-12-28 19:40:49) [GET]
  4.  
  5.  
  6. NoMethodError (undefined method `active?' for :false:Symbol):
  7. /app/controllers/users_controller.rb:37:in `activate'
  8. /usr/local/lib/ruby/gems/1.8/gems/actionpack-2.2.2/lib/action_controller/base.rb:1253:in `send'
  9. /usr/local/lib/ruby/gems/1.8/gems/actionpack-2.2.2/lib/action_controller/base.rb:1253:in `perform_action_without_filters'
  10. /usr/local/lib/ruby/gems/1.8/gems/actionpack-2.2.2/lib/action_controller/filters.rb:617:in `call_filters'
  11. /usr/local/lib/ruby/gems/1.8/gems/actionpack-2.2.2/lib/action_controller/filters.rb:610:in `perform_action_without_benchmark'
  12. /usr/local/lib/ruby/gems/1.8/gems/actionpack-2.2.2/lib/action_controller/benchmarking.rb:68:in `perform_action_without_rescue'
  13. /usr/local/lib/ruby/1.8/benchmark.rb:293:in `measure'
  14. /usr/local/lib/ruby/gems/1.8/gems/actionpack-2.2.2/lib/action_controller/benchmarking.rb:68:in `perform_action_without_rescue'
  15. /usr/local/lib/ruby/gems/1.8/gems/actionpack-2.2.2/lib/action_controller/rescue.rb:136:in `perform_action_without_caching'
  16. /usr/local/lib/ruby/gems/1.8/gems/actionpack-2.2.2/lib/action_controller/caching/sql_cache.rb:13:in `perform_action'
  17. /usr/local/lib/ruby/gems/1.8/gems/activerecord-2.2.2/lib/active_record/connection_adapters/abstract/query_cache.rb:34:in `cache'
  18. /usr/local/lib/ruby/gems/1.8/gems/activerecord-2.2.2/lib/active_record/query_cache.rb:8:in `cache'
  19. /usr/local/lib/ruby/gems/1.8/gems/actionpack-2.2.2/lib/action_controller/caching/sql_cache.rb:12:in `perform_action'
  20. /usr/local/lib/ruby/gems/1.8/gems/actionpack-2.2.2/lib/action_controller/base.rb:524:in `send'
  21. /usr/local/lib/ruby/gems/1.8/gems/actionpack-2.2.2/lib/action_controller/base.rb:524:in `process_without_filters'
  22. /usr/local/lib/ruby/gems/1.8/gems/actionpack-2.2.2/lib/action_controller/filters.rb:606:in `process_without_session_management_support'
  23. /usr/local/lib/ruby/gems/1.8/gems/actionpack-2.2.2/lib/action_controller/session_management.rb:134:in `process'
  24. /usr/local/lib/ruby/gems/1.8/gems/actionpack-2.2.2/lib/action_controller/base.rb:392:in `process'
  25. /usr/local/lib/ruby/gems/1.8/gems/actionpack-2.2.2/lib/action_controller/dispatcher.rb:183:in `handle_request'
  26. /usr/local/lib/ruby/gems/1.8/gems/actionpack-2.2.2/lib/action_controller/dispatcher.rb:110:in `dispatch_unlocked'
  27. /usr/local/lib/ruby/gems/1.8/gems/actionpack-2.2.2/lib/action_controller/dispatcher.rb:123:in `dispatch'
  28. /usr/local/lib/ruby/gems/1.8/gems/actionpack-2.2.2/lib/action_controller/dispatcher.rb:122:in `synchronize'
  29. /usr/local/lib/ruby/gems/1.8/gems/actionpack-2.2.2/lib/action_controller/dispatcher.rb:122:in `dispatch'
  30. /usr/local/lib/ruby/gems/1.8/gems/actionpack-2.2.2/lib/action_controller/dispatcher.rb:132:in `dispatch_cgi'
  31. /usr/local/lib/ruby/gems/1.8/gems/actionpack-2.2.2/lib/action_controller/dispatcher.rb:39:in `dispatch'
  32. /usr/local/lib/ruby/gems/1.8/gems/rails-2.2.2/lib/fcgi_handler.rb:101:in `process_request'
  33. /usr/local/lib/ruby/gems/1.8/gems/rails-2.2.2/lib/fcgi_handler.rb:151:in `with_signal_handler'
  34. /usr/local/lib/ruby/gems/1.8/gems/rails-2.2.2/lib/fcgi_handler.rb:99:in `process_request'
  35. /usr/local/lib/ruby/gems/1.8/gems/rails-2.2.2/lib/fcgi_handler.rb:76:in `process_each_request'
  36. /usr/local/lib/ruby/gems/1.8/gems/fcgi-0.8.7/lib/fcgi.rb:612:in `each_cgi'
  37. /usr/local/lib/ruby/gems/1.8/gems/fcgi-0.8.7/lib/fcgi.rb:609:in `each'
  38. /usr/local/lib/ruby/gems/1.8/gems/fcgi-0.8.7/lib/fcgi.rb:609:in `each_cgi'
  39. /usr/local/lib/ruby/gems/1.8/gems/rails-2.2.2/lib/fcgi_handler.rb:75:in `process_each_request'
  40. /usr/local/lib/ruby/gems/1.8/gems/rails-2.2.2/lib/fcgi_handler.rb:74:in `catch'
  41. /usr/local/lib/ruby/gems/1.8/gems/rails-2.2.2/lib/fcgi_handler.rb:74:in `process_each_request'
  42. /usr/local/lib/ruby/gems/1.8/gems/rails-2.2.2/lib/fcgi_handler.rb:49:in `process!'
  43. /usr/local/lib/ruby/gems/1.8/gems/rails-2.2.2/lib/fcgi_handler.rb:23:in `process!'
  44. dispatch.fcgi:24
  45.  
  46. Rendering /home/jeffwal/qwikpc/public/500.html (500 Internal Server Error)
  47. controller:
  48.  
  49. class UsersController < ApplicationController
  50. # Be sure to include AuthenticationSystem in Application Controller instead
  51. include AuthenticatedSystem
  52.  
  53. # Protect these actions behind an admin login
  54. # before_filter :admin_required, :only => [:suspend, :unsuspend, :destroy, :purge]
  55. before_filter :find_user, :only => [:suspend, :unsuspend, :destroy, :purge]
  56.  
  57.  
  58. # render new.rhtml
  59. def new
  60. end
  61. def denied
  62. end
  63. def create
  64. cookies.delete :auth_token
  65. # protects against session fixation attacks, wreaks havoc with
  66. # request forgery protection.
  67. # uncomment at your own risk
  68. # reset_session
  69. @user = User.new(params[:user])
  70. @user.register! if @user.valid?
  71. if @user.errors.empty?
  72. # self.current_user = @user
  73. #redirect_back_or_default('/activate')
  74. redirect_to activate_path
  75. flash[:notice] = "Thanks for signing up!"
  76. else
  77. render :action => 'new'
  78. end
  79. end
  80.  
  81. def activate
  82. self.current_user = User.find_by_activation_code(params[:id])
  83. self.current_user = params[:activation_code].blank? ? :false :
  84. User.find_by_activation_code(params[:activation_code])
  85. if logged_in? && !current_user.active?
  86. current_user.notify!
  87. current_user.activate!
  88. flash[:notice] = "Signup complete!"
  89. end
  90. redirect_back_or_default('/')
  91. end
  92.  
  93. def suspend
  94. @user.suspend!
  95. redirect_to users_path
  96. end
  97.  
  98. def unsuspend
  99. @user.unsuspend!
  100. redirect_to users_path
  101. end
  102.  
  103. def destroy
  104. @user.delete!
  105. redirect_to users_path
  106. end
  107.  
  108. def purge
  109. @user.destroy
  110. redirect_to users_path
  111. end
  112.  
  113. protected
  114. def find_user
  115. @user = User.find(params[:id])
  116. end
  117.  
  118. end
  119.  
  120.  
  121. model:
  122.  
  123. require 'digest/sha1'
  124. class User < ActiveRecord::Base
  125. # Virtual attribute for the unencrypted password
  126. attr_accessor :password
  127.  
  128. validates_presence_of :login, :email #:first_name, :last_name
  129. validates_presence_of :password, :if => :password_required?
  130. validates_presence_of :password_confirmation, :if => :password_required?
  131. validates_length_of :password, :within => 4..40, :if => :password_required?
  132. validates_confirmation_of :password, :if => :password_required?
  133. #validates_length_of :first_name, :within => 3..40
  134. #validates_length_of :last_name, :within => 3..40
  135. validates_length_of :login, :within => 3..40
  136. validates_length_of :email, :within => 3..100
  137. validates_uniqueness_of :login, :email, :case_sensitive => false
  138. before_save :encrypt_password
  139.  
  140. # prevents a user from submitting a crafted form that bypasses activation
  141. # anything else you want your user to change should be added here.
  142. attr_accessible :login, :email, :password, :password_confirmation, :first_name, :last_name
  143.  
  144. acts_as_state_machine :initial => :pending
  145. state :passive
  146. state :notified
  147. state :pending, :enter => :make_activation_code
  148. state :active, :enter => :do_activate
  149. state :suspended
  150. state :deleted, :enter => :do_delete
  151.  
  152. event :register do
  153. transitions :from => :passive, :to => :pending, :guard => Proc.new {|u| !(u.crypted_password.blank? && u.password.blank?) }
  154. end
  155.  
  156. event :notify do
  157. transitions :from => :pending, :to => :notified
  158. end
  159.  
  160. event :activate do
  161. transitions :from => :notified, :to => :active
  162. end
  163.  
  164. event :suspend do
  165. transitions :from => [:passive, :pending, :notified, :active], :to => :suspended
  166. end
  167.  
  168. event :delete do
  169. transitions :from => [:passive, :pending, :notified, :active, :suspended], :to => :deleted
  170. end
  171.  
  172. event :unsuspend do
  173. transitions :from => :suspended, :to => :active, :guard => Proc.new {|u| !u.activated_at.blank? }
  174. transitions :from => :suspended, :to => :pending, :guard => Proc.new {|u| !u.activation_code.blank? }
  175. transitions :from => :suspended, :to => :passive
  176. end
  177.  
  178. # Authenticates a user by their login name and unencrypted password. Returns the user or nil.
  179. def self.authenticate(login, password)
  180. u = find_in_state :first, :active, :conditions => {:login => login} # need to get the salt
  181. u && u.authenticated?(password) ? u : nil
  182. end
  183.  
  184. # Encrypts some data with the salt.
  185. def self.encrypt(password, salt)
  186. Digest::SHA1.hexdigest("--#{salt}--#{password}--")
  187. end
  188.  
  189. # Encrypts the password with the user salt
  190. def encrypt(password)
  191. self.class.encrypt(password, salt)
  192. end
  193.  
  194. def authenticated?(password)
  195. crypted_password == encrypt(password)
  196. end
  197.  
  198. def remember_token?
  199. remember_token_expires_at && Time.now.utc < remember_token_expires_at
  200. end
  201.  
  202. # These create and unset the fields required for remembering users between browser closes
  203. def remember_me
  204. remember_me_for 2.weeks
  205. end
  206.  
  207. def remember_me_for(time)
  208. remember_me_until time.from_now.utc
  209. end
  210.  
  211. def remember_me_until(time)
  212. self.remember_token_expires_at = time
  213. self.remember_token = encrypt("#{email}--#{remember_token_expires_at}")
  214. save(false)
  215. end
  216.  
  217. def forget_me
  218. self.remember_token_expires_at = nil
  219. self.remember_token = nil
  220. save(false)
  221. end
  222.  
  223. # Returns true if the user has just been activated.
  224. def recently_activated?
  225. @activated
  226. end
  227.  
  228. protected
  229. # before filter
  230. def encrypt_password
  231. return if password.blank?
  232. self.salt = Digest::SHA1.hexdigest("--#{Time.now.to_s}--#{login}--") if new_record?
  233. self.crypted_password = encrypt(password)
  234. end
  235.  
  236. def password_required?
  237. crypted_password.blank? || !password.blank?
  238. end
  239.  
  240. def make_activation_code
  241. self.deleted_at = nil
  242. self.activation_code = Digest::SHA1.hexdigest( Time.now.to_s.split(//).sort_by {rand}.join )
  243. end
  244.  
  245. def do_delete
  246. self.deleted_at = Time.now.utc
  247. end
  248.  
  249. def do_activate
  250. @activated = true
  251. self.activated_at = Time.now.utc
  252. self.deleted_at = self.activation_code = nil
  253. end
  254. end
Add Comment
Please, Sign In to add comment