Commit 6fff92e984c8977bb1b8d5424e8b81796e2ccb07

Authored by Dmitriy Zaporozhets
1 parent db7d1549

Enable confirmable and reconfirmable modules for User

Now when you want to signup or change existing email you will be forced
to confirm that you really own this email. You get email with link to
follow in order to confirm your email address

Conflicts:
	app/models/user.rb
app/models/user.rb
@@ -43,7 +43,7 @@ require 'file_size_validator' @@ -43,7 +43,7 @@ require 'file_size_validator'
43 43
44 class User < ActiveRecord::Base 44 class User < ActiveRecord::Base
45 devise :database_authenticatable, :token_authenticatable, :lockable, :async, 45 devise :database_authenticatable, :token_authenticatable, :lockable, :async,
46 - :recoverable, :rememberable, :trackable, :validatable, :omniauthable, :registerable 46 + :recoverable, :rememberable, :trackable, :validatable, :omniauthable, :confirmable, :registerable
47 47
48 attr_accessible :email, :password, :password_confirmation, :remember_me, :bio, :name, :username, 48 attr_accessible :email, :password, :password_confirmation, :remember_me, :bio, :name, :username,
49 :skype, :linkedin, :twitter, :color_scheme_id, :theme_id, :force_random_password, 49 :skype, :linkedin, :twitter, :color_scheme_id, :theme_id, :force_random_password,
@@ -398,4 +398,4 @@ class User &lt; ActiveRecord::Base @@ -398,4 +398,4 @@ class User &lt; ActiveRecord::Base
398 398
399 self 399 self
400 end 400 end
401 -end  
402 \ No newline at end of file 401 \ No newline at end of file
  402 +end
config/initializers/devise.rb
@@ -54,6 +54,8 @@ Devise.setup do |config| @@ -54,6 +54,8 @@ Devise.setup do |config|
54 # The realm used in Http Basic Authentication. "Application" by default. 54 # The realm used in Http Basic Authentication. "Application" by default.
55 # config.http_authentication_realm = "Application" 55 # config.http_authentication_realm = "Application"
56 56
  57 + config.reconfirmable = true
  58 +
57 # It will change confirmation, password recovery and other workflows 59 # It will change confirmation, password recovery and other workflows
58 # to behave the same regardless if the e-mail provided was right or wrong. 60 # to behave the same regardless if the e-mail provided was right or wrong.
59 # Does not affect registerable. 61 # Does not affect registerable.
db/migrate/20131009115346_add_confirmable_to_users.rb 0 → 100644
@@ -0,0 +1,15 @@ @@ -0,0 +1,15 @@
  1 +class AddConfirmableToUsers < ActiveRecord::Migration
  2 + def self.up
  3 + add_column :users, :confirmation_token, :string
  4 + add_column :users, :confirmed_at, :datetime
  5 + add_column :users, :confirmation_sent_at, :datetime
  6 + add_column :users, :unconfirmed_email, :string
  7 + add_index :users, :confirmation_token, unique: true
  8 + User.update_all(confirmed_at: Time.now)
  9 + end
  10 +
  11 + def self.down
  12 + remove_column :users, :confirmation_token, :confirmed_at, :confirmation_sent_at
  13 + remove_column :users, :unconfirmed_email
  14 + end
  15 +end
@@ -11,7 +11,7 @@ @@ -11,7 +11,7 @@
11 # 11 #
12 # It's strongly recommended to check this file into your version control system. 12 # It's strongly recommended to check this file into your version control system.
13 13
14 -ActiveRecord::Schema.define(:version => 20131005191208) do 14 +ActiveRecord::Schema.define(:version => 20131009115346) do
15 15
16 create_table "deploy_keys_projects", :force => true do |t| 16 create_table "deploy_keys_projects", :force => true do |t|
17 t.integer "deploy_key_id", :null => false 17 t.integer "deploy_key_id", :null => false
@@ -284,10 +284,15 @@ ActiveRecord::Schema.define(:version =&gt; 20131005191208) do @@ -284,10 +284,15 @@ ActiveRecord::Schema.define(:version =&gt; 20131005191208) do
284 t.datetime "password_expires_at" 284 t.datetime "password_expires_at"
285 t.integer "created_by_id" 285 t.integer "created_by_id"
286 t.string "avatar" 286 t.string "avatar"
  287 + t.string "confirmation_token"
  288 + t.datetime "confirmed_at"
  289 + t.datetime "confirmation_sent_at"
  290 + t.string "unconfirmed_email"
287 end 291 end
288 292
289 add_index "users", ["admin"], :name => "index_users_on_admin" 293 add_index "users", ["admin"], :name => "index_users_on_admin"
290 add_index "users", ["authentication_token"], :name => "index_users_on_authentication_token", :unique => true 294 add_index "users", ["authentication_token"], :name => "index_users_on_authentication_token", :unique => true
  295 + add_index "users", ["confirmation_token"], :name => "index_users_on_confirmation_token", :unique => true
291 add_index "users", ["email"], :name => "index_users_on_email", :unique => true 296 add_index "users", ["email"], :name => "index_users_on_email", :unique => true
292 add_index "users", ["extern_uid", "provider"], :name => "index_users_on_extern_uid_and_provider", :unique => true 297 add_index "users", ["extern_uid", "provider"], :name => "index_users_on_extern_uid_and_provider", :unique => true
293 add_index "users", ["name"], :name => "index_users_on_name" 298 add_index "users", ["name"], :name => "index_users_on_name"