質問編集履歴
3
タイトル変更
test
CHANGED
@@ -1 +1 @@
|
|
1
|
-
devise
|
1
|
+
deviseでのユーザーログインで認証失敗の際エラーメッセージを表示させたい。
|
test
CHANGED
File without changes
|
2
誤字修正
test
CHANGED
File without changes
|
test
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
### deviseでのユーザーログインで認証失敗の際エラーメッセージを表示さ。
|
1
|
+
### deviseでのユーザーログインで認証失敗の際エラーメッセージを表示させたい。
|
2
2
|
|
3
3
|
|
4
4
|
|
1
ファイルの追加
test
CHANGED
File without changes
|
test
CHANGED
@@ -186,57 +186,191 @@
|
|
186
186
|
|
187
187
|
vendor/bundle/ruby/2.5.0/gems/actionpack-5.2.2/lib/action_dispatch/middleware/debug_exceptions.rb:61:in `call'
|
188
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
|
-
|
189
|
+
```
|
190
|
+
|
191
|
+
|
192
|
+
|
193
|
+
sessions_controller.rb
|
194
|
+
|
195
|
+
```
|
196
|
+
|
197
|
+
# frozen_string_literal: true
|
198
|
+
|
199
|
+
|
200
|
+
|
201
|
+
class Users::SessionsController < Devise::SessionsController
|
202
|
+
|
203
|
+
before_action :alert_account, only: :destroy, raise: false
|
204
|
+
|
205
|
+
before_action :reset_session_before_login, only: :create
|
206
|
+
|
207
|
+
protect_from_forgery :except => [:create]
|
208
|
+
|
209
|
+
|
210
|
+
|
211
|
+
# before_action :configure_sign_in_params, only: [:create]
|
212
|
+
|
213
|
+
|
214
|
+
|
215
|
+
# GET /resource/sign_in
|
216
|
+
|
217
|
+
# def new
|
218
|
+
|
219
|
+
# super
|
220
|
+
|
221
|
+
# end
|
222
|
+
|
223
|
+
|
224
|
+
|
225
|
+
# POST /resource/sign_in
|
226
|
+
|
227
|
+
# def create
|
228
|
+
|
229
|
+
# super
|
230
|
+
|
231
|
+
# end
|
232
|
+
|
233
|
+
|
234
|
+
|
235
|
+
# DELETE /resource/sign_out
|
236
|
+
|
237
|
+
# def destroy
|
238
|
+
|
239
|
+
# super
|
240
|
+
|
241
|
+
# end
|
242
|
+
|
243
|
+
|
244
|
+
|
245
|
+
# protected
|
246
|
+
|
247
|
+
|
248
|
+
|
249
|
+
# If you have extra params to permit, append them to the sanitizer.
|
250
|
+
|
251
|
+
# def configure_sign_in_params
|
252
|
+
|
253
|
+
# devise_parameter_sanitizer.permit(:sign_in, keys: [:attribute])
|
254
|
+
|
255
|
+
# end
|
256
|
+
|
257
|
+
private
|
258
|
+
|
259
|
+
|
260
|
+
|
261
|
+
def reset_session_before_login
|
262
|
+
|
263
|
+
user_return_to = session[:user_return_to]
|
264
|
+
|
265
|
+
reset_session
|
266
|
+
|
267
|
+
session[:user_return_to] = user_return_to if user_return_to
|
268
|
+
|
269
|
+
end
|
270
|
+
|
271
|
+
end
|
272
|
+
|
273
|
+
```
|
274
|
+
|
275
|
+
|
276
|
+
|
277
|
+
application_controller.rb
|
278
|
+
|
279
|
+
|
280
|
+
|
281
|
+
```
|
282
|
+
|
283
|
+
class ApplicationController < ActionController::Base
|
284
|
+
|
285
|
+
protect_from_forgery with: :exception
|
286
|
+
|
287
|
+
before_action :configure_permitted_parameters, if: :devise_controller?
|
288
|
+
|
289
|
+
before_action :configure_account_update_params, if: :devise_controller?
|
290
|
+
|
291
|
+
before_action :set_host
|
292
|
+
|
293
|
+
before_action :store_current_location, unless: :devise_controller?
|
294
|
+
|
295
|
+
|
296
|
+
|
297
|
+
def alert_account
|
298
|
+
|
299
|
+
unless current_user
|
300
|
+
|
301
|
+
flash[:alert] = "アカウントの作成もしくはログインしてください"
|
302
|
+
|
303
|
+
redirect_to new_user_session_path
|
304
|
+
|
305
|
+
end
|
306
|
+
|
307
|
+
end
|
308
|
+
|
309
|
+
|
310
|
+
|
311
|
+
def configure_permitted_parameters
|
312
|
+
|
313
|
+
devise_parameter_sanitizer.permit(:sign_up, keys: [:username, :tall, :age, :gendar, :active_level, :recom_calorie, :image, :password, :password_confirmation, :email])
|
314
|
+
|
315
|
+
end
|
316
|
+
|
317
|
+
|
318
|
+
|
319
|
+
def configure_account_update_params
|
320
|
+
|
321
|
+
devise_parameter_sanitizer.permit(:account_update, keys: [:username,:tall, :age, :gendar, :active_level, :recom_calorie, :image])
|
322
|
+
|
323
|
+
end
|
324
|
+
|
325
|
+
|
326
|
+
|
327
|
+
def require_admin
|
328
|
+
|
329
|
+
redirect_to root_path unless current_user.admin?
|
330
|
+
|
331
|
+
end
|
332
|
+
|
333
|
+
|
334
|
+
|
335
|
+
def set_host
|
336
|
+
|
337
|
+
Rails.application.routes.default_url_options[:host] = request.host_with_port
|
338
|
+
|
339
|
+
end
|
340
|
+
|
341
|
+
|
342
|
+
|
343
|
+
def user_recom?
|
344
|
+
|
345
|
+
unless (current_user&.recom_calorie) || session[:recom_calorie]
|
346
|
+
|
347
|
+
flash[:notice] = "先に推奨カロリーを計算しましょう。"
|
348
|
+
|
349
|
+
unless current_user
|
350
|
+
|
351
|
+
redirect_to new_scalcalo_path
|
352
|
+
|
353
|
+
else
|
354
|
+
|
355
|
+
redirect_to edit_calcalo_path(current_user)
|
356
|
+
|
357
|
+
end
|
358
|
+
|
359
|
+
end
|
360
|
+
|
361
|
+
end
|
362
|
+
|
363
|
+
|
364
|
+
|
365
|
+
def store_current_location
|
366
|
+
|
367
|
+
return if current_user
|
368
|
+
|
369
|
+
store_location_for(:user, request.url)
|
370
|
+
|
371
|
+
end
|
372
|
+
|
373
|
+
end
|
240
374
|
|
241
375
|
```
|
242
376
|
|