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, #resource, #resource=, #resource_class, #resource_name

Instance Method Details

- (Object) create



36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
# File 'lib/janus/controllers/confirmations_controller.rb', line 36

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

  if resource
    JanusMailer.confirmation_instructions(resource).deliver

    respond_to do |format|
      format.html { redirect_to root_url, :notice => t('flash.janus.confirmations.create.email_sent') }
      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

- (Object) new



31
32
33
34
# File 'lib/janus/controllers/confirmations_controller.rb', line 31

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

- (Object) show



8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
# 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 { redirect_to root_url, :notice => t('flash.janus.confirmations.edit.confirmed') }
      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