Class: Decidim::Verifications::PostalLetter::AuthorizationsController

Inherits:
ApplicationController
  • Object
show all
Includes:
Renewable
Defined in:
app/controllers/decidim/verifications/postal_letter/authorizations_controller.rb

Instance Method Summary collapse

Methods inherited from ApplicationController

#renew

Instance Method Details

#createObject



19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
# File 'app/controllers/decidim/verifications/postal_letter/authorizations_controller.rb', line 19

def create
  enforce_permission_to :create, :authorization, authorization: @authorization

  @form = AddressForm.from_params(params.merge(user: current_user))

  PerformAuthorizationStep.call(@authorization, @form) do
    on(:ok) do
      flash[:notice] = t("authorizations.create.success", scope: "decidim.verifications.postal_letter")
      redirect_to decidim_verifications.authorizations_path
    end

    on(:invalid) do
      flash.now[:alert] = t("authorizations.create.error", scope: "decidim.verifications.postal_letter")
      render :new
    end
  end
end

#editObject



37
38
39
40
41
# File 'app/controllers/decidim/verifications/postal_letter/authorizations_controller.rb', line 37

def edit
  enforce_permission_to :update, :authorization, authorization: @authorization

  @form = ConfirmationForm.from_params(params)
end

#newObject



13
14
15
16
17
# File 'app/controllers/decidim/verifications/postal_letter/authorizations_controller.rb', line 13

def new
  enforce_permission_to :create, :authorization, authorization: @authorization

  @form = AddressForm.new
end

#updateObject



43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
# File 'app/controllers/decidim/verifications/postal_letter/authorizations_controller.rb', line 43

def update
  enforce_permission_to :update, :authorization, authorization: @authorization

  @form = ConfirmationForm.from_params(params)

  ConfirmUserAuthorization.call(@authorization, @form, session) do
    on(:ok) do
      flash[:notice] = t("authorizations.update.success", scope: "decidim.verifications.postal_letter")
      redirect_to decidim_verifications.authorizations_path
    end

    on(:invalid) do
      flash.now[:alert] = t("authorizations.update.error", scope: "decidim.verifications.postal_letter")
      render :edit
    end
  end
end