質問編集履歴

3

ローカル環境でログインを試みた際のログを追記致しました。

2021/10/12 14:03

投稿

punchan36
punchan36

スコア105

test CHANGED
File without changes
test CHANGED
@@ -100,6 +100,48 @@
100
100
 
101
101
  ローカル環境では新規ユーザー登録・ログイン共に問題なく出来ますので、ログイン機能に関するコードに問題はないと思いますが、必要なコードやログがありましたら追記させて頂きます。
102
102
 
103
+ またローカル環境でログインを試みた際のログは以下の様になります。
104
+
105
+ ```
106
+
107
+ Started POST "/login" for ::1 at 2021-10-12 22:05:33 +0900
108
+
109
+ Processing by UsersController#login as HTML
110
+
111
+ Parameters: {"utf8"=>"✓", "authenticity_token"=>"tiF++rWWqbqxr7qrIDVwWM7l/maX+DmYI+Lrz99GpiIURMAkSz66n/4Dvv5vlvJa3EyPe23oVuvC6cYmLNbSjg==", "email"=>"hoge@fuga.com", "password"=>"[FILTERED]"}
112
+
113
+ User Load (0.6ms) SELECT `users`.* FROM `users` WHERE `users`.`id` IS NULL LIMIT 1
114
+
115
+ ↳ app/controllers/application_controller.rb:9
116
+
117
+ User Load (5.1ms) SELECT `users`.* FROM `users` WHERE `users`.`email` = 'hoge@fuga.com' LIMIT 1
118
+
119
+ ↳ app/controllers/users_controller.rb:255
120
+
121
+ Redirected to http://localhost:3000/
122
+
123
+ Completed 302 Found in 400ms (ActiveRecord: 23.5ms)
124
+
125
+
126
+
127
+
128
+
129
+ Started GET "/" for ::1 at 2021-10-12 22:05:33 +0900
130
+
131
+ Processing by UsersController#top as HTML
132
+
133
+ User Load (6.9ms) SELECT `users`.* FROM `users` WHERE `users`.`id` = 8 LIMIT 1
134
+
135
+
136
+
137
+ 以下略
138
+
139
+ ```
140
+
141
+
142
+
143
+
144
+
103
145
  何か思い当たる原因はありそうでしょうか。どなたかご助言を頂けますと有難いです。
104
146
 
105
147
 

2

config/production.rb 内の記述を追加。またログをより広い範囲で追記致しました。

2021/10/12 14:03

投稿

punchan36
punchan36

スコア105

test CHANGED
File without changes
test CHANGED
@@ -18,29 +18,81 @@
18
18
 
19
19
 
20
20
 
