Class: Janus::ConfirmationsController

Inherits:
ApplicationController
  • Object
show all
Includes:
InternalHelpers
Defined in:
lib/janus/controllers/confirmations_controller.rb

Overview

This controller is responsible for confirming any user email. It’s also responsible for resending the confirmation email on demand by the user.

Instance Method Summary collapse

Methods included from InternalHelpers

#authenticate!, #janus_scope, #mailer_class, #resource, #resource=, #resource_class, #resource_name

Instance Method Details

#after_confirmation_url(resource) ⇒ Object

Where to redirect when the user has confirmed her account.



79
80
81
# File 'lib/janus/controllers/confirmations_controller.rb', line 79

def after_confirmation_url(resource)
  root_url
end

#after_resending_confirmation_instructions_url(resource) ⇒ Object

Where to redirect after the instructions have been sent.



74
75
76
# File 'lib/janus/controllers/confirmations_controller.rb', line 74

def after_resending_confirmation_instructions_url(resource)
  root_url
end

#createObject



40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
# File 'lib/janus/controllers/confirmations_controller.rb', line 40

def create
  self.resource = resource_class.find_for_database_authentication(params[resource_name])

  if resource
    deliver_confirmation_instructions(resource)

    respond_to do |format|
      format.html do
        redirect_to after_resending_confirmation_instructions_url(resource),
          :notice => t('flash.janus.confirmations.create.email_sent')
      end

      format.any  { head :ok }
    end
  else
    respond_to do |format|
      format.html do
        self.resource = resource_class.new
        resource.errors.add(:base, :not_found)
        render 'new'
      end

      format.any { head :not_found }
    end
  end
end

#deliver_confirmation_instructions(resource) ⇒ Object

Simple wrapper for Mailer#confirmation_instructions.deliver to allow customization of the email (eg: to pass additional data).



69
70
71
# File 'lib/janus/controllers/confirmations_controller.rb', line 69

def deliver_confirmation_instructions(resource)
  mailer_class.confirmation_instructions(resource).deliver
end

#newObject



35
36
37
38
# File 'lib/janus/controllers/confirmations_controller.rb', line 35

def new
  self.resource = resource_class.new
  respond_with(resource)
end

#showObject



8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
# File 'lib/janus/controllers/confirmations_controller.rb', line 8

def show
  self.resource = resource_class.find_for_confirmation(params[resource_class.confirmation_key])

  if resource
    resource.confirm!

    respond_to do |format|
      format.html do
        redirect_to after_confirmation_url(resource),
          :notice => t('flash.janus.confirmations.edit.confirmed')
      end

      format.any { head :ok }
    end
  else
    respond_to do |format|
      format.html do
        self.resource = resource_class.new
        resource.errors.add(:base, :invalid_token)
        render 'new'
      end

      format.any { head :bad_request }
    end
  end
end