Class: Decidim::Verifications::Sms::AuthorizationsController

Inherits:
ApplicationController show all
Includes:
Renewable
Defined in:
decidim-verifications/app/controllers/decidim/verifications/sms/authorizations_controller.rb

Instance Method Summary collapse

Methods inherited from ApplicationController

#renew

Methods included from RegistersPermissions

register_permissions

Methods included from UserBlockedChecker

#check_user_block_status, #check_user_not_blocked

Methods included from NeedsSnippets

#snippets

Methods included from HttpCachingDisabler

#disable_http_caching

Methods included from HasStoredPath

#skip_store_location?, #store_current_location

Methods included from NeedsOrganization

enhance_controller, extended, included

Instance Method Details

#createObject


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

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

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

  PerformAuthorizationStep.call(authorization, @form) do
    on(:ok) do
      flash[:notice] = t("authorizations.create.success", scope: "decidim.verifications.sms")
      authorization_method = Decidim::Verifications::Adapter.from_element(authorization.name)
      redirect_to authorization_method.resume_authorization_path(redirect_url: redirect_url)
    end
    on(:invalid) do
      flash.now[:alert] = t("authorizations.create.error", scope: "decidim.verifications.sms")
      render :new
    end
  end
end

#destroyObject


64
65
66
67
68
69
70
71
# File 'decidim-verifications/app/controllers/decidim/verifications/sms/authorizations_controller.rb', line 64

def destroy
  enforce_permission_to :destroy, :authorization, authorization: authorization

  authorization.destroy!
  flash[:notice] = t("authorizations.destroy.success", scope: "decidim.verifications.sms")

  redirect_to action: :new
end

#editObject


35
36
37
38
39
# File 'decidim-verifications/app/controllers/decidim/verifications/sms/authorizations_controller.rb', line 35

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

  @form = ConfirmationForm.from_params(params)
end

#newObject


11
12
13
14
15
# File 'decidim-verifications/app/controllers/decidim/verifications/sms/authorizations_controller.rb', line 11

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

  @form = MobilePhoneForm.new
end

#updateObject


41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
# File 'decidim-verifications/app/controllers/decidim/verifications/sms/authorizations_controller.rb', line 41

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.sms")

      if redirect_url
        redirect_to redirect_url
      else
        redirect_to decidim_verifications.authorizations_path
      end
    end

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