Created
September 2, 2009 13:53
-
-
Save kirel/179723 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| module Zweitag | |
| # following migration needed | |
| # | |
| # class AddResetCodeToUser < ActiveRecord::Migration | |
| # def self.up | |
| # add_column :users, :reset_code, :string | |
| # end | |
| # | |
| # def self.down | |
| # remove_column :users, :reset_code | |
| # end | |
| # end | |
| # | |
| module RestfulAuthenticationResetPassword | |
| def self.included( recipient ) | |
| recipient.extend( RestfulAuthenticationResetPasswordClassMethods ) | |
| recipient.class_eval do | |
| include RestfulAuthenticationResetPasswordInstanceMethods | |
| aasm_state :reset_pending, :enter => :make_reset_code, :exit => :do_reset | |
| aasm_event :request_reset do | |
| transitions :from => [:passive, :pending, :active], :to => :reset_pending | |
| end | |
| aasm_event :reset do | |
| transitions :from => :reset_pending, :to => :active, :guard => Proc.new {|u| !u.activated_at.blank? } | |
| transitions :from => :reset_pending, :to => :pending, :guard => Proc.new {|u| !u.activation_code.blank? } | |
| transitions :from => :reset_pending, :to => :passive | |
| end | |
| end | |
| end | |
| module RestfulAuthenticationResetPasswordClassMethods | |
| end # class methods | |
| module RestfulAuthenticationResetPasswordInstanceMethods | |
| # Returns true if the user has just been activated. | |
| def recently_reset? | |
| @reset | |
| end | |
| def do_reset | |
| self.reset_code = nil | |
| end | |
| def make_reset_code | |
| self.reset_code = self.class.make_token | |
| @reset = true | |
| end | |
| end # instance methods | |
| end | |
| end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment