Class: Decidim::Initiatives::InitiativeSignaturesController
Instance Method Summary
collapse
#permission_class_chain, #permission_scope, #permissions_context
register_permissions
#check_user_block_status, #check_user_not_blocked
#snippets
#disable_http_caching
#skip_store_location?, #store_current_location
enhance_controller, extended, included
Instance Method Details
#create ⇒ Object
POST /initiatives/:initiative_id/initiative_signatures
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
|
# File 'decidim-initiatives/app/controllers/decidim/initiatives/initiative_signatures_controller.rb', line 36
def create
enforce_permission_to :vote, :initiative, initiative: current_initiative
@form = form(Decidim::Initiatives::VoteForm)
.from_params(
initiative: current_initiative,
signer: current_user
)
VoteInitiative.call(@form) do
on(:ok) do
current_initiative.reload
render :update_buttons_and_counters
end
on(:invalid) do
render :error_on_vote, status: :unprocessable_entity
end
end
end
|
#fill_personal_data ⇒ Object
57
58
59
60
61
62
63
64
65
|
# File 'decidim-initiatives/app/controllers/decidim/initiatives/initiative_signatures_controller.rb', line 57
def fill_personal_data
redirect_to(sms_phone_number_path) && return unless fill_personal_data_step?
@form = form(Decidim::Initiatives::VoteForm)
.from_params(
initiative: current_initiative,
signer: current_user
)
end
|
#finish ⇒ Object
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
|
# File 'decidim-initiatives/app/controllers/decidim/initiatives/initiative_signatures_controller.rb', line 131
def finish
if params.has_key?(:initiatives_vote) || !fill_personal_data_step?
build_vote_form(params)
else
check_session_personal_data
end
VoteInitiative.call(@vote_form) do
on(:ok) do
session[:initiative_vote_form] = {}
end
on(:invalid) do |vote|
logger.fatal "Failed creating signature: #{vote.errors.full_messages.join(", ")}" if vote
flash[:alert] = I18n.t("create.invalid", scope: "decidim.initiatives.initiative_votes")
send(sms_step? ? :sms_code_path : :fill_personal_data_path)
end
end
end
|
#index ⇒ Object
31
32
33
|
# File 'decidim-initiatives/app/controllers/decidim/initiatives/initiative_signatures_controller.rb', line 31
def index
redirect_to send(fill_personal_data_step? ? :fill_personal_data_path : :sms_phone_number_path)
end
|
#sms_code ⇒ Object
106
107
108
109
110
111
112
|
# File 'decidim-initiatives/app/controllers/decidim/initiatives/initiative_signatures_controller.rb', line 106
def sms_code
redirect_to(finish_path) && return unless sms_step?
redirect_to sms_phone_number_path && return if session_sms_code.blank?
@form = Decidim::Verifications::Sms::ConfirmationForm.new
end
|
#sms_phone_number ⇒ Object
82
83
84
85
86
|
# File 'decidim-initiatives/app/controllers/decidim/initiatives/initiative_signatures_controller.rb', line 82
def sms_phone_number
redirect_to(finish_path) && return unless sms_step?
@form = Decidim::Verifications::Sms::MobilePhoneForm.new
end
|
#store_personal_data ⇒ Object
67
68
69
70
71
72
73
74
75
76
77
78
79
80
|
# File 'decidim-initiatives/app/controllers/decidim/initiatives/initiative_signatures_controller.rb', line 67
def store_personal_data
redirect_to(sms_phone_number_path) && return unless fill_personal_data_step?
build_vote_form(params)
if @vote_form.invalid?
flash[:alert] = I18n.t("personal_data.invalid", scope: "decidim.initiatives.initiative_votes")
@form = @vote_form
render :fill_personal_data
else
redirect_to sms_phone_number_path
end
end
|
#store_sms_code ⇒ Object
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
|
# File 'decidim-initiatives/app/controllers/decidim/initiatives/initiative_signatures_controller.rb', line 114
def store_sms_code
redirect_to(finish_path) && return unless sms_step?
@form = Decidim::Verifications::Sms::ConfirmationForm.from_params(params)
ValidateSmsCode.call(@form, session_sms_code) do
on(:ok) do
clear_session_sms_code
redirect_to finish_path
end
on(:invalid) do
flash[:alert] = I18n.t("sms_code.invalid", scope: "decidim.initiatives.initiative_votes")
render :sms_code
end
end
end
|
#store_sms_phone_number ⇒ Object
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
|
# File 'decidim-initiatives/app/controllers/decidim/initiatives/initiative_signatures_controller.rb', line 88
def store_sms_phone_number
redirect_to(finish_path) && return unless sms_step?
@form = Decidim::Verifications::Sms::MobilePhoneForm.from_params(params.merge(user: current_user))
ValidateMobilePhone.call(@form, current_user) do
on(:ok) do |metadata|
store_session_sms_code(metadata)
redirect_to sms_code_path
end
on(:invalid) do
flash[:alert] = I18n.t("sms_phone.invalid", scope: "decidim.initiatives.initiative_votes")
render :sms_phone_number
end
end
end
|