Class: Decidim::Verifications::ConfirmUserAuthorization

Inherits:
Rectify::Command
  • Object
show all
Defined in:
decidim-verifications/app/commands/decidim/verifications/confirm_user_authorization.rb

Overview

A command to confirm a previous partial authorization.

Constant Summary collapse

MAX_FAILED_ATTEMPTS =

Number of failed confirmation attempts before throttling.

2

Instance Method Summary collapse

Constructor Details

#initialize(authorization, form, session) ⇒ ConfirmUserAuthorization

Public: Initializes the command.

authorization - An Authorization to be confirmed. form - A form object with the verification data to confirm it.


14
15
16
17
18
# File 'decidim-verifications/app/commands/decidim/verifications/confirm_user_authorization.rb', line 14

def initialize(authorization, form, session)
  @authorization = authorization
  @form = form
  @session = session
end

Instance Method Details

#callObject

Executes the command. Broadcasts these events:

  • :ok when everything is valid.

  • :invalid if the handler wasn't valid and we couldn't proceed.

Returns nothing.


26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
# File 'decidim-verifications/app/commands/decidim/verifications/confirm_user_authorization.rb', line 26

def call
  return already_confirmed! if authorization.granted?

  return invalid! unless form.valid?

  throttle! if too_many_failed_attempts?

  if confirmation_successful?
    valid!
  else
    invalid!
  end
rescue StandardError => e
  invalid!(e.message)
end