From 8b252d8c14e6e4c47512e31bd4cdbca9882f316f Mon Sep 17 00:00:00 2001 From: Pavel Chipiga Date: Wed, 21 Mar 2012 15:37:16 +0200 Subject: [PATCH] Add and tune devise lockable strategy. Refs #270 --- app/models/user.rb | 2 +- db/migrate/20120321130436_add_devise_lockable.rb | 8 ++++++++ db/schema.rb | 14 +++++++++----- 3 files changed, 18 insertions(+), 6 deletions(-) create mode 100644 db/migrate/20120321130436_add_devise_lockable.rb diff --git a/app/models/user.rb b/app/models/user.rb index cd21449e2..b94dfb0ad 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -14,7 +14,7 @@ class User < ActiveRecord::Base validates_inclusion_of :avatar_file_size, :in => (0..MAX_AVATAR_SIZE), :allow_nil => true devise :database_authenticatable, :registerable, #:omniauthable, # :token_authenticatable, :encryptable, :timeoutable - :recoverable, :rememberable, :validatable #, :trackable, :confirmable, :lockable + :recoverable, :rememberable, :validatable, :lockable #, :trackable, :confirmable has_one :notifier, :class_name => 'Settings::Notifier', :dependent => :destroy #:notifier diff --git a/db/migrate/20120321130436_add_devise_lockable.rb b/db/migrate/20120321130436_add_devise_lockable.rb new file mode 100644 index 000000000..0d242536d --- /dev/null +++ b/db/migrate/20120321130436_add_devise_lockable.rb @@ -0,0 +1,8 @@ +class AddDeviseLockable < ActiveRecord::Migration + def change + add_column :users, :failed_attempts, :integer, :default => 0 # Only if lock strategy is :failed_attempts + add_column :users, :unlock_token, :string # Only if unlock strategy is :email or :both + add_column :users, :locked_at, :datetime + add_index :users, :unlock_token, :unique => true + end +end diff --git a/db/schema.rb b/db/schema.rb index 6d149f5f6..b145fe88c 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -11,14 +11,14 @@ # # It's strongly recommended to check this file into your version control system. -ActiveRecord::Schema.define(:version => 20120320102912) do +ActiveRecord::Schema.define(:version => 20120321130436) do create_table "activity_feeds", :force => true do |t| t.integer "user_id", :null => false t.string "kind" t.text "data" - t.datetime "created_at" - t.datetime "updated_at" + t.datetime "created_at", :null => false + t.datetime "updated_at", :null => false end create_table "arches", :force => true do |t| @@ -370,16 +370,16 @@ ActiveRecord::Schema.define(:version => 20120320102912) do t.string "name" t.string "email", :default => "", :null => false t.string "encrypted_password", :limit => 128, :default => "", :null => false - t.string "password_salt", :default => "", :null => false t.string "reset_password_token" t.datetime "remember_created_at" t.datetime "created_at" t.datetime "updated_at" + t.text "ssh_key" t.string "uname" t.string "role" t.string "language", :default => "en" - t.integer "own_projects_count", :default => 0, :null => false t.datetime "reset_password_sent_at" + t.integer "own_projects_count", :default => 0, :null => false t.text "professional_experience" t.string "site" t.string "company" @@ -388,10 +388,14 @@ ActiveRecord::Schema.define(:version => 20120320102912) do t.string "avatar_content_type" t.integer "avatar_file_size" t.datetime "avatar_updated_at" + t.integer "failed_attempts", :default => 0 + t.string "unlock_token" + t.datetime "locked_at" end add_index "users", ["email"], :name => "index_users_on_email", :unique => true add_index "users", ["reset_password_token"], :name => "index_users_on_reset_password_token", :unique => true add_index "users", ["uname"], :name => "index_users_on_uname", :unique => true + add_index "users", ["unlock_token"], :name => "index_users_on_unlock_token", :unique => true end