Devise :: PasswordExpiredController#update

时间:2018-10-25 22:00:08

标签: devise

Rails 3.2

我将Devise与devise_security_extension gem一起使用。

I am working on Rails application, using Devise for User management. The new requirement, is to add some rules, to 

我在Gemfile中添加了以下内容:

gem 'devise_security_extension', '0.10.0'

在我的config / initializers / devise.rb文件中,添加了以下内容:

config.expire_password_after = 3.months
config.password_regex= /^(?=.*?[A-Z])(?=.*?[a-z])(?=.*?[0-9])(?=.*?[#?!@$%^&*-]).{8,70}$/
config.password_archiving_count = 6
config.deny_old_passwords = true
config.expire_after = 3.months
config.timeout_in = 15.minutes
config.expire_auth_token_on_timeout = true

我修改了我的模型/user.rb,并将以下内容添加到attr_accessible部分:

:expired_at, :password_changed_at, :last_activity_at, :unique_session_id

然后我执行以下操作:

bundle install
rails generate devise_security_extension:install

我还添加了以下两个迁移:

class CreateOldPasswordsTable < ActiveRecord::Migration
  create_table :old_passwords do |t|
    t.string :encrypted_password, :null => false
    t.string :password_archivable_type, :null => false
    t.integer :password_archivable_id, :null => false
    t.datetime :created_at
  end
  add_index :old_passwords, [:password_archivable_type, :password_archivable_id], :name => :index_password_archivable
end

class AddDeviseSecurityExtensionFieldsToUser < ActiveRecord::Migration
  def change
    add_column :users, :password_changed_at, :datetime
    add_index :users, :password_changed_at
    add_column :users, :unique_session_id, :string, :limit => 20
    add_column :users, :last_activity_at, :datetime
    add_index :users, :last_activity_at
    add_column :users, :expired_at, :datetime
    add_index :users, :expired_at
  end
end

我进行了迁移,并验证了表old_passwords是creta的,并且其他列在users表中。

然后我编译资源,等等。

我启动了该应用程序,然后注销了。当我尝试重新登录时,收到一条消息,提示我密码已过期,并显示用于更改密码的表单。我填写了它,然后单击“更改我的密码”列,并收到以下错误:

Mysql2::Error: Column 'encrypted_password' cannot be null: INSERT INTO `old_passwords` (`created_at`, `encrypted_password`, `password_archivable_id`, `password_archivable_type`) VALUES ('2018-10-25 21:31:20', NULL, 13945325101939907, 'User')

请求的参数(来自错误日志):

Request
Parameters:

{"utf8"=>"✓",
 "_method"=>"put",
 "authenticity_token"=>"L0f17SGVlX63/bNnrc4t6PxeWoQMwp2loi9BZLricJE=",
 "user"=>{"current_password"=>"[FILTERED]",
 "password"=>"[FILTERED]",
 "password_confirmation"=>"[FILTERED]"},
 "commit"=>"Change my password"}

因此,很明显,encrtypted_pa​​ssword为null,并且该字段不能为null。

有什么想法吗?

0 个答案:

没有答案