Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save talyric/316219 to your computer and use it in GitHub Desktop.
Save talyric/316219 to your computer and use it in GitHub Desktop.
lifecycle do
state :unverified, :default => true
state :verified,:active, :inactive, :banned
create :signup, :available_to => "Guest",
:params => [:name, :real_name, :birthday, :email_address, :password, :password_confirmation],
:become => :unverified, :new_key => true do
if self.birthday.to_time < 18.years.ago
UserMailer.deliver_email_verification(self, lifecycle.key)
else
UserMailer.deliver_email(self,"Account Request","We're sorry, but you must be over 18 to signup for an account.")
end
end
transition :verify_email_address, { :unverified => :verified }, :available_to => :key_holder do
UserMailer.deliver_email(self,"Email address verified","Your email address has been verified.")
end
transition :accept_terms, { :verified => :active }, :available_to => :user_account do
UserMailer.deliver_email(self,"Terms accepted","Now that you've accepted the terms of use, you can start submitting content.")
end
transition :deactivate, { [:verified,:active] => :inactive }, :available_to => :user_account do
UserMailer.deliver_email(self,"Account deactivated","At your request, your account has been deactivated.")
end
transition :activate, { :inactive => :verified }, :available_to => :user_account do
UserMailer.deliver_email(self,"Account reactivated","At your request, your account has been reactivated.")
end
transition :ban, { [:verified, :unverified, :active, :inactive] => :banned },
:available_to => User.administrators do
UserMailer.deliver_email(self,"Account Banned","Due to violations, your account has been banned.")
end
transition :request_password_reset, { :active => :active }, :new_key => true do
UserMailer.deliver_forgot_password(self, lifecycle.key)
end
transition :reset_password, { :active => :active }, :available_to => :key_holder,
:params => [ :password, :password_confirmation ]
transition :change_email, { [:active, :inactive, :verified] => :unverified },
:available_to => :user_account,
:params => [ :email_address ], :new_key => true do
UserMailer.deliver_email_verification(self, lifecycle.key)
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment