设计:无法登录(401 Unauthorized)

时间:2013-07-15 13:09:36

标签: ruby-on-rails devise

我已经使用Devise 2.2.4安装了Rails 3.2.13。我使用了默认的Devise设置(除了config.mail_sender),从erb到slim的转换视图,仅此而已。现在我有一个奇怪的错误:用户可以注册,可以恢复密码,但无法登录!

日志:

Started POST "/users/sign_in" for 188.186.102.147 at 2013-07-14 17:58:42 +0400
Processing by Devise::SessionsController#create as HTML
  Parameters: {"utf8"=>"✓", "authenticity_token"=>"eqZ9zAUWn+blmhNMTi3iqhjX9ac1N8EaXpqNMyp/fYw=", "user"=>{"email"=>"ertaquo@gmail.com", "password"=>"[FILTERED]", "remember_me"=>"1"}, "commit"=>"Войти"}
Completed 401 Unauthorized in 1ms
Processing by Devise::SessionsController#new as HTML
  Parameters: {"utf8"=>"✓", "authenticity_token"=>"eqZ9zAUWn+blmhNMTi3iqhjX9ac1N8EaXpqNMyp/fYw=", "user"=>{"email"=>"ertaquo@gmail.com", "password"=>"[FILTERED]", "remember_me"=>"1"}, "commit"=>"Войти"}
  Rendered devise/shared/_links.slim (3.8ms)
  Rendered devise/sessions/new.html.slim within layouts/application (59.6ms)
Completed 200 OK in 208ms (Views: 83.6ms | ActiveRecord: 1.4ms)

配置/初始化/ devise.rb:

Devise.setup do |config|
  config.mailer_sender = "robot@nizarium.com"

  require 'devise/orm/active_record'

  config.case_insensitive_keys = [ :email ]
  config.strip_whitespace_keys = [ :email ]
  config.skip_session_storage = [:http_auth]
  config.stretches = Rails.env.test? ? 1 : 10
  config.reconfirmable = true
  config.password_length = 8..128
  config.reset_password_within = 6.hours
  config.sign_out_via = :delete
end

型号:

class User < ActiveRecord::Base
  devise :database_authenticatable, :registerable,
         :recoverable, :rememberable, :trackable, :validatable

  attr_accessible :email, :password, :password_confirmation, :remember_me
end

转储用户表:

CREATE TABLE `users` (
  `id` int(11) NOT NULL AUTO_INCREMENT,
  `email` varchar(255) COLLATE utf8_unicode_ci NOT NULL DEFAULT '',
  `encrypted_password` varchar(255) COLLATE utf8_unicode_ci NOT NULL DEFAULT '',
  `reset_password_token` varchar(255) COLLATE utf8_unicode_ci DEFAULT NULL,
  `reset_password_sent_at` datetime DEFAULT NULL,
  `remember_created_at` datetime DEFAULT NULL,
  `sign_in_count` int(11) DEFAULT '0',
  `current_sign_in_at` datetime DEFAULT NULL,
  `last_sign_in_at` datetime DEFAULT NULL,
  `current_sign_in_ip` varchar(255) COLLATE utf8_unicode_ci DEFAULT NULL,
  `last_sign_in_ip` varchar(255) COLLATE utf8_unicode_ci DEFAULT NULL,
  `created_at` datetime NOT NULL,
  `updated_at` datetime NOT NULL,
  PRIMARY KEY (`id`),
  UNIQUE KEY `index_users_on_email` (`email`),
  UNIQUE KEY `index_users_on_reset_password_token` (`reset_password_token`)
) ENGINE=MyISAM AUTO_INCREMENT=2 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;

LOCK TABLES `users` WRITE;
INSERT INTO `users` VALUES (1,'ertaquo@gmail.com','$2a$10$tLC/NVBIa3cyI0HkiaZ7O.oXKTZ/jVm/L8jDMsSQ27CzNWcefWkCm',NULL,NULL,NULL,2,'2013-07-14 15:49:29','2013-07-14 12:37:07','188.186.102.147','188.186.102.147','2013-07-14 12:37:07','2013-07-14 15:49:29');
UNLOCK TABLES;

有人可以帮忙吗?

2 个答案:

答案 0 :(得分:7)

好的,所以我已经为我的问题解决了这个问题。我的错误也是第一位的。一些事情

<p class="notice"><%= notice %></p>
<p class="alert"><%= alert %></p>

当我尝试构建自己的登录表单时,我已从布局中的会话/新视图中删除了这些行。因此,当我在安装我的应用程序时从我的rake任务插入管理员和密码时,我没有得到该帐户尚未确认或密码,用户名不正确的指示。

一旦我添加了这些行,感谢solution found here我能够看到我使用了错误的电子邮件地址,因为我是一个血腥的菜鸟。

答案 1 :(得分:-5)

解决:我已经用Devise安装了Rails 4,没有这样的问题。