質問編集履歴
1
修正
test
CHANGED
File without changes
|
test
CHANGED
@@ -10,6 +10,8 @@
|
|
10
10
|
|
11
11
|
メールが届き、Activateリンクを踏んでも認証されていないという問題が発生して困っています。
|
12
12
|
|
13
|
+
リンクの生成が正しく行われていないのかと思います。
|
14
|
+
|
13
15
|
ログはこんな感じです。
|
14
16
|
|
15
17
|
```
|
@@ -110,43 +112,233 @@
|
|
110
112
|
|
111
113
|
----==_mimepart_5dccc97b9e4cc_c5e93ff5410a0d68846d
|
112
114
|
|
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
|
-
a
|
138
|
-
|
139
|
-
|
140
|
-
|
141
|
-
|
142
|
-
|
143
|
-
|
144
|
-
|
145
|
-
|
146
|
-
|
147
|
-
|
148
|
-
|
149
|
-
|
115
|
+
|
116
|
+
|
117
|
+
```
|
118
|
+
|
119
|
+
Postmanで確認してみるとこんな感じになります
|
120
|
+
|
121
|
+
```json
|
122
|
+
|
123
|
+
{
|
124
|
+
|
125
|
+
"status": "success",
|
126
|
+
|
127
|
+
"data": {
|
128
|
+
|
129
|
+
"id": 63,
|
130
|
+
|
131
|
+
"email": "ts@icloud.com",
|
132
|
+
|
133
|
+
"password_digest": "$2a$12$tp4dd/HD7L81zvxaVrNnhOyI1JOBt/300zLEQbiV56rJ9JXqxuN/a",
|
134
|
+
|
135
|
+
"remember_digest": null,
|
136
|
+
|
137
|
+
"admin": null,
|
138
|
+
|
139
|
+
"activation_digest": "$2a$12$551NNcMiWkr9seluACIDj.xcmyji5DrMPWXIjqZepoVi42KOCXrPO",
|
140
|
+
|
141
|
+
"activated_at": null,
|
142
|
+
|
143
|
+
"reset_digest": null,
|
144
|
+
|
145
|
+
"reset_sent_at": null,
|
146
|
+
|
147
|
+
"user_name": "ts",
|
148
|
+
|
149
|
+
"display_name": null,
|
150
|
+
|
151
|
+
"address": null,
|
152
|
+
|
153
|
+
"avatar_uri": null,
|
154
|
+
|
155
|
+
"created_at": "2019-11-14T12:26:51.396+09:00",
|
156
|
+
|
157
|
+
"updated_at": "2019-11-14T12:26:51.396+09:00",
|
158
|
+
|
159
|
+
"activated": false,
|
160
|
+
|
161
|
+
}
|
162
|
+
|
163
|
+
}
|
164
|
+
|
165
|
+
```
|
166
|
+
|
167
|
+
### 該当のソースコード
|
168
|
+
|
169
|
+
user_controller.rb
|
170
|
+
|
171
|
+
```ruby
|
172
|
+
|
173
|
+
class UsersController < ApplicationController
|
174
|
+
|
175
|
+
before_action :set_user, only: [:update, :destroy]
|
176
|
+
|
177
|
+
|
178
|
+
|
179
|
+
# before_action :logged_in_user, only: [:index, :edit, :update, :destroy,
|
180
|
+
|
181
|
+
# :following, :followers]
|
182
|
+
|
183
|
+
# before_action :correct_user, only: [:edit, :update]
|
184
|
+
|
185
|
+
# before_action :admin_user, only: :destroy
|
186
|
+
|
187
|
+
|
188
|
+
|
189
|
+
def create
|
190
|
+
|
191
|
+
@user = User.new(user_params)
|
192
|
+
|
193
|
+
if @user.save
|
194
|
+
|
195
|
+
@user.send_activation_email
|
196
|
+
|
197
|
+
render json: { status: "Please check your email to activate your account." }
|
198
|
+
|
199
|
+
else
|
200
|
+
|
201
|
+
render json: { status: 'error!', data: @user.errors }
|
202
|
+
|
203
|
+
end
|
204
|
+
|
205
|
+
end
|
206
|
+
|
207
|
+
|
208
|
+
|
209
|
+
def edit
|
210
|
+
|
211
|
+
@user = User.find(params[:id])
|
212
|
+
|
213
|
+
end
|
214
|
+
|
215
|
+
|
216
|
+
|
217
|
+
def update
|
218
|
+
|
219
|
+
# @user = User.find(params[:id])
|
220
|
+
|
221
|
+
if @user.update(user_params)
|
222
|
+
|
223
|
+
render json: { status: 'success', data: @user }
|
224
|
+
|
225
|
+
else
|
226
|
+
|
227
|
+
render json: { status: 'error', data: @user.errors }
|
228
|
+
|
229
|
+
end
|
230
|
+
|
231
|
+
end
|
232
|
+
|
233
|
+
|
234
|
+
|
235
|
+
def destroy
|
236
|
+
|
237
|
+
# User.find(params[:id]).destroy
|
238
|
+
|
239
|
+
# flash[:success] = "User deleted"
|
240
|
+
|
241
|
+
# redirect_to users_url
|
242
|
+
|
243
|
+
@user.destroy
|
244
|
+
|
245
|
+
render json: { status: 'success', data: @user }
|
246
|
+
|
247
|
+
end
|
248
|
+
|
249
|
+
|
250
|
+
|
251
|
+
private
|
252
|
+
|
253
|
+
|
254
|
+
|
255
|
+
def user_params
|
256
|
+
|
257
|
+
params.require(:user).permit(:user_name,:email,:password,:password_confirmation)
|
258
|
+
|
259
|
+
# @users = params[:user].permit(:email, :password, :password_confirmation)
|
260
|
+
|
261
|
+
end
|
262
|
+
|
263
|
+
|
264
|
+
|
265
|
+
def set_user
|
266
|
+
|
267
|
+
@user = User.find(params[:id])
|
268
|
+
|
269
|
+
end
|
270
|
+
|
271
|
+
end
|
272
|
+
|
273
|
+
|
274
|
+
|
275
|
+
```
|
276
|
+
|
277
|
+
account_activation_controller.rb
|
278
|
+
|
279
|
+
```ruby
|
280
|
+
|
281
|
+
class AccountActivationsController < ApplicationController
|
282
|
+
|
283
|
+
|
284
|
+
|
285
|
+
def edit
|
286
|
+
|
287
|
+
user = User.find_by(email: params[:email])
|
288
|
+
|
289
|
+
token = params[:token]
|
290
|
+
|
291
|
+
if user && !user.activated? && user.authenticated?(:activation, :token)
|
292
|
+
|
293
|
+
user.activate
|
294
|
+
|
295
|
+
log_in user
|
296
|
+
|
297
|
+
render json:{status:"Account activated!"}
|
298
|
+
|
299
|
+
else
|
300
|
+
|
301
|
+
render json:{status:"Invalid activation link"}
|
302
|
+
|
303
|
+
end
|
304
|
+
|
305
|
+
end
|
306
|
+
|
307
|
+
end
|
308
|
+
|
309
|
+
```
|
310
|
+
|
311
|
+
account_activation.text.erb
|
312
|
+
|
313
|
+
```erb
|
314
|
+
|
315
|
+
Hi <%= @user.user_name %>,
|
316
|
+
|
317
|
+
|
318
|
+
|
319
|
+
Welcome to the Sample App! Click on the link below to activate your account:
|
320
|
+
|
321
|
+
|
322
|
+
|
323
|
+
<%= edit_account_activation_url(@user,
|
324
|
+
|
325
|
+
token: @user.activation_token,
|
326
|
+
|
327
|
+
email: @user.email) %>
|
328
|
+
|
329
|
+
|
330
|
+
|
331
|
+
```
|
332
|
+
|
333
|
+
account_activation.html.erb
|
334
|
+
|
335
|
+
```erb
|
336
|
+
|
337
|
+
<h1>Sample App</h1>
|
338
|
+
|
339
|
+
|
340
|
+
|
341
|
+
<p>Hi <%= @user.user_name %>,</p>
|
150
342
|
|
151
343
|
|
152
344
|
|
@@ -158,168 +350,20 @@
|
|
158
350
|
|
159
351
|
|
160
352
|
|
161
|
-
<
|
353
|
+
<%= link_to "Activate", edit_account_activation_url(@user,
|
162
|
-
|
163
|
-
|
164
|
-
|
354
|
+
|
165
|
-
|
355
|
+
token: @user.activation_token,
|
166
|
-
|
356
|
+
|
167
|
-
|
357
|
+
email: @user.email) %>
|
168
|
-
|
169
|
-
|
170
|
-
|
171
|
-
|
358
|
+
|
172
|
-
|
173
|
-
|
174
|
-
|
175
|
-
|
176
|
-
|
177
|
-
|
359
|
+
|
178
|
-
|
179
|
-
|
180
|
-
|
360
|
+
|
181
|
-
```
|
361
|
+
```
|
182
|
-
|
183
|
-
|
362
|
+
|
184
|
-
|
185
|
-
|
363
|
+
user.rb
|
186
|
-
|
187
|
-
{
|
188
|
-
|
189
|
-
"status": "success",
|
190
|
-
|
191
|
-
"data": {
|
192
|
-
|
193
|
-
"id": 63,
|
194
|
-
|
195
|
-
"email": "ts@icloud.com",
|
196
|
-
|
197
|
-
"password_digest": "$2a$12$tp4dd/HD7L81zvxaVrNnhOyI1JOBt/300zLEQbiV56rJ9JXqxuN/a",
|
198
|
-
|
199
|
-
"remember_digest": null,
|
200
|
-
|
201
|
-
"admin": null,
|
202
|
-
|
203
|
-
"activation_digest": "$2a$12$551NNcMiWkr9seluACIDj.xcmyji5DrMPWXIjqZepoVi42KOCXrPO",
|
204
|
-
|
205
|
-
"activated_at": null,
|
206
|
-
|
207
|
-
"reset_digest": null,
|
208
|
-
|
209
|
-
"reset_sent_at": null,
|
210
|
-
|
211
|
-
"user_name": "ts",
|
212
|
-
|
213
|
-
"display_name": null,
|
214
|
-
|
215
|
-
"address": null,
|
216
|
-
|
217
|
-
"avatar_uri": null,
|
218
|
-
|
219
|
-
"created_at": "2019-11-14T12:26:51.396+09:00",
|
220
|
-
|
221
|
-
"updated_at": "2019-11-14T12:26:51.396+09:00",
|
222
|
-
|
223
|
-
"activated": false,
|
224
|
-
|
225
|
-
}
|
226
|
-
|
227
|
-
}
|
228
|
-
|
229
|
-
```
|
230
|
-
|
231
|
-
### 該当のソースコード
|
232
|
-
|
233
|
-
account_activation_controller.rb
|
234
364
|
|
235
365
|
```ruby
|
236
366
|
|
237
|
-
class AccountActivationsController < ApplicationController
|
238
|
-
|
239
|
-
|
240
|
-
|
241
|
-
def edit
|
242
|
-
|
243
|
-
user = User.find_by(email: params[:email])
|
244
|
-
|
245
|
-
token = params[:token]
|
246
|
-
|
247
|
-
if user && !user.activated? && user.authenticated?(:activation, :token)
|
248
|
-
|
249
|
-
user.activate
|
250
|
-
|
251
|
-
log_in user
|
252
|
-
|
253
|
-
render json:{status:"Account activated!"}
|
254
|
-
|
255
|
-
else
|
256
|
-
|
257
|
-
render json:{status:"Invalid activation link"}
|
258
|
-
|
259
|
-
end
|
260
|
-
|
261
|
-
end
|
262
|
-
|
263
|
-
end
|
264
|
-
|
265
|
-
```
|
266
|
-
|
267
|
-
account_activation.text.erb
|
268
|
-
|
269
|
-
```erb
|
270
|
-
|
271
|
-
Hi <%= @user.user_name %>,
|
272
|
-
|
273
|
-
|
274
|
-
|
275
|
-
Welcome to the Sample App! Click on the link below to activate your account:
|
276
|
-
|
277
|
-
|
278
|
-
|
279
|
-
<%= edit_account_activation_url(@user,
|
280
|
-
|
281
|
-
token: @user.activation_token,
|
282
|
-
|
283
|
-
email: @user.email) %>
|
284
|
-
|
285
|
-
|
286
|
-
|
287
|
-
```
|
288
|
-
|
289
|
-
account_activation.html.erb
|
290
|
-
|
291
|
-
```erb
|
292
|
-
|
293
|
-
<h1>Sample App</h1>
|
294
|
-
|
295
|
-
|
296
|
-
|
297
|
-
<p>Hi <%= @user.user_name %>,</p>
|
298
|
-
|
299
|
-
|
300
|
-
|
301
|
-
<p>
|
302
|
-
|
303
|
-
Welcome to the Sample App! Click on the link below to activate your account:
|
304
|
-
|
305
|
-
</p>
|
306
|
-
|
307
|
-
|
308
|
-
|
309
|
-
<%= link_to "Activate", edit_account_activation_url(@user,
|
310
|
-
|
311
|
-
token: @user.activation_token,
|
312
|
-
|
313
|
-
email: @user.email) %>
|
314
|
-
|
315
|
-
|
316
|
-
|
317
|
-
```
|
318
|
-
|
319
|
-
user.rb
|
320
|
-
|
321
|
-
```ruby
|
322
|
-
|
323
367
|
class User < ApplicationRecord
|
324
368
|
|
325
369
|
attr_accessor :remember_token, :activation_token
|