質問編集履歴
5
説明を変更しました
title
CHANGED
|
File without changes
|
body
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
現在簡単なECサイトを作成しています。
|
|
2
|
-
|
|
2
|
+
メール送信によるパスワードリセットで新しいパスワードを入力したところ
|
|
3
3
|
|
|
4
4
|
パスワードリセット用トークンは不正な値です
|
|
5
5
|
|
4
変更しました
title
CHANGED
|
File without changes
|
body
CHANGED
|
@@ -20,7 +20,6 @@
|
|
|
20
20
|
Ruby:2.3.5
|
|
21
21
|
Ruby on Rails: 4.2.5
|
|
22
22
|
devise(gem):4.5.0
|
|
23
|
-
デプロイ先:AWS
|
|
24
23
|
確認ブラウザ:chrome、firefox
|
|
25
24
|
|
|
26
25
|
|
3
ルーティングを追加しました
title
CHANGED
|
File without changes
|
body
CHANGED
|
@@ -13,6 +13,9 @@
|
|
|
13
13
|
|
|
14
14
|
###期待する動作
|
|
15
15
|
パスワードリセットができるようになってほしい
|
|
16
|
+
|
|
17
|
+
### 疑問
|
|
18
|
+
- パスワード忘れによるリセットをしたいが下記のルーティングのedit_user_password_urlであっているのか?
|
|
16
19
|
###動作環境
|
|
17
20
|
Ruby:2.3.5
|
|
18
21
|
Ruby on Rails: 4.2.5
|
|
@@ -22,8 +25,26 @@
|
|
|
22
25
|
|
|
23
26
|
|
|
24
27
|
###試したこと
|
|
25
|
-
下記サイトの内容がそれっぽかったので変更をしてみましたがエラーは変わりませんでした。
|
|
26
28
|
[devise 新規登録時にパスワードリセットメールを送信したいのでやってみた](https://qiita.com/motty93/items/2862f1cb6daabe6e4c55)
|
|
29
|
+
rake routesコマンドで
|
|
30
|
+
```
|
|
31
|
+
new_user_session GET /users/sign_in(.:format) users/sessions#new
|
|
32
|
+
user_session POST /users/sign_in(.:format) users/sessions#create
|
|
33
|
+
destroy_user_session GET /users/sign_out(.:format) users/sessions#destroy
|
|
34
|
+
user_facebook_omniauth_authorize GET|POST /users/auth/facebook(.:format)
|
|
35
|
+
/users/omniauth_callbacks#passthru
|
|
36
|
+
user_facebook_omniauth_callback GET|POST /users/auth/facebook/callback(.:format) users/omniauth_callbacks#facebook
|
|
37
|
+
user_google_omniauth_authorize GET|POST /users/auth/google(.:format) users/omniauth_callbacks#passthru
|
|
38
|
+
user_google_omniauth_callback GET|POST /users/auth/google/callback(.:format) users/omniauth_callbacks#google
|
|
39
|
+
user_password POST /users/password(.:format) users/passwords#create
|
|
40
|
+
new_user_password GET /users/password/new(.:format) users/passwords#new
|
|
41
|
+
edit_user_password GET /users/password/edit(.:format) users/passwords#edit
|
|
42
|
+
PATCH /users/password(.:format) users/passwords#update
|
|
43
|
+
PUT /users/password(.:format) users/passwords#update
|
|
44
|
+
cancel_user_registration GET /users/cancel(.:format) users/registrations#cancel
|
|
45
|
+
```
|
|
46
|
+
で確認し、`reset_password_instructions.html.erb`を変更してみましたが変わりませんでした。
|
|
47
|
+
|
|
27
48
|
###関係ありそうなソースコード
|
|
28
49
|
reset_password_instructions.html.erb
|
|
29
50
|
```ruby
|
2
修正を加えました
title
CHANGED
|
File without changes
|
body
CHANGED
|
@@ -6,13 +6,11 @@
|
|
|
6
6
|
とでてパスワードのリセットがうまくいきません(m_ _m)
|
|
7
7
|
わかる方がいらっしゃれば教えていただきますようよろしくお願いいたします(m_ _m)
|
|
8
8
|
|
|
9
|
-
ちなみにdeviseで既存のコードを変更した部分はdestroyアクションになります(退会処理を変更するため)
|
|
10
9
|
|
|
11
10
|
###エラー内容
|
|
12
11
|
メール送信によるパスワードリセットがうまくいかない
|
|
12
|
+

|
|
13
13
|
|
|
14
|
-
※firefoxでの「要素を調査」の該当部分
|
|
15
|
-

|
|
16
14
|
###期待する動作
|
|
17
15
|
パスワードリセットができるようになってほしい
|
|
18
16
|
###動作環境
|
|
@@ -21,20 +19,16 @@
|
|
|
21
19
|
devise(gem):4.5.0
|
|
22
20
|
デプロイ先:AWS
|
|
23
21
|
確認ブラウザ:chrome、firefox
|
|
24
|
-
###参考サイト
|
|
25
|
-
[Rails 4 + Devise: Password Reset is always giving a “Token is invalid” error on the production server, but works fine locally.](https://stackoverflow.com/questions/19018657/rails-4-devise-password-reset-is-always-giving-a-token-is-invalid-error-on)
|
|
26
22
|
|
|
27
|
-
|
|
23
|
+
|
|
28
|
-
↗︎
|
|
29
|
-
こちらは修正する場所がわからず何もしていません
|
|
30
24
|
###試したこと
|
|
31
|
-
|
|
25
|
+
下記サイトの内容がそれっぽかったので変更をしてみましたがエラーは変わりませんでした。
|
|
32
|
-
|
|
26
|
+
[devise 新規登録時にパスワードリセットメールを送信したいのでやってみた](https://qiita.com/motty93/items/2862f1cb6daabe6e4c55)
|
|
33
27
|
###関係ありそうなソースコード
|
|
34
|
-
|
|
28
|
+
reset_password_instructions.html.erb
|
|
35
29
|
```ruby
|
|
36
30
|
<p>Hello <%= @resource.email %>!</p>
|
|
37
|
-
<p><%= link_to 'Change my password',
|
|
31
|
+
<p><%= link_to 'Change my password', edit_user_password_url(@resource, reset_password_token: @token) %></p>
|
|
38
32
|
|
|
39
33
|
```
|
|
40
34
|
|
|
@@ -55,65 +49,8 @@
|
|
|
55
49
|
```ruby
|
|
56
50
|
#app/model/user.erb
|
|
57
51
|
class User < ActiveRecord::Base
|
|
58
|
-
# Include default devise modules. Others available are:
|
|
59
|
-
# :confirmable, :lockable, :timeoutable and :omniauthable
|
|
60
52
|
devise :database_authenticatable, :registerable,
|
|
61
53
|
:recoverable, :rememberable, :trackable, :validatable, :confirmable, :omniauthable
|
|
62
|
-
|
|
63
|
-
# logical-delete user
|
|
64
|
-
def logical_delete
|
|
65
|
-
update_attribute(:soft_destroyed_at, Time.current)
|
|
66
|
-
|
|
67
|
-
new_email = Time.current.to_s + '_' + self.email.to_s
|
|
68
|
-
self.skip_reconfirmation!
|
|
69
|
-
self.update_attribute(:email, new_email)
|
|
70
|
-
|
|
71
|
-
unless self.uid.blank?
|
|
72
|
-
uid = self.uid + '_' + Time.current.to_s
|
|
73
|
-
self.update_attribute(:uid, uid)
|
|
74
|
-
end
|
|
75
|
-
end
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
def self.find_for_oauth(auth)
|
|
79
|
-
user = User.where(uid: auth.uid, provider: auth.provider).first
|
|
80
|
-
|
|
81
|
-
unless user
|
|
82
|
-
user = User.create(
|
|
83
|
-
uid: auth.uid,
|
|
84
|
-
provider: auth.provider,
|
|
85
|
-
email: User.dummy_email(auth),
|
|
86
|
-
password: Devise.friendly_token[0, 20]
|
|
87
|
-
|
|
54
|
+
.
|
|
88
|
-
|
|
55
|
+
.
|
|
89
|
-
|
|
90
|
-
user
|
|
91
|
-
end
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
private
|
|
96
|
-
def self.dummy_email(auth)
|
|
97
|
-
"#{auth.uid}-#{auth.provider}@example.com"
|
|
98
|
-
end
|
|
99
|
-
end
|
|
100
|
-
```
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
app/controllers/public/settings/users/registrations_controller.rb
|
|
104
|
-
```ruby
|
|
105
|
-
# frozen_string_literal: true
|
|
106
|
-
|
|
107
|
-
class Public::Settings::Users::RegistrationsController < Devise::RegistrationsController
|
|
108
|
-
|
|
109
|
-
# DELETE /resource
|
|
110
|
-
def destroy
|
|
111
|
-
# super
|
|
112
|
-
resource.logical_delete
|
|
113
|
-
|
|
114
|
-
Devise.sign_out_all_scopes ? sign_out : sign_out(resource_name)
|
|
115
|
-
|
|
116
|
-
redirect_to root_path
|
|
117
|
-
end
|
|
118
|
-
end
|
|
119
56
|
```
|
1
参考サイトの記述を少し変更しました
title
CHANGED
|
File without changes
|
body
CHANGED
|
@@ -25,9 +25,10 @@
|
|
|
25
25
|
[Rails 4 + Devise: Password Reset is always giving a “Token is invalid” error on the production server, but works fine locally.](https://stackoverflow.com/questions/19018657/rails-4-devise-password-reset-is-always-giving-a-token-is-invalid-error-on)
|
|
26
26
|
|
|
27
27
|
[reset_password_token(invitation_token)が上書きされてまう、Mac Sierra Safariで!](https://qiita.com/kshimadutsu/items/ed3ae8dd10f67997cb7d)
|
|
28
|
-
|
|
28
|
+
↗︎
|
|
29
|
+
こちらは修正する場所がわからず何もしていません
|
|
29
30
|
###試したこと
|
|
30
|
-
上記サイトの通り変更をしてみましたが
|
|
31
|
+
上記サイトの通り変更をしてみましたがエラーは変わりませんでした。
|
|
31
32
|
|
|
32
33
|
###関係ありそうなソースコード
|
|
33
34
|
app/views/public/settings/users/mailer/reset_password_instructions.html.erb
|