kirgudu_base 0.0.23 → 0.0.25
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/app/controllers/kirgudu_base/application_controller.rb +775 -766
- data/app/controllers/kirgudu_base/security/authentications_controller.rb +389 -390
- data/app/views/kirgudu_base/admin/medialoot/layouts/application.html.erb +3 -3
- data/app/views/kirgudu_base/admin/zapanel/layouts/application.html.erb +11 -1
- metadata +2 -2
@@ -1,414 +1,413 @@
|
|
1
1
|
# -*- encoding : utf-8 -*-
|
2
2
|
|
3
3
|
module KirguduBase
|
4
|
-
|
5
|
-
|
4
|
+
module Security
|
5
|
+
class AuthenticationsController < ::KirguduBase::ApplicationController
|
6
6
|
|
7
7
|
|
8
|
-
|
8
|
+
before_action :redirect_if_loggedin
|
9
9
|
|
10
|
-
|
10
|
+
before_action :init_authentications_variables
|
11
11
|
|
12
|
-
|
13
|
-
|
12
|
+
before_action :on_before_login, only: :login
|
13
|
+
after_action :on_after_login, only: :login
|
14
14
|
|
15
|
-
|
15
|
+
DEFAULT_FROM = "kirgudu.net@gmail.com"
|
16
16
|
|
17
17
|
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
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
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
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
|
-
|
143
|
-
|
144
|
-
|
145
|
-
|
146
|
-
|
147
|
-
|
148
|
-
|
149
|
-
|
150
|
-
|
151
|
-
|
152
|
-
|
153
|
-
|
154
|
-
|
155
|
-
|
156
|
-
|
157
|
-
|
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
|
-
|
215
|
-
|
216
|
-
|
217
|
-
|
218
|
-
|
219
|
-
|
220
|
-
|
221
|
-
|
222
|
-
|
223
|
-
|
224
|
-
|
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
|
-
|
278
|
-
|
279
|
-
|
280
|
-
|
281
|
-
|
282
|
-
|
283
|
-
|
284
|
-
|
285
|
-
|
286
|
-
|
287
|
-
|
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
|
-
|
331
|
-
|
332
|
-
|
333
|
-
|
334
|
-
|
335
|
-
|
336
|
-
|
337
|
-
|
338
|
-
|
339
|
-
|
340
|
-
|
341
|
-
|
342
|
-
|
343
|
-
|
344
|
-
|
345
|
-
|
346
|
-
|
347
|
-
|
348
|
-
|
349
|
-
|
350
|
-
|
351
|
-
|
352
|
-
|
353
|
-
|
354
|
-
|
355
|
-
|
356
|
-
|
357
|
-
|
358
|
-
|
359
|
-
|
360
|
-
|
361
|
-
|
362
|
-
|
363
|
-
|
364
|
-
|
365
|
-
|
366
|
-
|
367
|
-
else
|
18
|
+
def login
|
19
|
+
params_to_local_data = [:email, :password, :token_id, :redirect_to]
|
20
|
+
params_to_local_data.each do |param_name|
|
21
|
+
@local_data[param_name] = params[param_name] if params[param_name]
|
22
|
+
end
|
23
|
+
|
24
|
+
session[:redirect_to] = params[:redirect_to] if params[:redirect_to]
|
25
|
+
|
26
|
+
#logger.info("AUTH CONTROLLER TEMPLATE: #{@local_data[:template]}")
|
27
|
+
#logger.info("LOGIN VIEW PATH: #{@local_data[:template]}/authentications/login")
|
28
|
+
|
29
|
+
render "/#{@local_data[:template]}/authentications/login", locals: {data: @local_data}, layout: "/#{@local_data[:template]}/layouts/application"
|
30
|
+
end
|
31
|
+
|
32
|
+
def login_process
|
33
|
+
|
34
|
+
@local_data[:user] = ::KirguduBase::Security::User.where(email: params[:email]).first
|
35
|
+
|
36
|
+
params_to_local_data = [:email, :password, :token_id, :redirect_to]
|
37
|
+
params_to_local_data.each do |param_name|
|
38
|
+
@local_data[param_name] = params[param_name] if params[param_name]
|
39
|
+
end
|
40
|
+
|
41
|
+
process_result = false
|
42
|
+
|
43
|
+
|
44
|
+
if @local_data[:user] && @local_data[:user].password == ::ChupakabraTools::Security.get_password_hash(params[:password])
|
45
|
+
self.current_user_set_info(@local_data[:user], params[:remember_me])
|
46
|
+
process_result = true
|
47
|
+
|
48
|
+
else
|
49
|
+
@local_data[:errors] << I18n.t("kirgudu_base.authentications.login.errors.generic_user_password")
|
50
|
+
end
|
51
|
+
unless verify_recaptcha
|
52
|
+
@local_data[:errors] << I18n.t("kirgudu_base.authentications.login.errors.captcha_error")
|
53
|
+
process_result = false
|
54
|
+
end
|
55
|
+
|
56
|
+
|
57
|
+
if process_result
|
58
|
+
redirect_to session[:return_to] || ::KirguduBase.url_for_default_redirection_after_login || "/"
|
59
|
+
else
|
60
|
+
render "/#{@local_data[:template]}/authentications/login", locals: {data: @local_data}, layout: "#{@local_data[:template]}/layouts/application"
|
61
|
+
end
|
62
|
+
end
|
63
|
+
|
64
|
+
|
65
|
+
def one_time_pass_login
|
66
|
+
render "/#{@local_data[:template]}/authentications/token_login", locals: {data: @local_data}, layout: "#{@local_data[:template]}/layouts/application"
|
67
|
+
end
|
68
|
+
|
69
|
+
def one_time_pass_login_process
|
70
|
+
end
|
71
|
+
|
72
|
+
def direct_login
|
73
|
+
@local_data[:app_id] = params[:app_id]
|
74
|
+
@local_data[:email] = params[:email]
|
75
|
+
@local_data[:password] = params[:password]
|
76
|
+
|
77
|
+
end
|
78
|
+
|
79
|
+
def logout
|
80
|
+
security_logout(session)
|
81
|
+
|
82
|
+
self.current_user_clear_info
|
83
|
+
redirect_to self.get_url_for_login
|
84
|
+
end
|
85
|
+
|
86
|
+
def create
|
87
|
+
|
88
|
+
# omniauth = request.env["omniauth.auth"]
|
89
|
+
# # Checking if External Authentication Services Allowed
|
90
|
+
# external_authentication_allowed = Option.where(name: 'external_authentication_allowed').first
|
91
|
+
#
|
92
|
+
# if !external_authentication_allowed.nil? && external_authentication_allowed == false
|
93
|
+
# flash[:error] = "External Authentication Services are prohibited. Pleas Login with Your Local Account"
|
94
|
+
# redirect_to ::KirguduBase::Security::AuthenticationsController.to_url_for(action: :login)
|
95
|
+
# return
|
96
|
+
# end
|
97
|
+
#
|
98
|
+
# authentication = ::KirguduBase::Security::Authentication.find_by_provider_and_uid(omniauth['provider'], omniauth['uid'])
|
99
|
+
# if authentication
|
100
|
+
# flash[:notice] = "Signed in successfully."
|
101
|
+
# session[:user_id] = authentication.user.id
|
102
|
+
# session[:user_provider] = authentication.provider
|
103
|
+
# #sign_in_and_redirect(:user, authentication.user)
|
104
|
+
# #redirect_to home_path
|
105
|
+
# return
|
106
|
+
# elsif @current_website
|
107
|
+
# authentication = @current_website.authentications.create!(
|
108
|
+
# provider: omniauth['provider'],
|
109
|
+
# uid: omniauth['uid']
|
110
|
+
# )
|
111
|
+
# session[:user_provider] = authentication.provider
|
112
|
+
# flash[:notice] = "Authentication successful."
|
113
|
+
# #redirect_to home_path
|
114
|
+
# return
|
115
|
+
# else
|
116
|
+
# user_params = {
|
117
|
+
# first_name: omniauth.info.first_name || "",
|
118
|
+
# last_name: omniauth.info.last_name || "",
|
119
|
+
# email: omniauth.info.email,
|
120
|
+
# #phone: "",
|
121
|
+
# password: ::ChupakabraTools::Security.generate_secret(length: 10)
|
122
|
+
# }
|
123
|
+
#
|
124
|
+
# @local_data[:user] = ::KirguduBase::Security::User.new(user_params)
|
125
|
+
#
|
126
|
+
# if @local_data[:user].save
|
127
|
+
# authentication = @local_data[:user].authentications.create!(
|
128
|
+
# provider: omniauth['provider'],
|
129
|
+
# uid: omniauth['uid']
|
130
|
+
# )
|
131
|
+
# session[:user_provider] = authentication.provider
|
132
|
+
# flash[:notice] = "Signed in successfully."
|
133
|
+
# session[:user_id] = @local_data[:user].id
|
134
|
+
# #redirect_to home_path
|
135
|
+
# return
|
136
|
+
# else
|
137
|
+
# #session[:omniauth] = omniauth.except('extra')
|
138
|
+
# redirect_to url_for(controller: ::KirguduBase::Security::AuthenticationsController.to_route_path, action: :register)
|
139
|
+
# return
|
140
|
+
# end
|
141
|
+
# end
|
142
|
+
end
|
143
|
+
|
144
|
+
def register
|
145
|
+
@local_data[:user] = ::KirguduBase::Security::User.new
|
146
|
+
|
147
|
+
params_to_local_data = [:token_id, :redirect_to]
|
148
|
+
params_to_local_data.each do |param_name|
|
149
|
+
@local_data[param_name] = params[param_name] if params[param_name]
|
150
|
+
end
|
151
|
+
session[:token_id] = params[:token_id] if params[:token_id]
|
152
|
+
session[:redirect_to] = params[:redirect_to] if params[:redirect_to]
|
153
|
+
|
154
|
+
|
155
|
+
render "/#{@local_data[:template]}/authentications/register", locals: {data: @local_data}, layout: "#{@local_data[:template]}/layouts/application"
|
156
|
+
end
|
157
|
+
|
158
|
+
def register_process
|
159
|
+
|
160
|
+
params_user = params[::KirguduBase::Security::User.for_form_params]
|
161
|
+
@local_data[:user] = ::KirguduBase::Security::User.new(self.strong_params_on_create)
|
162
|
+
|
163
|
+
|
164
|
+
params_to_local_data = [:token_id, :redirect_to]
|
165
|
+
params_to_local_data.each do |param_name|
|
166
|
+
@local_data[param_name] = params[param_name] if params[param_name]
|
167
|
+
end
|
168
|
+
|
169
|
+
|
170
|
+
@local_data[:user].email = params_user[:email]
|
171
|
+
@local_data[:user].password = params_user[:password]
|
172
|
+
@local_data[:user].password_confirmation = params_user[:password_confirmation]
|
173
|
+
@local_data[:user].uin ||= ::SecureRandom.uuid
|
174
|
+
@local_data[:user].created_at = DateTime.now
|
175
|
+
@local_data[:user].updated_at = DateTime.now
|
176
|
+
|
177
|
+
|
178
|
+
user_plain_text_password = @local_data[:user].password
|
179
|
+
user_plain_text_password_confirmation = @local_data[:user].password_confirmation
|
180
|
+
|
181
|
+
process_result = false
|
182
|
+
captcha_is_ok = verify_recaptcha
|
183
|
+
|
184
|
+
unless captcha_is_ok
|
185
|
+
@local_data[:errors] << I18n.t("kirgudu_base.authentications.register.errors.captcha_error")
|
186
|
+
process_result = false
|
187
|
+
end
|
188
|
+
if captcha_is_ok
|
189
|
+
if @local_data[:user].valid?
|
190
|
+
# starting transaction
|
191
|
+
ActiveRecord::Base.transaction do
|
192
|
+
@local_data[:user].password = ::ChupakabraTools::Security.get_password_hash(@local_data[:user].password)
|
193
|
+
@local_data[:user].password_confirmation = @local_data[:user].password
|
194
|
+
|
195
|
+
if @local_data[:user].save
|
196
|
+
@local_data[:messages] << I18n.t("kirgudu_base.authentications.register.messages.user_created")
|
197
|
+
process_result = true
|
198
|
+
else
|
199
|
+
@local_data[:errors] << I18n.t("kirgudu_base.authentications.register.errors.failed_to_save_user")
|
200
|
+
end
|
201
|
+
end
|
202
|
+
|
203
|
+
end
|
204
|
+
end
|
205
|
+
|
206
|
+
|
207
|
+
if process_result
|
208
|
+
render "/#{@local_data[:template]}/authentications/register_successful", locals: {data: @local_data}
|
209
|
+
else
|
210
|
+
@local_data[:user].password = user_plain_text_password
|
211
|
+
@local_data[:user].password_confirmation = user_plain_text_password_confirmation
|
212
|
+
render "/#{@local_data[:template]}/authentications/register", locals: {data: @local_data}, layout: "#{@local_data[:template]}/layouts/application"
|
213
|
+
end
|
214
|
+
end
|
215
|
+
|
216
|
+
def restore_password
|
217
|
+
|
218
|
+
params_to_local_data = [:token_id, :redirect_to, :email]
|
219
|
+
params_to_local_data.each do |param_name|
|
220
|
+
@local_data[param_name] = params[param_name] if params[param_name]
|
221
|
+
end
|
222
|
+
render "#{@local_data[:template]}/authentications/restore_password", locals: {data: @local_data}, layout: "#{@local_data[:template]}/layouts/application"
|
223
|
+
end
|
224
|
+
|
225
|
+
def restore_password_send
|
226
|
+
params_to_local_data = [:token_id, :redirect_to, :email]
|
227
|
+
params_to_local_data.each do |param_name|
|
228
|
+
@local_data[param_name] = params[param_name] if params[param_name]
|
229
|
+
end
|
230
|
+
|
231
|
+
process_result = false
|
232
|
+
|
233
|
+
if verify_recaptcha
|
234
|
+
if @local_data[:email] && !@local_data[:email].blank?
|
235
|
+
if @local_data[:email]
|
236
|
+
user = ::KirguduBase::Security::User.get_by_email(@local_data[:email])
|
237
|
+
if user
|
238
|
+
restore = ::KirguduBase::Security::RestorePasswordCode.where { (expire_at > Time.now) & (is_used == false) }.order(::KirguduBase::Security::RestorePasswordCode.for_sql_order_by(:created_at, :desc)).first
|
239
|
+
unless restore
|
240
|
+
restore = ::KirguduBase::Security::RestorePasswordCode.new(expire_at: 30.minute.from_now, code: 100000 + SecureRandom.random_number(899999), user_id: user.id)
|
241
|
+
unless restore.save
|
242
|
+
restore = nil
|
243
|
+
@local_data[:errors] << I18n.t("kirgudu_base.authentications.restore_password.errors.cant_create_restore_code")
|
244
|
+
end
|
245
|
+
end
|
246
|
+
if restore
|
247
|
+
begin
|
248
|
+
::KirguduBase::AuthenticationsMailer.restore_password_code(DEFAULT_FROM, user.email, user, restore).deliver!
|
249
|
+
process_result = true
|
250
|
+
restore.sent_at = Time.now
|
251
|
+
restore.save
|
252
|
+
rescue Exception => e
|
253
|
+
@local_data[:errors] << I18n.t("kirgudu_base.authentications.restore_password.errors.mail_delivery_error")
|
254
|
+
end
|
255
|
+
|
256
|
+
end
|
257
|
+
else
|
258
|
+
@local_data[:errors] << I18n.t("kirgudu_base.authentications.restore_password.errors.user_not_found")
|
259
|
+
end
|
260
|
+
else
|
261
|
+
@local_data[:errors] << I18n.t("kirgudu_base.authentications.restore_password.errors.email_wrong_format")
|
262
|
+
end
|
263
|
+
else
|
264
|
+
@local_data[:errors] << I18n.t("kirgudu_base.authentications.restore_password.errors.email_cannot_be_empty")
|
265
|
+
end
|
266
|
+
else
|
267
|
+
@local_data[:errors] << I18n.t("kirgudu_base.authentications.restore_password.errors.captcha_error")
|
268
|
+
end
|
269
|
+
|
270
|
+
|
271
|
+
if process_result
|
272
|
+
redirect_to self.get_url_for_restore_password_code(email: user.email)
|
273
|
+
else
|
274
|
+
render "/#{@local_data[:template]}/authentications/restore_password", locals: {data: @local_data}, layout: "#{@local_data[:template]}/layouts/application"
|
275
|
+
end
|
276
|
+
|
277
|
+
end
|
278
|
+
|
279
|
+
def restore_password_code
|
280
|
+
|
281
|
+
params_to_local_data = [:token_id, :redirect_to, :email, :id, :code]
|
282
|
+
params_to_local_data.each do |param_name|
|
283
|
+
@local_data[param_name] = params[param_name] if params[param_name]
|
284
|
+
end
|
285
|
+
render "/#{@local_data[:template]}/authentications/restore_password_code", locals: {data: @local_data}, layout: "#{@local_data[:template]}/layouts/application"
|
286
|
+
end
|
287
|
+
|
288
|
+
def restore_password_code_process
|
289
|
+
|
290
|
+
params_to_local_data = [:token_id, :redirect_to, :email, :id, :code]
|
291
|
+
params_to_local_data.each do |param_name|
|
292
|
+
@local_data[param_name] = params[param_name] if params[param_name]
|
293
|
+
end
|
294
|
+
|
295
|
+
restore_code = nil
|
296
|
+
restore_code = ::KirguduBase::Security::RestorePasswordCode.find(@local_data[:id]) if @local_data[:id]
|
297
|
+
|
298
|
+
process_result = false
|
299
|
+
if restore_code && restore_code.code == @local_data[:code]
|
300
|
+
unless restore_code.is_used?
|
301
|
+
password = ::ChupakabraTools::Security.generate_secret(length: 8)
|
302
|
+
restore_code.user.password = ::ChupakabraTools::Security.get_password_hash(password)
|
303
|
+
if restore_code.user.save
|
304
|
+
begin
|
305
|
+
::KirguduBase::AuthenticationsMailer.restore_password_success(DEFAULT_FROM, restore_code.user.email, restore_code.user, password).deliver!
|
306
|
+
@local_data[:email] = restore_code.user.email
|
307
|
+
process_result = true
|
308
|
+
restore_code.is_used = true
|
309
|
+
restore_code.save
|
310
|
+
rescue Exception => e
|
311
|
+
@local_data[:errors] << I18n.t("kirgudu_base.authentications.restore_password_code.errors.failed_to_send_password")
|
312
|
+
end
|
313
|
+
else
|
314
|
+
@local_data[:errors] << I18n.t("kirgudu_base.authentications.restore_password_code.errors.failed_to_save_password")
|
315
|
+
end
|
316
|
+
else
|
317
|
+
@local_data[:errors] << I18n.t("kirgudu_base.authentications.restore_password_code.errors.used_code")
|
318
|
+
end
|
319
|
+
else
|
320
|
+
@local_data[:errors] << I18n.t("kirgudu_base.authentications.restore_password_code.errors.wrong_code")
|
321
|
+
process_result = false
|
322
|
+
end
|
323
|
+
|
324
|
+
|
325
|
+
if process_result
|
326
|
+
redirect_to ::KirguduBase.authentications_controller.to_url_for(:restore_password_success, email: @local_data[:email])
|
327
|
+
else
|
328
|
+
render "/#{@local_data[:template]}/authentications/restore_password_code", locals: {data: @local_data}
|
329
|
+
end
|
330
|
+
end
|
331
|
+
|
332
|
+
def restore_password_success
|
333
|
+
|
334
|
+
params_to_local_data = [:token_id, :redirect_to, :email, :id, :code]
|
335
|
+
params_to_local_data.each do |param_name|
|
336
|
+
@local_data[param_name] = params[param_name] if params[param_name]
|
337
|
+
end
|
338
|
+
render "/#{@local_data[:template]}/authentications/restore_password_success", locals: {data: @local_data}
|
339
|
+
|
340
|
+
end
|
341
|
+
|
342
|
+
|
343
|
+
def confirm_email
|
344
|
+
|
345
|
+
end
|
346
|
+
|
347
|
+
def confirm_email_process
|
348
|
+
|
349
|
+
end
|
350
|
+
|
351
|
+
def destroy
|
352
|
+
|
353
|
+
end
|
354
|
+
|
355
|
+
def destroy_process
|
356
|
+
|
357
|
+
@local_data[:user] = ::KirguduBase::Security::User.where(id: session[self.current_user_symbol])
|
358
|
+
|
359
|
+
if @local_data[:user]
|
360
|
+
if @local_data[:user].destroy
|
361
|
+
flash[:notice] = "Successfully destroyed authentication."
|
362
|
+
redirect_to authentications_url
|
363
|
+
else
|
364
|
+
# failed to delete user
|
365
|
+
end
|
366
|
+
else
|
368
367
|
|
369
|
-
|
370
|
-
|
368
|
+
end
|
369
|
+
end
|
371
370
|
|
372
371
|
|
373
|
-
|
374
|
-
|
372
|
+
protected
|
373
|
+
def on_before_login
|
375
374
|
|
376
|
-
|
375
|
+
end
|
377
376
|
|
378
|
-
|
377
|
+
def on_after_login
|
379
378
|
|
380
|
-
|
379
|
+
end
|
381
380
|
|
382
|
-
|
383
|
-
|
384
|
-
|
381
|
+
def strong_params_on_create
|
382
|
+
params.require(::KirguduBase::Security::User.for_form_params).permit(:email, :first_name, :last_name, :password, :password_confirmation)
|
383
|
+
end
|
385
384
|
|
386
|
-
|
387
|
-
|
388
|
-
|
389
|
-
|
385
|
+
private
|
386
|
+
def redirect_if_loggedin
|
387
|
+
if self.current_user
|
388
|
+
if session[:token_id]
|
390
389
|
|
391
|
-
|
392
|
-
|
393
|
-
|
394
|
-
|
395
|
-
|
396
|
-
|
397
|
-
|
390
|
+
else
|
391
|
+
# redirect_to params[:return_to] || session[:return_to] || self.url_for_default_redirection_after_login || ::KirguduBase.url_for_default_redirection_after_login || "/"
|
392
|
+
raise "redirect if logged in error"
|
393
|
+
redirect_to params[:return_to] || session[:return_to] || ::KirguduBase.url_for_default_redirection_after_login
|
394
|
+
end
|
395
|
+
end
|
396
|
+
end
|
398
397
|
|
399
398
|
|
400
|
-
|
401
|
-
|
402
|
-
|
403
|
-
|
404
|
-
|
405
|
-
|
406
|
-
|
399
|
+
def init_authentications_variables
|
400
|
+
@local_data = {
|
401
|
+
template: self.class.get_method_latest_result(:get_kb_template),
|
402
|
+
messages: [],
|
403
|
+
errors: []
|
404
|
+
}
|
405
|
+
end
|
407
406
|
|
408
407
|
|
409
|
-
|
410
|
-
|
411
|
-
|
412
|
-
|
413
|
-
|
408
|
+
def url_for_default_redirection_after_login
|
409
|
+
nil
|
410
|
+
end
|
411
|
+
end
|
412
|
+
end
|
414
413
|
end
|