質問編集履歴
5
変更してあったソースコードの繁栄
test
CHANGED
File without changes
|
test
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
### 前提・実現したいこと
|
2
2
|
|
3
|
-
teratailの皆様のおかげでなんとかあ
|
3
|
+
teratailの皆様のおかげでなんとかサービス完成まであと僅かのところまで漕ぎつけました。
|
4
4
|
|
5
5
|
Ruby on railsでログイン機能を実装したいです。
|
6
6
|
|
@@ -92,7 +92,7 @@
|
|
92
92
|
|
93
93
|
|
94
94
|
|
95
|
-
app/views/registrations/new.html.erb(会員登録フォーム)
|
95
|
+
app/views/users/registrations/new.html.erb(会員登録フォーム)
|
96
96
|
|
97
97
|
```
|
98
98
|
|
@@ -122,7 +122,7 @@
|
|
122
122
|
|
123
123
|
|
124
124
|
|
125
|
-
app/users/sessions_controller.rb(ログイン処理のコントローラー)
|
125
|
+
app/controllers/users/sessions_controller.rb(ログイン処理のコントローラー)
|
126
126
|
|
127
127
|
```
|
128
128
|
|
@@ -134,17 +134,11 @@
|
|
134
134
|
|
135
135
|
def create
|
136
136
|
|
137
|
-
|
137
|
+
@user = User.find_by(email: params[:session][:email])
|
138
|
-
|
139
|
-
|
138
|
+
|
140
|
-
|
141
|
-
user = User.find_by(email: params[:email])
|
142
|
-
|
143
|
-
if user && user.valid_password?(params[:password])
|
139
|
+
if @user && @user.valid_password?(params[:session][:password])
|
144
|
-
|
140
|
+
|
145
|
-
sign_in user
|
141
|
+
sign_in @user
|
146
|
-
|
147
|
-
# session[:id] = user.id
|
148
142
|
|
149
143
|
flash[:notice] = "ログイン成功"
|
150
144
|
|
@@ -208,28 +202,6 @@
|
|
208
202
|
|
209
203
|
|
210
204
|
|
211
|
-
### 試したこと
|
212
|
-
|
213
|
-
user.rbに
|
214
|
-
|
215
|
-
```
|
216
|
-
|
217
|
-
has_secure_password
|
218
|
-
|
219
|
-
```
|
220
|
-
|
221
|
-
を追加すると新規登録ボタンを押した時点で
|
222
|
-
|
223
|
-
```
|
224
|
-
|
225
|
-
We're sorry, but something went wrong.
|
226
|
-
|
227
|
-
```
|
228
|
-
|
229
|
-
が発生してしまいます。
|
230
|
-
|
231
|
-
|
232
|
-
|
233
205
|
### 補足情報
|
234
206
|
|
235
207
|
Windows 10 home 64ビット
|
@@ -245,39 +217,3 @@
|
|
245
217
|
|
246
218
|
|
247
219
|
失礼な点があるかもしれませんがどうぞ宜しくおねがい致します。
|
248
|
-
|
249
|
-
|
250
|
-
|
251
|
-
### 補足
|
252
|
-
|
253
|
-
一部省略
|
254
|
-
|
255
|
-
```
|
256
|
-
|
257
|
-
2020-06-06T08:24:31.746790+00:00 app[web.1]: Puma starting in single mode...
|
258
|
-
|
259
|
-
2020-06-06T08:25:00.922875+00:00 app[web.1]: [07b453f3-d520-402c-8aad-5f9667e4acee] Parameters: {"authenticity_token"=>"KSGXsYc0GV+coPxYTg5twI4T3B+T7RQ9XOz/x51E1Gp7J8ynmSO9vREN3Hj0LileNdR0xQQ9jti0wnii+HsnJQ==", "session"=>{"email"=>"tihutihutihu@tihu.org", "password"=>"[FILTERED]", "remember_me"=>"0"}, "commit"=>"ログイン!"}
|
260
|
-
|
261
|
-
2020-06-06T08:27:30.840763+00:00 app[web.1]: DEPRECATION WARNING: Including LoggerSilence is deprecated and will be removed in Rails 6.1. Please use `ActiveSupport::LoggerSilence` instead (called from <top (required)> at /app/config/application.rb:3)
|
262
|
-
|
263
|
-
2020-06-06T08:27:59.355676+00:00 app[web.1]: [0727795b-cf75-4fcf-ab01-a2e86c286967] Parameters: {"authenticity_token"=>"POnZT/w7W1e9u92vYPQaVocONPLuChbmry3nTA3pdo9u74JZ4iz/tTAW/Y/a1F7IPMmcKHnajANHA2ApaNaFwA==", "session"=>{"email"=>"tihutihutihu@tihu.org", "password"=>"[FILTERED]", "remember_me"=>"0"}, "commit"=>"ログイン!"}
|
264
|
-
|
265
|
-
2020-06-06T08:27:59.825406+00:00 app[web.1]: [a28788cb-1074-40e8-a70e-6968a3eef49e] 32: <a href="ionamata">運営者が投稿する</a>
|
266
|
-
|
267
|
-
2020-06-06T08:27:59.825406+00:00 app[web.1]: [a28788cb-1074-40e8-a70e-6968a3eef49e] 33: <a href="kensaku">検索ページ</a>
|
268
|
-
|
269
|
-
2020-06-06T08:27:59.825407+00:00 app[web.1]: [a28788cb-1074-40e8-a70e-6968a3eef49e] 34: <a href="kesu">退会したい方はこちら</a>
|
270
|
-
|
271
|
-
2020-06-06T08:27:59.825407+00:00 app[web.1]: [a28788cb-1074-40e8-a70e-6968a3eef49e] 35: <% if user_signed_in? %>
|
272
|
-
|
273
|
-
2020-06-06T08:27:59.825407+00:00 app[web.1]: [a28788cb-1074-40e8-a70e-6968a3eef49e] 36: <p>ログインしていますよ!</p>
|
274
|
-
|
275
|
-
2020-06-06T08:27:59.825408+00:00 app[web.1]: [a28788cb-1074-40e8-a70e-6968a3eef49e] 37: <%= link_to "退会", "kesu" %>
|
276
|
-
|
277
|
-
2020-06-06T08:27:59.825408+00:00 app[web.1]: [a28788cb-1074-40e8-a70e-6968a3eef49e] 38: <% else %>
|
278
|
-
|
279
|
-
2020-06-06T08:27:59.825409+00:00 app[web.1]: [a28788cb-1074-40e8-a70e-6968a3eef49e]
|
280
|
-
|
281
|
-
2020-06-06T08:27:20.000000+00:00 app[api]: Build succeeded
|
282
|
-
|
283
|
-
```
|
4
heroku logs
test
CHANGED
File without changes
|
test
CHANGED
@@ -245,3 +245,39 @@
|
|
245
245
|
|
246
246
|
|
247
247
|
失礼な点があるかもしれませんがどうぞ宜しくおねがい致します。
|
248
|
+
|
249
|
+
|
250
|
+
|
251
|
+
### 補足
|
252
|
+
|
253
|
+
一部省略
|
254
|
+
|
255
|
+
```
|
256
|
+
|
257
|
+
2020-06-06T08:24:31.746790+00:00 app[web.1]: Puma starting in single mode...
|
258
|
+
|
259
|
+
2020-06-06T08:25:00.922875+00:00 app[web.1]: [07b453f3-d520-402c-8aad-5f9667e4acee] Parameters: {"authenticity_token"=>"KSGXsYc0GV+coPxYTg5twI4T3B+T7RQ9XOz/x51E1Gp7J8ynmSO9vREN3Hj0LileNdR0xQQ9jti0wnii+HsnJQ==", "session"=>{"email"=>"tihutihutihu@tihu.org", "password"=>"[FILTERED]", "remember_me"=>"0"}, "commit"=>"ログイン!"}
|
260
|
+
|
261
|
+
2020-06-06T08:27:30.840763+00:00 app[web.1]: DEPRECATION WARNING: Including LoggerSilence is deprecated and will be removed in Rails 6.1. Please use `ActiveSupport::LoggerSilence` instead (called from <top (required)> at /app/config/application.rb:3)
|
262
|
+
|
263
|
+
2020-06-06T08:27:59.355676+00:00 app[web.1]: [0727795b-cf75-4fcf-ab01-a2e86c286967] Parameters: {"authenticity_token"=>"POnZT/w7W1e9u92vYPQaVocONPLuChbmry3nTA3pdo9u74JZ4iz/tTAW/Y/a1F7IPMmcKHnajANHA2ApaNaFwA==", "session"=>{"email"=>"tihutihutihu@tihu.org", "password"=>"[FILTERED]", "remember_me"=>"0"}, "commit"=>"ログイン!"}
|
264
|
+
|
265
|
+
2020-06-06T08:27:59.825406+00:00 app[web.1]: [a28788cb-1074-40e8-a70e-6968a3eef49e] 32: <a href="ionamata">運営者が投稿する</a>
|
266
|
+
|
267
|
+
2020-06-06T08:27:59.825406+00:00 app[web.1]: [a28788cb-1074-40e8-a70e-6968a3eef49e] 33: <a href="kensaku">検索ページ</a>
|
268
|
+
|
269
|
+
2020-06-06T08:27:59.825407+00:00 app[web.1]: [a28788cb-1074-40e8-a70e-6968a3eef49e] 34: <a href="kesu">退会したい方はこちら</a>
|
270
|
+
|
271
|
+
2020-06-06T08:27:59.825407+00:00 app[web.1]: [a28788cb-1074-40e8-a70e-6968a3eef49e] 35: <% if user_signed_in? %>
|
272
|
+
|
273
|
+
2020-06-06T08:27:59.825407+00:00 app[web.1]: [a28788cb-1074-40e8-a70e-6968a3eef49e] 36: <p>ログインしていますよ!</p>
|
274
|
+
|
275
|
+
2020-06-06T08:27:59.825408+00:00 app[web.1]: [a28788cb-1074-40e8-a70e-6968a3eef49e] 37: <%= link_to "退会", "kesu" %>
|
276
|
+
|
277
|
+
2020-06-06T08:27:59.825408+00:00 app[web.1]: [a28788cb-1074-40e8-a70e-6968a3eef49e] 38: <% else %>
|
278
|
+
|
279
|
+
2020-06-06T08:27:59.825409+00:00 app[web.1]: [a28788cb-1074-40e8-a70e-6968a3eef49e]
|
280
|
+
|
281
|
+
2020-06-06T08:27:20.000000+00:00 app[api]: Build succeeded
|
282
|
+
|
283
|
+
```
|
3
変更点の繁栄
test
CHANGED
File without changes
|
test
CHANGED
@@ -134,11 +134,17 @@
|
|
134
134
|
|
135
135
|
def create
|
136
136
|
|
137
|
+
# user = User.find_by(email: params[:session][:email])
|
138
|
+
|
139
|
+
# if user && user.authenticate(params[:session][:encrypted_password])
|
140
|
+
|
137
141
|
user = User.find_by(email: params[:email])
|
138
142
|
|
139
|
-
if user && user.a
|
143
|
+
if user && user.valid_password?(params[:password])
|
144
|
+
|
140
|
-
|
145
|
+
sign_in user
|
146
|
+
|
141
|
-
session[:id] = user.id
|
147
|
+
# session[:id] = user.id
|
142
148
|
|
143
149
|
flash[:notice] = "ログイン成功"
|
144
150
|
|
@@ -184,7 +190,7 @@
|
|
184
190
|
|
185
191
|
|
186
192
|
|
187
|
-
|
193
|
+
models/user.rb
|
188
194
|
|
189
195
|
```
|
190
196
|
|
@@ -204,28 +210,6 @@
|
|
204
210
|
|
205
211
|
### 試したこと
|
206
212
|
|
207
|
-
app/users/sessions_controller.rb(ログイン処理のコントローラー)
|
208
|
-
|
209
|
-
の
|
210
|
-
|
211
|
-
```
|
212
|
-
|
213
|
-
if user && user.authenticate(params[:encrypted_password])
|
214
|
-
|
215
|
-
```
|
216
|
-
|
217
|
-
を
|
218
|
-
|
219
|
-
```
|
220
|
-
|
221
|
-
if user && user.authenticate(params[:password])
|
222
|
-
|
223
|
-
```
|
224
|
-
|
225
|
-
に変えましたがログインに失敗してしまいました。
|
226
|
-
|
227
|
-
|
228
|
-
|
229
213
|
user.rbに
|
230
214
|
|
231
215
|
```
|
2
has_secure_passwordの追記
test
CHANGED
File without changes
|
test
CHANGED
@@ -226,6 +226,26 @@
|
|
226
226
|
|
227
227
|
|
228
228
|
|
229
|
+
user.rbに
|
230
|
+
|
231
|
+
```
|
232
|
+
|
233
|
+
has_secure_password
|
234
|
+
|
235
|
+
```
|
236
|
+
|
237
|
+
を追加すると新規登録ボタンを押した時点で
|
238
|
+
|
239
|
+
```
|
240
|
+
|
241
|
+
We're sorry, but something went wrong.
|
242
|
+
|
243
|
+
```
|
244
|
+
|
245
|
+
が発生してしまいます。
|
246
|
+
|
247
|
+
|
248
|
+
|
229
249
|
### 補足情報
|
230
250
|
|
231
251
|
Windows 10 home 64ビット
|
1
モデルの追記
test
CHANGED
File without changes
|
test
CHANGED
@@ -184,6 +184,24 @@
|
|
184
184
|
|
185
185
|
|
186
186
|
|
187
|
+
spp/models/user.rb
|
188
|
+
|
189
|
+
```
|
190
|
+
|
191
|
+
class User < ApplicationRecord
|
192
|
+
|
193
|
+
devise :database_authenticatable, :registerable,
|
194
|
+
|
195
|
+
:recoverable, :rememberable, :validatable
|
196
|
+
|
197
|
+
validates :email, uniqueness: true
|
198
|
+
|
199
|
+
end
|
200
|
+
|
201
|
+
```
|
202
|
+
|
203
|
+
|
204
|
+
|
187
205
|
### 試したこと
|
188
206
|
|
189
207
|
app/users/sessions_controller.rb(ログイン処理のコントローラー)
|