Class: KirguduBase::Security::AuthenticationsController
Constant Summary
collapse
- DEFAULT_FROM =
"[email protected]"
Instance Attribute Summary
#kirgudu_controller_options
Instance Method Summary
collapse
#add_new_breadcrumb, #authenticate_user, #breadcrumbs_length, #check_locale_parameter, #class_strong_params, #current_user, #current_user=, #current_user_clear_info, #current_user_query_db, #current_user_set_info, #current_user_symbol, #entry_class, #fake_counter_iterate, #get_best_locale, get_class_hierarchy, #get_class_hierarchy, #get_class_variable, #get_filters_for_list, #get_kirgudu_base_authentication_controller_setting, #get_layout_path, get_method_latest_result, #get_template_path, #get_url_for_login, #get_url_for_logout, #get_url_for_restore_password_code, #get_url_to_redirect_for_authentication, #get_view_default_path, #get_view_path, #initialize_global_variables, #kb_breadcrumbs, #page_for_default_redirection_after_login, #prepare_applications_data, #prepare_breadcrumbs, #process_transaction_injections, #render, #render_breadcrumbs, #render_page_e404, #set_content_type, #set_i18n_locale_from_params, #string_logger, #string_logger=, #system_logging_init, #system_logging_write_event, #to_i18n, to_i18n, #to_route_path, to_route_path, to_url_for, #to_url_for, #update_url_with_ajax_referer_url
#get_kb_entry_class, #get_kb_home_controller, #get_kb_home_path, #get_kb_menu, #get_kb_option, #get_kb_page, #get_kb_parent_controller_data, #get_kb_template, #get_kb_view_path, #kb_entry_class, #kb_home_controller, #kb_home_path, #kb_management_settings, #kb_menu, #kb_page, #kb_parent_controller, #kb_template_path, #kb_views_paths_404_page, #kb_views_paths_dashboard, #kb_views_paths_delete, #kb_views_paths_edit, #kb_views_paths_entry_not_found, #kb_views_paths_index, #kb_views_paths_layout, #kb_views_paths_management, #kb_views_paths_new, #kb_views_paths_show, #kb_views_paths_sorting
#get_kb_transaction_injections, #kb_transaction_injection
#get_kb_obligatory_filters, #kb_obligatory_filter
assign_portal_to_all_models, assign_portal_to_models_of_class, #build_query_string_params, #get_flash_message, #kb_auth_form_for, #kb_dynamic_form_for, #kirgudu_form_for, #print_flash_message, #print_flash_notice, #print_property, #render_html, #render_html1, #render_json, #render_json_access_denied, #render_json_error, #render_json_need_authentication, #render_json_not_found, #render_json_ok, #render_json_page_404, #render_liquid, #render_redirect, #russian_month_labels, #security_login, #security_logout, #web_chu_form_for
included
Methods included from UrlHelper
#url_for, #with_subdomain
Instance Method Details
#confirm_email ⇒ Object
343
344
345
|
# File 'app/controllers/kirgudu_base/security/authentications_controller.rb', line 343
def confirm_email
end
|
#confirm_email_process ⇒ Object
347
348
349
|
# File 'app/controllers/kirgudu_base/security/authentications_controller.rb', line 347
def confirm_email_process
end
|
#create ⇒ Object
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
|
# File 'app/controllers/kirgudu_base/security/authentications_controller.rb', line 86
def create
end
|
#destroy ⇒ Object
351
352
353
|
# File 'app/controllers/kirgudu_base/security/authentications_controller.rb', line 351
def destroy
end
|
#destroy_process ⇒ Object
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
|
# File 'app/controllers/kirgudu_base/security/authentications_controller.rb', line 355
def destroy_process
@local_data[:user] = ::KirguduBase::Security::User.where(id: session[self.current_user_symbol])
if @local_data[:user]
if @local_data[:user].destroy
flash[:notice] = "Successfully destroyed authentication."
redirect_to authentications_url
else
end
else
end
end
|
#direct_login ⇒ Object
72
73
74
75
76
77
|
# File 'app/controllers/kirgudu_base/security/authentications_controller.rb', line 72
def direct_login
@local_data[:app_id] = params[:app_id]
@local_data[:email] = params[:email]
@local_data[:password] = params[:password]
end
|
#login ⇒ Object
18
19
20
21
22
23
24
25
26
27
28
29
30
|
# File 'app/controllers/kirgudu_base/security/authentications_controller.rb', line 18
def login
params_to_local_data = [:email, :password, :token_id, :redirect_to]
params_to_local_data.each do |param_name|
@local_data[param_name] = params[param_name] if params[param_name]
end
session[:redirect_to] = params[:redirect_to] if params[:redirect_to]
render "/#{@local_data[:template]}/authentications/login", locals: {data: @local_data}, layout: "/#{@local_data[:template]}/layouts/application"
end
|
#login_process ⇒ Object
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
|
# File 'app/controllers/kirgudu_base/security/authentications_controller.rb', line 32
def login_process
@local_data[:user] = ::KirguduBase::Security::User.where(email: params[:email]).first
params_to_local_data = [:email, :password, :token_id, :redirect_to]
params_to_local_data.each do |param_name|
@local_data[param_name] = params[param_name] if params[param_name]
end
process_result = false
if @local_data[:user] && @local_data[:user].password == ::ChupakabraTools::Security.get_password_hash(params[:password])
self.current_user_set_info(@local_data[:user], params[:remember_me])
process_result = true
else
@local_data[:errors] << I18n.t("kirgudu_base.authentications.login.errors.generic_user_password")
end
unless verify_recaptcha
@local_data[:errors] << I18n.t("kirgudu_base.authentications.login.errors.captcha_error")
process_result = false
end
if process_result
redirect_to session[:return_to] || ::KirguduBase.url_for_default_redirection_after_login || "/"
else
render "/#{@local_data[:template]}/authentications/login", locals: {data: @local_data}, layout: "#{@local_data[:template]}/layouts/application"
end
end
|
#logout ⇒ Object
79
80
81
82
83
84
|
# File 'app/controllers/kirgudu_base/security/authentications_controller.rb', line 79
def logout
security_logout(session)
self.current_user_clear_info
redirect_to self.get_url_for_login
end
|
#one_time_pass_login ⇒ Object
65
66
67
|
# File 'app/controllers/kirgudu_base/security/authentications_controller.rb', line 65
def one_time_pass_login
render "/#{@local_data[:template]}/authentications/token_login", locals: {data: @local_data}, layout: "#{@local_data[:template]}/layouts/application"
end
|
#one_time_pass_login_process ⇒ Object
69
70
|
# File 'app/controllers/kirgudu_base/security/authentications_controller.rb', line 69
def one_time_pass_login_process
end
|
#register ⇒ Object
144
145
146
147
148
149
150
151
152
153
154
155
156
|
# File 'app/controllers/kirgudu_base/security/authentications_controller.rb', line 144
def register
@local_data[:user] = ::KirguduBase::Security::User.new
params_to_local_data = [:token_id, :redirect_to]
params_to_local_data.each do |param_name|
@local_data[param_name] = params[param_name] if params[param_name]
end
session[:token_id] = params[:token_id] if params[:token_id]
session[:redirect_to] = params[:redirect_to] if params[:redirect_to]
render "/#{@local_data[:template]}/authentications/register", locals: {data: @local_data}, layout: "#{@local_data[:template]}/layouts/application"
end
|
#register_process ⇒ Object
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
|
# File 'app/controllers/kirgudu_base/security/authentications_controller.rb', line 158
def register_process
params_user = params[::KirguduBase::Security::User.for_form_params]
@local_data[:user] = ::KirguduBase::Security::User.new(self.strong_params_on_create)
params_to_local_data = [:token_id, :redirect_to]
params_to_local_data.each do |param_name|
@local_data[param_name] = params[param_name] if params[param_name]
end
@local_data[:user].email = params_user[:email]
@local_data[:user].password = params_user[:password]
@local_data[:user].password_confirmation = params_user[:password_confirmation]
@local_data[:user].uin ||= ::SecureRandom.uuid
@local_data[:user].created_at = DateTime.now
@local_data[:user].updated_at = DateTime.now
user_plain_text_password = @local_data[:user].password
user_plain_text_password_confirmation = @local_data[:user].password_confirmation
process_result = false
captcha_is_ok = verify_recaptcha
unless captcha_is_ok
@local_data[:errors] << I18n.t("kirgudu_base.authentications.register.errors.captcha_error")
process_result = false
end
if captcha_is_ok
if @local_data[:user].valid?
ActiveRecord::Base.transaction do
@local_data[:user].password = ::ChupakabraTools::Security.get_password_hash(@local_data[:user].password)
@local_data[:user].password_confirmation = @local_data[:user].password
if @local_data[:user].save
@local_data[:messages] << I18n.t("kirgudu_base.authentications.register.messages.user_created")
process_result = true
else
@local_data[:errors] << I18n.t("kirgudu_base.authentications.register.errors.failed_to_save_user")
end
end
end
end
if process_result
render "/#{@local_data[:template]}/authentications/register_successful", locals: {data: @local_data}
else
@local_data[:user].password = user_plain_text_password
@local_data[:user].password_confirmation = user_plain_text_password_confirmation
render "/#{@local_data[:template]}/authentications/register", locals: {data: @local_data}, layout: "#{@local_data[:template]}/layouts/application"
end
end
|
#restore_password ⇒ Object
216
217
218
219
220
221
222
223
|
# File 'app/controllers/kirgudu_base/security/authentications_controller.rb', line 216
def restore_password
params_to_local_data = [:token_id, :redirect_to, :email]
params_to_local_data.each do |param_name|
@local_data[param_name] = params[param_name] if params[param_name]
end
render "#{@local_data[:template]}/authentications/restore_password", locals: {data: @local_data}, layout: "#{@local_data[:template]}/layouts/application"
end
|
#restore_password_code ⇒ Object
279
280
281
282
283
284
285
286
|
# File 'app/controllers/kirgudu_base/security/authentications_controller.rb', line 279
def restore_password_code
params_to_local_data = [:token_id, :redirect_to, :email, :id, :code]
params_to_local_data.each do |param_name|
@local_data[param_name] = params[param_name] if params[param_name]
end
render "/#{@local_data[:template]}/authentications/restore_password_code", locals: {data: @local_data}, layout: "#{@local_data[:template]}/layouts/application"
end
|
#restore_password_code_process ⇒ Object
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
|
# File 'app/controllers/kirgudu_base/security/authentications_controller.rb', line 288
def restore_password_code_process
params_to_local_data = [:token_id, :redirect_to, :email, :id, :code]
params_to_local_data.each do |param_name|
@local_data[param_name] = params[param_name] if params[param_name]
end
restore_code = nil
restore_code = ::KirguduBase::Security::RestorePasswordCode.find(@local_data[:id]) if @local_data[:id]
process_result = false
if restore_code && restore_code.code == @local_data[:code]
unless restore_code.is_used?
password = ::ChupakabraTools::Security.generate_secret(length: 8)
restore_code.user.password = ::ChupakabraTools::Security.get_password_hash(password)
if restore_code.user.save
begin
::KirguduBase::AuthenticationsMailer.restore_password_success(DEFAULT_FROM, restore_code.user.email, restore_code.user, password).deliver!
@local_data[:email] = restore_code.user.email
process_result = true
restore_code.is_used = true
restore_code.save
rescue Exception => e
@local_data[:errors] << I18n.t("kirgudu_base.authentications.restore_password_code.errors.failed_to_send_password")
end
else
@local_data[:errors] << I18n.t("kirgudu_base.authentications.restore_password_code.errors.failed_to_save_password")
end
else
@local_data[:errors] << I18n.t("kirgudu_base.authentications.restore_password_code.errors.used_code")
end
else
@local_data[:errors] << I18n.t("kirgudu_base.authentications.restore_password_code.errors.wrong_code")
process_result = false
end
if process_result
redirect_to ::KirguduBase.authentications_controller.to_url_for(:restore_password_success, email: @local_data[:email])
else
render "/#{@local_data[:template]}/authentications/restore_password_code", locals: {data: @local_data}
end
end
|
#restore_password_send ⇒ Object
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
|
# File 'app/controllers/kirgudu_base/security/authentications_controller.rb', line 225
def restore_password_send
params_to_local_data = [:token_id, :redirect_to, :email]
params_to_local_data.each do |param_name|
@local_data[param_name] = params[param_name] if params[param_name]
end
process_result = false
if verify_recaptcha
if @local_data[:email] && !@local_data[:email].blank?
if @local_data[:email]
user = ::KirguduBase::Security::User.get_by_email(@local_data[:email])
if user
restore = ::KirguduBase::Security::RestorePasswordCode.where { (expire_at > Time.now) & (is_used == false) }.order(::KirguduBase::Security::RestorePasswordCode.for_sql_order_by(:created_at, :desc)).first
unless restore
restore = ::KirguduBase::Security::RestorePasswordCode.new(expire_at: 30.minute.from_now, code: 100000 + SecureRandom.random_number(899999), user_id: user.id)
unless restore.save
restore = nil
@local_data[:errors] << I18n.t("kirgudu_base.authentications.restore_password.errors.cant_create_restore_code")
end
end
if restore
begin
::KirguduBase::AuthenticationsMailer.restore_password_code(DEFAULT_FROM, user.email, user, restore).deliver!
process_result = true
restore.sent_at = Time.now
restore.save
rescue Exception => e
@local_data[:errors] << I18n.t("kirgudu_base.authentications.restore_password.errors.mail_delivery_error")
end
end
else
@local_data[:errors] << I18n.t("kirgudu_base.authentications.restore_password.errors.user_not_found")
end
else
@local_data[:errors] << I18n.t("kirgudu_base.authentications.restore_password.errors.email_wrong_format")
end
else
@local_data[:errors] << I18n.t("kirgudu_base.authentications.restore_password.errors.email_cannot_be_empty")
end
else
@local_data[:errors] << I18n.t("kirgudu_base.authentications.restore_password.errors.captcha_error")
end
if process_result
redirect_to self.get_url_for_restore_password_code(email: user.email)
else
render "/#{@local_data[:template]}/authentications/restore_password", locals: {data: @local_data}, layout: "#{@local_data[:template]}/layouts/application"
end
end
|
#restore_password_success ⇒ Object
332
333
334
335
336
337
338
339
340
|
# File 'app/controllers/kirgudu_base/security/authentications_controller.rb', line 332
def restore_password_success
params_to_local_data = [:token_id, :redirect_to, :email, :id, :code]
params_to_local_data.each do |param_name|
@local_data[param_name] = params[param_name] if params[param_name]
end
render "/#{@local_data[:template]}/authentications/restore_password_success", locals: {data: @local_data}
end
|