Guest User

Untitled

a guest
Feb 19th, 2018
77
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.42 KB | None | 0 0
  1. ## Routes
  2.  
  3. map.add_person '/add_person', :controller => 'people', :action => 'new_unclaimed_person'
  4. map.add '/add', :controller => 'people', :action => 'create_unclaimed_person'
  5.  
  6.  
  7. ## People Controller
  8.  
  9. def new_unclaimed_person
  10. @person = Person.new
  11. end
  12.  
  13. def create_unclaimed_person
  14. logout_keeping_session!
  15. @person = Person.create(params[:person])
  16. @person.add! if @person && @person.valid?
  17. success = @person && @person.valid?
  18. if success && @person.errors.empty?
  19. redirect_back_or_default('/')
  20. flash[:notice] = "moo"
  21. else
  22. flash[:error] = "moo"
  23. render :action => 'new_unclaimed_person'
  24. end
  25. end
  26.  
  27. ## PersonObserver
  28.  
  29. #so we don't try to send an email to an unclaimed user
  30. def after_create(person)
  31. PersonMailer.deliver_signup_notification(person) if person.email
  32. end
  33.  
  34.  
  35. ## stateful_roles.rb
  36.  
  37. # I think we can put this in the Person model so we don't have to muck with the plugin
  38.  
  39. #setting initial state to passive messes up creating a new real user.
  40. acts_as_state_machine :initial => :passive
  41. state :unclaimed
  42.  
  43. event :add do
  44. transitions :from => :passive, :to => :unclaimed
  45. end
  46.  
  47. # the state can be changed to pending when the user registers fresh or from claiming an existing user => [:passive, :unclaimed]
  48. event :register do
  49. transitions :from => [:passive, :unclaimed], :to => :pending, :guard => Proc.new {|u| !(u.crypted_password.blank? && u.password.blank?) }
  50. end
Add Comment
Please, Sign In to add comment