21
- `Heroku logs -t` でログを確認してみたものの、エラーらしき記述を見つける事が出来ませんでした。以下がログインアクション関連のログです。
22
-
23
-
24
-
25
- ```
26
-
27
- 2021-10-11T06:08:59.095224+00:00 heroku[router]: at=info method=GET path="/login" host=hoge.herokuapp.com request_id=45d8248f-937f-471e-87f2-37421b60ac3e fwd="223.219.73.25" dyno=web.1 connect=0ms service=149ms status=200 bytes=5390 protocol=https
28
-
29
- 2021-10-11T06:08:59.482201+00:00 heroku[router]: at=info method=GET path="/country-select-js-master/build/css/countrySelect.css" host=hoge.herokuapp.com request_id=548a4e4d-4cbf-4ee3-a0b0-752a3fa7f53d fwd="223.219.73.25" dyno=web.1 connect=0ms service=1ms status=304 bytes=112 protocol=https
30
-
31
- 2021-10-11T06:09:00.120858+00:00 heroku[router]: at=info method=GET path="/assets/favicon-158c6f713a5801c7d85c29ce37dc893eb66d4156312d27869b837afd9e76a4fa.ico" host=hoge.herokuapp.com request_id=a5f3bb62-033a-46e9-800a-23eb3211ab1a fwd="223.219.73.25" dyno=web.1 connect=0ms service=7ms status=200 bytes=15617 protocol=https
32
-
33
- 2021-10-11T06:09:08.082510+00:00 app[web.1]: I, [2021-10-11T06:09:08.082404 #4] INFO -- : [ee0eebb4-830d-4c0c-ac86-71d369d33256] Started POST "/login" for 223.219.73.25 at 2021-10-11 06:09:08 +0000
34
-
35
- 2021-10-11T06:09:08.083803+00:00 app[web.1]: I, [2021-10-11T06:09:08.083719 #4] INFO -- : [ee0eebb4-830d-4c0c-ac86-71d369d33256] Processing by UsersController#login as HTML
36
-
37
- 2021-10-11T06:09:08.083896+00:00 app[web.1]: I, [2021-10-11T06:09:08.083843 #4] INFO -- : [ee0eebb4-830d-4c0c-ac86-71d369d33256] Parameters: {"utf8"=>"✓", "authenticity_token"=>"30j5dWlCH04y+DOuibu11Il7jd9Zif3o5vyZzAubyjuCNu/8LrcrYFrJaCgMABB9Yk5RCY7rifqMT7pjvowtOA==", "email"=>"hoge@fuga.com", "password"=>"[FILTERED]"}
38
-
39
- 2021-10-11T06:09:08.089908+00:00 app[web.1]: D, [2021-10-11T06:09:08.089828 #4] DEBUG -- : [ee0eebb4-830d-4c0c-ac86-71d369d33256] User Load (2.3ms) SELECT "users".* FROM "users" WHERE "users"."id" IS NULL LIMIT $1 [["LIMIT", 1]]
40
-
41
- 2021-10-11T06:09:08.094137+00:00 app[web.1]: I, [2021-10-11T06:09:08.094061 #4] INFO -- : [ee0eebb4-830d-4c0c-ac86-71d369d33256] Completed 200 OK in 10ms (ActiveRecord: 2.3ms)
42
-
43
- 2021-10-11T06:09:08.102649+00:00 heroku[router]: at=info method=POST path="/login" host=hoge.herokuapp.com request_id=ee0eebb4-830d-4c0c-ac86-71d369d33256 fwd="223.219.73.25" dyno=web.1 connect=0ms service=26ms status=200 bytes=5380 protocol=https
21
+ `Heroku logs -t` でログを確認してみたものの、エラーらしき記述を見つける事が出来ませんでした。以下がログインアクションを含む、ステージング環境を動かした際のログです。
22
+
23
+
24
+
25
+ ```
26
+
27
+ 2021-10-12T06:47:00.234658+00:00 heroku[web.1]: Process exited with status 143
28
+
29
+ 2021-10-12T06:47:07.000000+00:00 app[api]: Build succeeded
30
+
31
+ 2021-10-12T06:47:08.927921+00:00 heroku[web.1]: Starting process with command `bin/rails server -p ${PORT:-5000} -e production`
32
+
33
+ 2021-10-12T06:47:13.161822+00:00 heroku[web.1]: State changed from starting to up
34
+
35
+ 2021-10-12T06:47:22.072892+00:00 heroku[router]: at=info method=GET path="/" host=hoge.herokuapp.com request_id=92132780-ed51-4f7e-a38f-1ddcac5daf99 fwd="106.181.160.222" dyno=web.1 connect=0ms service=73ms status=302 bytes=969 protocol=https
36
+
37
+ 2021-10-12T06:47:22.001611+00:00 app[web.1]: => Booting Puma
38
+
39
+ 2021-10-12T06:47:22.001625+00:00 app[web.1]: => Rails 5.2.6 application starting in production
40
+
41
+ 2021-10-12T06:47:22.001626+00:00 app[web.1]: => Run `rails server -h` for more startup options
42
+
43
+ 2021-10-12T06:47:22.001626+00:00 app[web.1]: Puma starting in single mode...
44
+
45
+ 2021-10-12T06:47:22.001626+00:00 app[web.1]: * Version 3.12.6 (ruby 2.6.8-p205), codename: Llamas in Pajamas
46
+
47
+ 2021-10-12T06:47:22.001627+00:00 app[web.1]: * Min threads: 5, max threads: 5
48
+
49
+ 2021-10-12T06:47:22.001627+00:00 app[web.1]: * Environment: production
50
+
51
+ 2021-10-12T06:47:22.001627+00:00 app[web.1]: * Listening on tcp://0.0.0.0:19816
52
+
53
+ 2021-10-12T06:47:22.001627+00:00 app[web.1]: Use Ctrl-C to stop
54
+
55
+ 2021-10-12T06:47:22.001628+00:00 app[web.1]: I, [2021-10-12T06:47:22.001511 #4] INFO -- : [92132780-ed51-4f7e-a38f-1ddcac5daf99] Started GET "/" for 106.181.160.222 at 2021-10-12 06:47:22 +0000
56
+
57
+ 2021-10-12T06:47:22.002655+00:00 app[web.1]: I, [2021-10-12T06:47:22.002597 #4] INFO -- : [92132780-ed51-4f7e-a38f-1ddcac5daf99] Processing by UsersController#top as HTML
58
+
59
+ 2021-10-12T06:47:22.068886+00:00 app[web.1]: D, [2021-10-12T06:47:22.068807 #4] DEBUG -- : [92132780-ed51-4f7e-a38f-1ddcac5daf99] User Load (1.3ms) SELECT "users".* FROM "users" WHERE "users"."id" IS NULL LIMIT $1 [["LIMIT", 1]]
60
+
61
+ 2021-10-12T06:47:22.069356+00:00 app[web.1]: I, [2021-10-12T06:47:22.069304 #4] INFO -- : [92132780-ed51-4f7e-a38f-1ddcac5daf99] Redirected to https://hoge.herokuapp.com/login
62
+
63
+ 2021-10-12T06:47:22.069415+00:00 app[web.1]: I, [2021-10-12T06:47:22.069390 #4] INFO -- : [92132780-ed51-4f7e-a38f-1ddcac5daf99] Filter chain halted as :authenticate_user rendered or redirected
64
+
65
+ 2021-10-12T06:47:22.069517+00:00 app[web.1]: I, [2021-10-12T06:47:22.069493 #4] INFO -- : [92132780-ed51-4f7e-a38f-1ddcac5daf99] Completed 302 Found in 67ms (ActiveRecord: 28.0ms)
66
+
67
+ 2021-10-12T06:47:22.483502+00:00 heroku[router]: at=info method=GET path="/login" host=hoge.herokuapp.com request_id=b8471159-6064-43d7-8c4b-857a9267369e fwd="106.181.160.222" dyno=web.1 connect=0ms service=44ms status=200 bytes=5015 protocol=https
68
+
69
+ 2021-10-12T06:47:22.439459+00:00 app[web.1]: I, [2021-10-12T06:47:22.439391 #4] INFO -- : [b8471159-6064-43d7-8c4b-857a9267369e] Started GET "/login" for 106.181.160.222 at 2021-10-12 06:47:22 +0000
70
+
71
+ 2021-10-12T06:47:22.440264+00:00 app[web.1]: I, [2021-10-12T06:47:22.440195 #4] INFO -- : [b8471159-6064-43d7-8c4b-857a9267369e] Processing by UsersController#login_form as HTML
72
+
73
+ 2021-10-12T06:47:22.448194+00:00 app[web.1]: D, [2021-10-12T06:47:22.447956 #4] DEBUG -- : [b8471159-6064-43d7-8c4b-857a9267369e] User Load (3.3ms) SELECT "users".* FROM "users" WHERE "users"."id" IS NULL LIMIT $1 [["LIMIT", 1]]
74
+
75
+ 2021-10-12T06:47:22.460549+00:00 app[web.1]: I, [2021-10-12T06:47:22.460442 #4] INFO -- : [b8471159-6064-43d7-8c4b-857a9267369e] Rendering users/login_form.html.erb within layouts/application
76
+
77
+ 2021-10-12T06:47:22.463981+00:00 app[web.1]: I, [2021-10-12T06:47:22.463869 #4] INFO -- : [b8471159-6064-43d7-8c4b-857a9267369e] Rendered users/login_form.html.erb within layouts/application (3.2ms)
78
+
79
+ 2021-10-12T06:47:22.476022+00:00 app[web.1]: D, [2021-10-12T06:47:22.475940 #4] DEBUG -- : [b8471159-6064-43d7-8c4b-857a9267369e] CACHE User Load (0.0ms) SELECT "users".* FROM "users" WHERE "users"."id" IS NULL LIMIT $1 [["LIMIT", 1]]
80
+
81
+ 2021-10-12T06:47:22.480355+00:00 app[web.1]: I, [2021-10-12T06:47:22.480293 #4] INFO -- : [b8471159-6064-43d7-8c4b-857a9267369e] Completed 200 OK in 40ms (Views: 20.9ms | ActiveRecord: 3.3ms)
82
+
83
+ 2021-10-12T06:47:24.905575+00:00 heroku[router]: at=info method=GET path="/country-select-js-master/build/css/countrySelect.css" host=hoge.herokuapp.com request_id=0150fcf9-a871-499a-9183-b4af89f791e6 fwd="106.181.160.222" dyno=web.1 connect=0ms service=6ms status=200 bytes=23223 protocol=https
84
+
85
+ 2021-10-12T06:47:36.035785+00:00 heroku[router]: at=info method=POST path="/login" host=hoge.herokuapp.com request_id=25e922c2-a2d9-4c0a-82e2-4bd629c7f72a fwd="106.181.160.222" dyno=web.1 connect=0ms service=13ms status=200 bytes=5009 protocol=https
86
+
87
+ 2021-10-12T06:47:36.029749+00:00 app[web.1]: I, [2021-10-12T06:47:36.029673 #4] INFO -- : [25e922c2-a2d9-4c0a-82e2-4bd629c7f72a] Started POST "/login" for 106.181.160.222 at 2021-10-12 06:47:36 +0000
88
+
89
+ 2021-10-12T06:47:36.030350+00:00 app[web.1]: I, [2021-10-12T06:47:36.030307 #4] INFO -- : [25e922c2-a2d9-4c0a-82e2-4bd629c7f72a] Processing by UsersController#login as HTML
90
+
91
+ 2021-10-12T06:47:36.030398+00:00 app[web.1]: I, [2021-10-12T06:47:36.030366 #4] INFO -- : [25e922c2-a2d9-4c0a-82e2-4bd629c7f72a] Parameters: {"utf8"=>"✓", "authenticity_token"=>"Beft8hxwZ0OxZeSL3M3wuzQ2rAMzfbO4268bjy+Mmon0FQE9SA+ahZ9aemMqLOehklbP/S5G1XIfmJbF6KK1qQ==", "email"=>"hoge@fuga.comm", "password"=>"[FILTERED]"}
92
+
93
+ 2021-10-12T06:47:36.033840+00:00 app[web.1]: D, [2021-10-12T06:47:36.033777 #4] DEBUG -- : [25e922c2-a2d9-4c0a-82e2-4bd629c7f72a] User Load (1.2ms) SELECT "users".* FROM "users" WHERE "users"."id" IS NULL LIMIT $1 [["LIMIT", 1]]
94
+
95
+ 2021-10-12T06:47:36.034672+00:00 app[web.1]: I, [2021-10-12T06:47:36.034626 #4] INFO -- : [25e922c2-a2d9-4c0a-82e2-4bd629c7f72a] Completed 200 OK in 4ms (ActiveRecord: 1.2ms)
44
96
 
45
97
  ```
46
98
 
@@ -198,6 +250,22 @@
198
250
 
199
251
 
200
252
 
253
+ **config/production.rb**
254
+
255
+ ```
256
+
257
+ config.force_ssl = true
258
+
259
+
260
+
261
+ config.force_ssl = false
262
+
263
+ # application.rb内で記述した、secure: Rails.env.production?(本番環境のみSSL属性を付ける(SSL化する))為に必要なコード。デフォルトのfalseに直すも結果は変わらず。
264
+
265
+ ```
266
+
267
+
268
+
201
269
  ### 補足情報(FW/ツールのバージョンなど)
202
270
 
203
271
 

1

「コード」の部分を丸々追記致しました。

2021/10/12 07:05

投稿

punchan36
punchan36

スコア105

test CHANGED
File without changes
test CHANGED
@@ -52,6 +52,124 @@
52
52
 
53
53
 
54
54
 
55
+ ### コード
56
+
57
+
58
+
59
+ **routes.rb**
60
+
61
+ ```
62
+
63
+ get "login" => "users#login_form"
64
+
65
+ post "login" => "users#login"
66
+
67
+ ```
68
+
69
+
70
+
71
+ **users_controller.rb**
72
+
73
+ ```
74
+
75
+ class UsersController < ApplicationController
76
+
77
+ before_action :authenticate_user, {except: [:new, :create, :login_form, :login]}
78
+
79
+ before_action :forbid_login_user, {only: [:new, :create, :login_form, :login]}
80
+
81
+
82
+
83
+ def login
84
+
85
+ @user = User.find_by(email: params[:email])
86
+
87
+ if @user && @user.authenticate(params[:password])
88
+
89
+ session[:user_id] = @user.id
90
+
91
+ flash[:notice] = "You have successfully logged in"
92
+
93
+ redirect_to("/")
94
+
95
+ else
96
+
97
+ @error_message = "Email address or password is incorrect"
98
+
99
+ @email = params[:email]
100
+
101
+ @password = params[:password]
102
+
103
+ render("users/login_form")
104
+
105
+ end
106
+
107
+ end
108
+
109
+
110
+
111
+ def login_form
112
+
113
+ end
114
+
115
+ end
116
+
117
+ ```
118
+
119
+
120
+
121
+ **users/login_form.html.erb**
122
+
123
+ ```
124
+
125
+ <% if @error_message %>
126
+
127
+ <div class="form-error">
128
+
129
+ <%= @error_message %>
130
+
131
+ </div>
132
+
133
+ <% end %>
134
+
135
+
136
+
137
+ <%= form_tag("/login") do %>
138
+
139
+ <ul>
140
+
141
+ <li>
142
+
143
+ <div class="col-1">Email</div>
144
+
145
+ <div class="col-2"><input size="60" name="email" value="<%= @email %>"></div>
146
+
147
+ </li>
148
+
149
+ <li>
150
+
151
+ <div class="col-1">Password</div>
152
+
153
+ <div class="col-2"><input size="40" id="password" name="password" type="password" value="<%= @password %>"></div>
154
+
155
+ <span toggle="#password-field" class="fa fa-fw fa-eye field_icon toggle-password"></span>
156
+
157
+ </li>
158
+
159
+ <li>
160
+
161
+ <div class="save"><input class="btn-square-little-rich" id="button" type="submit" value="Log in" onclick="myfunk()"></div>
162
+
163
+ </li>
164
+
165
+ </ul>
166
+
167
+ <% end %>
168
+
169
+ ```
170
+
171
+
172
+
55
173
  ### 試したこと
56
174
 
57
175
 
@@ -80,8 +198,6 @@
80
198
 
81
199
 
82
200
 
83
-
84
-
85
201
  ### 補足情報(FW/ツールのバージョンなど)
86
202
 
87
203