Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- ## Routes
- map.add_person '/add_person', :controller => 'people', :action => 'new_unclaimed_person'
- map.add '/add', :controller => 'people', :action => 'create_unclaimed_person'
- ## People Controller
- def new_unclaimed_person
- @person = Person.new
- end
- def create_unclaimed_person
- logout_keeping_session!
- @person = Person.create(params[:person])
- @person.add! if @person && @person.valid?
- success = @person && @person.valid?
- if success && @person.errors.empty?
- redirect_back_or_default('/')
- flash[:notice] = "moo"
- else
- flash[:error] = "moo"
- render :action => 'new_unclaimed_person'
- end
- end
- ## PersonObserver
- #so we don't try to send an email to an unclaimed user
- def after_create(person)
- PersonMailer.deliver_signup_notification(person) if person.email
- end
- ## stateful_roles.rb
- # I think we can put this in the Person model so we don't have to muck with the plugin
- #setting initial state to passive messes up creating a new real user.
- acts_as_state_machine :initial => :passive
- state :unclaimed
- event :add do
- transitions :from => :passive, :to => :unclaimed
- end
- # the state can be changed to pending when the user registers fresh or from claiming an existing user => [:passive, :unclaimed]
- event :register do
- transitions :from => [:passive, :unclaimed], :to => :pending, :guard => Proc.new {|u| !(u.crypted_password.blank? && u.password.blank?) }
- end
Add Comment
Please, Sign In to add comment