0

我在恢复新密码时遇到问题。我已经设置了邮件程序,并且可以正常接收密码说明。当我单击电子邮件中的重置密码链接时,我可以正常进入更改新密码页面。但是,当我输入新密码时,我得到一个“请检查以下问题”,没有错误,并且密码没有更改。

当我检查日志时,我看到:

2013-10-08T17:10:35.118663+00:00 app[web.1]: Started PUT "/users/password" for 24.87.52.189 at 2013-10-08 17:10:35 +0000
2013-10-08T17:10:35.354246+00:00 app[web.1]: Processing by Devise::PasswordsController#update as HTML
2013-10-08T17:10:35.354246+00:00 app[web.1]:   Parameters: {"utf8"=>"✓", "authenticity_token"=>"7LQ4VtOfwDZTV2tw4YwPoj8sqD6UGeCd5NvQkdANrH0=", "user"=>{"reset_password_token"=>"    [FILTERED]", "password"=>"[FILTERED]", "password_confirmation"=>"[FILTERED]"}, "commit"=>"Change my password"}
2013-10-08T17:10:35.354246+00:00 app[web.1]:   Rendered devise/shared/_links.erb (0.4ms)
2013-10-08T17:10:35.354246+00:00 app[web.1]:   Rendered devise/passwords/edit.html.erb within layouts/application (5.2ms)
2013-10-08T17:10:35.354246+00:00 app[web.1]:   Rendered layouts/_shim.html.erb (0.0ms)
2013-10-08T17:10:35.354246+00:00 app[web.1]:   Rendered layouts/_footer.html.erb (0.6ms)
2013-10-08T17:10:35.354246+00:00 app[web.1]: Completed 200 OK in 232ms (Views: 8.9ms | ActiveRecord: 0.0ms)
2013-10-08T17:10:35.741022+00:00 heroku[router]: at=info method=GET path=/users/password host=skalefree.net fwd="24.87.52.189" dyno=web.1 connect=1ms service=20ms status=302 bytes=101
2013-10-08T17:10:35.725344+00:00 app[web.1]: Started GET "/users/password" for 24.87.52.189 at 2013-10-08 17:10:35 +0000
2013-10-08T17:10:35.883843+00:00 app[web.1]:   Rendered devise/sessions/new.html.erb within layouts/application (9.6ms)
2013-10-08T17:10:35.883843+00:00 app[web.1]:   Rendered layouts/_shim.html.erb (0.0ms)
2013-10-08T17:10:35.883843+00:00 app[web.1]:   Rendered layouts/_header.html.erb (1.3ms)
2013-10-08T17:10:35.883843+00:00 app[web.1]:   Rendered layouts/_footer.html.erb (1.0ms)
2013-10-08T17:10:35.883843+00:00 app[web.1]: Completed 200 OK in 23ms (Views: 19.6ms | ActiveRecord: 0.0ms)
2013-10-08T17:10:35.354246+00:00 app[web.1]:   Rendered layouts/_header.html.erb (0.9ms)
2013-10-08T17:10:35.735631+00:00 app[web.1]:   Parameters: {"id"=>"password"}
2013-10-08T17:10:35.883843+00:00 app[web.1]: Processing by Devise::SessionsController#new as */*
**2013-10-08T17:10:35.735631+00:00 app[web.1]: Completed 401 Unauthorized in 3ms**
2013-10-08T17:10:35.735631+00:00 app[web.1]: Processing by UsersController#show as */*
2013-10-08T17:10:35.883843+00:00 app[web.1]:   Rendered devise/shared/_links.erb (0.5ms)
2013-10-08T17:10:35.856371+00:00 app[web.1]: Started GET "/users/sign_in" for 24.87.52.189 at 2013-10-08    17:10:35 +0000
2013-10-08T17:09:38.753083+00:00 heroku[router]: at=info method=GET path=/users/sign_in host=www.skalefree.net fwd="24.87.52.189" dyno=web.1 connect=14ms service=45ms status=200 bytes=3688
2013-10-08T17:10:35.892408+00:00 heroku[router]: at=info method=GET path=/users/sign_in host=skalefree.net fwd="24.87.52.189" dyno=web.1 connect=2ms service=40ms status=200 bytes=3783

如您所见,我在那里有一个未经授权的 301。有谁知道这个问题的解决方案?

这是我的路线:

devise_for :users, skip: :registrations

devise_scope :user do

  resource :registration,

  only: [:new, :create, :edit, :update],

  path: 'users',

  path_names: { new: 'sign_up' },

  controller: 'devise/registrations',

  as: :user_registration do

    get :cancel

  end

end

我的用户模型:

devise :database_authenticatable, :registerable, :recoverable, :rememberable, :trackable, :validatable

还有我的初始化程序:

config.reset_password_keys = [ :email ]

在此先感谢您的帮助!

4

1 回答 1

0

未经授权的看起来像是来自:

Started GET "/users/password" for 24.87.52.189 at 2013-10-08 17:10:35 +0000
...
   Parameters: {"id"=>"password"}

并且没有用户具有 :id 密码或类似的密码。这基本上意味着它没有正确重定向,或者你正在覆盖某些东西。时间表应如下所示:

输入电子邮件地址并单击发送说明按钮:

Started POST "/users/password" for 127.0.0.1 at 2013-10-08 14:22:02 -0400
Processing by Devise::PasswordsController#create as HTML

单击电子邮件中的链接以重置密码:

Started GET "/users/password/edit?reset_password_token=[FILTERED]" for 127.0.0.1 at 2013-10-08 14:22:19 -0400
Processing by Devise::PasswordsController#edit as HTML

提交带有密码和确认的表格:

Started PUT "/users/password" for 127.0.0.1 at 2013-10-08 14:22:24 -0400
Processing by Devise::PasswordsController#update as HTML
...
Redirected to <some-url-here>
Completed 302 Found in 243ms (ActiveRecord: 6.9ms)

看起来您在密码控制器中的更新方法没有重定向。查看after_sign_in_path_for将应用程序控制器中的方法设置为不是设计路径的路径是否可以修复它:

def after_sign_in_path_for(user)
  some_path
end
于 2013-10-08T18:31:42.080 回答