设计:突然不能登录了 [英] Devise: Suddenly cannot log in anymore

查看:112
本文介绍了设计:突然不能登录了的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用Devise 1.3.4来验证我的应用程序中的后端。
现在几天了,我不能登录了。
发生的情况是:

I'm using Devise 1.3.4 for authentication for the backend in my app. For a couple of days now I cannot log in anymore. What happens is:


  • 我去登录页面/ admin / sign_in

  • 登录有良好的凭据

  • 在日志中看到登录工作(last_sign_in_at,current_sign_in_at和current_sign_in_ip已设置,sign_in_count增加)

  • 设计会话控制器尝试将我转发到我在应用程序控制器(Admin :: DashboardsController#show)中指定的after_sign_in_path_for

  • 然后突然显示登录页面。没有重定向,没有任何东西。

  • I go to the login page /admin/sign_in
  • Log in with good credentials
  • See in the log that the login worked (last_sign_in_at, current_sign_in_at and current_sign_in_ip are set, sign_in_count is increased)
  • Devise sessions controller tries to forward me to the after_sign_in_path_for I specified in my application controller (Admin::DashboardsController#show)
  • Then suddenly the sign in page is rendered again. No redirect, no nothing.

我检查了before_filters,它绝对是Devise的autorize_admin_user!过滤器导致问题(调用它之前的过滤器,不调用之后的过滤器)。这意味着即使登录成功,它也不会将我认定为登录。

I checked the before_filters and it definitely is Devise's autorize_admin_user! filter that causes the problems (filters before it are called, filters after it are not called). Meaning that even after logging in successfully it doesn't recognize me as logged in.

我意识到,很难找到解决方案,而不会看到我的大部分代码。
所以我的第一个问题是:

I realize that it is hard to come up with a solution without seeing most of my code. So my first question would be:

我如何调试这个错误?
如何回溯到哪里,登录不正常?我要去监狱长吗?
它可以是会话/ cookie问题吗?如何调试?

How can I debug this error? How can I retrace where exactly the login doesn't work? Do I have to dig in to Warden? Can it be a session/cookie problem? How could I debug that?

所有想法都赞赏!

这是日志说的:

Started GET "/admin/sign_in" for 127.0.0.1 at 2011-05-20 13:49:11 +0200
[Barista] Compiling all scripts for barista
[Barista] Compiling all coffeescripts
  Processing by Admin::SessionsController#new as HTML
Rendered admin/shared/_header.html.haml (3.1ms)
Rendered admin/shared/_menu.html.haml (1.7ms)
Rendered admin/sessions/new.html.haml within layouts/admin (128.7ms)
Completed 200 OK in 171ms (Views: 133.0ms | ActiveRecord: 0.0ms)


Started POST "/admin/sign_in" for 127.0.0.1 at 2011-05-20 13:49:15 +0200
[Barista] Compiling all scripts for barista
[Barista] Compiling all coffeescripts
  Processing by Admin::SessionsController#create as HTML
  Parameters: {"utf8"=>"✓", "authenticity_token"=>"VLjjo6W+sd7yRH3SRSNpUN3L8a+OaOgCUpJgB5VaGEM=", "admin_user"=>{"email"=>"my@email.com", "password"=>"[FILTERED]", "remember_me"=>"0"}, "commit"=>"Sign in"}
  AdminUser Load (0.7ms)  SELECT `admin_users`.* FROM `admin_users` WHERE `admin_users`.`email` = 'admin3@gmail.com' LIMIT 1
  SQL (0.2ms)  BEGIN
  AREL (0.3ms)  UPDATE `admin_users` SET `last_sign_in_at` = '2011-05-20 11:49:15', `current_sign_in_at` = '2011-05-20 11:49:15', `current_sign_in_ip` = '127.0.0.1', `sign_in_count` = 3, `updated_at` = '2011-05-20 11:49:15' WHERE `admin_users`.`id` = 33
  SQL (0.5ms)  COMMIT
Redirected to http://myapp.dev/admin
Completed 302 Found in 160ms


Started GET "/admin" for 127.0.0.1 at 2011-05-20 13:49:15 +0200
[Barista] Compiling all scripts for barista
[Barista] Compiling all coffeescripts
  Processing by Admin::DashboardsController#show as HTML
Completed   in 26ms


Started GET "/admin/sign_in" for 127.0.0.1 at 2011-05-20 13:49:16 +0200
[Barista] Compiling all scripts for barista
[Barista] Compiling all coffeescripts
  Processing by Admin::SessionsController#new as HTML
Rendered admin/shared/_header.html.haml (3.5ms)
Rendered admin/shared/_menu.html.haml (2.0ms)
Rendered admin/sessions/new.html.haml within layouts/admin (134.9ms)
Completed 200 OK in 182ms (Views: 139.2ms | ActiveRecord: 0.0ms)


推荐答案

愚蠢的我终于找到了答案。

Okay, after 2 days of fumbling around I finally found the answer.

另一个错误同时出现,但首先我没有建立连接。
错误是当用户想要注销时,Devise尝试删除会话cookie,并使用会话存储的配置来查找我的应用程序存储会话cookie的位置。
现在我使用app config,如 redis-store 用于我的会话。我的会话存储配置看起来像这样

Another error appeared simultaneously but first I didn't make a connection. The error was that when a user wanted to log out, Devise tried to delete a session cookie and used the configuration for my session store to find out where my app stores session cookies. Now I use a "app config" like this and redis-store for my sessions. My session store configuration looked like this

MyApp::Application.config.session_store :redis_session_store, AppConfig.redis

AppConfig.redis看起来像

AppConfig.redis looks something like

{ :port => 123, :namespace => 'foo' }

这个问题是 AppConfig.redis 是一个 ActiveSupport :: HashWithIndifferentAccess ,而不是 Hash 。在某些时候有人试图在其上调用 symbolize_keys!,因为 ActiveSupport :: HashWithIndifferentAccess 没有方法。

Problem with this is that AppConfig.redis is a ActiveSupport::HashWithIndifferentAccess, not a Hash. At some point someone tries to call symbolize_keys! on it and it fails because ActiveSupport::HashWithIndifferentAccess doesn't have that method.

长篇小说:我将AppConfig.redis 更改为 AppConfig.redis。 to_hash ,一切都开始工作了。显然阻止我登录的问题是我的用户的会话cookie仍然存在。 (还有人有更好的解释吗?)仍然很奇怪,Devise不会抛出正确的例外,也不会覆盖会话cookie。

Long story short: I changed AppConfig.redis to AppConfig.redis.to_hash and everything started working again. The problem that prevented me from logging in apparently was that a session cookie for my user still existed. (Or does anybody have a better explanation?). Still weird that Devise doesn't either throw a proper exception or just overwrites the sessions cookie.

这篇关于设计:突然不能登录了的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