How to make Devise lockable with number of failed attempts

后端 未结 2 937
眼角桃花
眼角桃花 2020-12-05 00:17

Using Devise 2.1.2 and Rails 3.2.6

I\'m doing this Q&A just in case others run into this problem because I found little and scattered documentation for it.

相关标签:
2条回答
  • 2020-12-05 00:31

    Devise needs these three attributes on your model. Therefore, generate the following migration and run it.

    class AddLockableToExamples < ActiveRecord::Migration
      def change
        add_column :examples, :failed_attempts, :integer, default: 0
        add_column :examples, :unlock_token, :string # Only if unlock strategy is :email or :both
        add_column :examples, :locked_at, :datetime
      end
    end
    

    Hope this saves someone else hours of google-fu.

    0 讨论(0)
  • 2020-12-05 00:41

    Simply uncomment this strings in devise migration:

      ## Lockable
      # t.integer  :failed_attempts, :default => 0 # Only if lock strategy is :failed_attempts
      # t.string   :unlock_token # Only if unlock strategy is :email or :both
      # t.datetime :locked_at
    
    0 讨论(0)
提交回复
热议问题