Class: AuthHelpers::Controller::Recoverable

Inherits:
ApplicationController
  • Object
show all
Includes:
Helpers, InheritedResources::BaseHelpers
Defined in:
lib/auth_helpers/controller/recoverable.rb

Instance Method Summary collapse

Methods included from Helpers

included

Instance Method Details

#create(options = {}, &block) ⇒ Object Also known as: create!

POST /account/password POST /account/password.xml



22
23
24
25
26
27
28
29
30
31
32
33
34
# File 'lib/auth_helpers/controller/recoverable.rb', line 22

def create(options={}, &block)
  object = get_or_set_with_send(:find_and_send_reset_password_instructions, params[self.instance_name])

  if object.errors.empty?
    set_flash_message!(:notice, 'We sent instruction to reset your password, please check your inbox.')
    respond_with_dual_blocks(object, options, true, block) do |format|
      format.html { redirect_to(options[:location] || url_by_name_and_scope(:session)) }
    end
  else
    set_flash_message!(:error)
    respond_with_dual_blocks(object, options, false, block)
  end
end

#edit(&block) ⇒ Object Also known as: edit!



38
39
40
41
42
# File 'lib/auth_helpers/controller/recoverable.rb', line 38

def edit(&block)
  object = get_or_set_with_send(:new)
  object.perishable_token = params[self.instance_name].try(:fetch, :perishable_token)
  respond_with(object, &block)
end

#new(&block) ⇒ Object Also known as: new!

GET /account/password/new



14
15
16
17
# File 'lib/auth_helpers/controller/recoverable.rb', line 14

def new(&block)
  object = get_or_set_with_send(:new)
  respond_with(object, &block)
end

#update(options = {}, &block) ⇒ Object Also known as: update!

PUT /account/password PUT /account/password.xml



47
48
49
50
51
52
53
54
55
56
57
58
59
# File 'lib/auth_helpers/controller/recoverable.rb', line 47

def update(options={}, &block)
  object = get_or_set_with_send(:find_and_reset_password, params[self.instance_name])

  if object.errors.empty?
    set_flash_message!(:notice, 'Your password was successfully reset.')
    respond_with_dual_blocks(object, options, true, block) do |format|
      format.html { redirect_to(options[:location] || url_by_name_and_scope(:session)) }
    end
  else
    set_flash_message!(:error)
    respond_with_dual_blocks(object, options, false, block)
  end
end