Class: Decidim::Elections::VoteFlow

Inherits:
Object
  • Object
show all
Defined in:
decidim-elections/app/services/decidim/elections/vote_flow.rb

Overview

Service that encapsulates the vote flow used for elections

Direct Known Subclasses

CurrentUserVoteFlow, Votings::CensusVoteFlow

Defined Under Namespace

Classes: VoteCheckResult

Instance Method Summary collapse

Constructor Details

#initialize(election) ⇒ VoteFlow

Returns a new instance of VoteFlow.


7
8
9
# File 'decidim-elections/app/services/decidim/elections/vote_flow.rb', line 7

def initialize(election)
  @election = election
end

Instance Method Details

#valid_received_data?Boolean

Returns:

  • (Boolean)

34
35
36
# File 'decidim-elections/app/services/decidim/elections/vote_flow.rb', line 34

def valid_received_data?
  valid_token_common_data? && valid_token_flow_data? && valid_voter_id?
end

#voter_from_token(params) ⇒ Object


11
12
13
14
15
16
# File 'decidim-elections/app/services/decidim/elections/vote_flow.rb', line 11

def voter_from_token(params)
  @received_voter_token = params[:voter_token]
  @received_voter_id = params[:voter_id]

  received_voter_token.present? && received_voter_id.present?
end

#voter_idObject


18
19
20
# File 'decidim-elections/app/services/decidim/elections/vote_flow.rb', line 18

def voter_id
  @voter_id ||= calculate_voter_id(voter_token_data)
end

#voter_id_token(a_voter_id = nil) ⇒ Object


22
23
24
# File 'decidim-elections/app/services/decidim/elections/vote_flow.rb', line 22

def voter_id_token(a_voter_id = nil)
  @voter_id_token ||= tokenizer.hex_digest(a_voter_id || voter_id)
end

#voter_tokenObject


26
27
28
29
30
31
32
# File 'decidim-elections/app/services/decidim/elections/vote_flow.rb', line 26

def voter_token
  @voter_token ||= received_voter_token ||
                   message_encryptor.encrypt_and_sign(
                     voter_token_data.to_json,
                     expires_at: Decidim::Elections.voter_token_expiration_minutes.minutes.from_now
                   )
end