From 6253955ab9186542ebc35c1e9579942331cd5e69 Mon Sep 17 00:00:00 2001 From: yasushiito Date: Thu, 11 Jun 2015 15:33:15 +0900 Subject: [PATCH] upgrade devise to 3 --- Gemfile | 3 +- app/models/admin.rb | 4 +-- app/models/demand_user.rb | 3 +- app/models/user.rb | 2 +- config/initializers/devise.rb | 6 ++-- config/locales/devise.en.yml | 5 +-- db/migrate/20111206092734_devise_create_admins.rb | 38 ++++++++++++++++++---- db/migrate/20120306231650_devise_create_users.rb | 37 +++++++++++++++++---- .../20121123051900_devise_create_demand_users.rb | 37 +++++++++++++++++---- 9 files changed, 103 insertions(+), 32 deletions(-) diff --git a/Gemfile b/Gemfile index 90b68a20..8951587d 100644 --- a/Gemfile +++ b/Gemfile @@ -1,7 +1,8 @@ source 'https://rubygems.org' gem 'rails', '~> 3.2.0' -gem 'devise', '=1.5.2' +gem 'devise' +# gem 'devise_token_auth' gem 'rest-client' gem 'underscore-rails' # gem 'backbone-rails' diff --git a/app/models/admin.rb b/app/models/admin.rb index abff349e..0788a942 100644 --- a/app/models/admin.rb +++ b/app/models/admin.rb @@ -2,12 +2,12 @@ class Admin < ActiveRecord::Base # Include default devise modules. Others available are: # , :encryptable, :lockable, :timeoutable and :omniauthable, :confirmable devise :database_authenticatable, :registerable, - :recoverable, :rememberable, :trackable, :validatable, :token_authenticatable + :recoverable, :rememberable, :trackable, :validatable # Setup accessible (or protected) attributes for your model attr_accessible :email, :password, :password_confirmation, :remember_me - def active_for_authentication? + def active_for_authentication? super && (self.approve == 1) end diff --git a/app/models/demand_user.rb b/app/models/demand_user.rb index 64fe0939..6c2a2c02 100644 --- a/app/models/demand_user.rb +++ b/app/models/demand_user.rb @@ -4,8 +4,7 @@ class DemandUser < ActiveRecord::Base # Include default devise modules. Others available are: # :encryptable, :confirmable, :lockable, :timeoutable and :omniauthable devise :database_authenticatable, :registerable, - :recoverable, :rememberable, :trackable, :validatable, :token_authenticatable - + :recoverable, :rememberable, :trackable, :validatable # Setup accessible (or protected) attributes for your model attr_accessible :email, :password, :password_confirmation, :remember_me diff --git a/app/models/user.rb b/app/models/user.rb index d59f35e4..20c2250d 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -5,7 +5,7 @@ class User < ActiveRecord::Base # Include default devise modules. Others available are: # :token_authenticatable, :encryptable, :confirmable, :lockable, :timeoutable and :omniauthable devise :database_authenticatable, :registerable, - :recoverable, :rememberable, :trackable, :token_authenticatable, :validatable#, :confirmable + :recoverable, :rememberable, :trackable, :validatable#, :confirmable # Setup accessible (or protected) attributes for your model attr_accessible :id, :name, :password, :password_confirmation, :remember_me , :email diff --git a/config/initializers/devise.rb b/config/initializers/devise.rb index 196e97d5..33a6b793 100644 --- a/config/initializers/devise.rb +++ b/config/initializers/devise.rb @@ -6,7 +6,7 @@ Devise.setup do |config| # note that it will be overwritten if you use your own mailer class with default "from" parameter. config.mailer_sender = "please-change-me-at-config-initializers-devise@example.com" config.sign_out_via = :get - + config.secret_key = 'ef21afb7caa18dd6b587e999417c281dbcafdfa132cdb38d08bd4150b763bda62bd5739df69d0d85f514f970608e2efff7fe92a5543ca546ce614ee188bc0177' # Configure the class responsible to send e-mails. # config.mailer = "Devise::Mailer" @@ -95,7 +95,7 @@ config.sign_out_via = :get # If true, uses the password salt as remember token. This should be turned # to false if you are not using database authenticatable. - config.use_salt_as_remember_token = true + # config.use_salt_as_remember_token = true # Options to be passed to the created cookie. For instance, you can set # :secure => true in order to force SSL only cookies. @@ -158,7 +158,7 @@ config.sign_out_via = :get # ==> Configuration for :token_authenticatable # Defines name of the authentication token params key -config.token_authentication_key = :auth_token +# config.token_authentication_key = :auth_token # If true, authentication through token does not store user in session and needs # to be supplied on each request. Useful if you are using the token as API token. diff --git a/config/locales/devise.en.yml b/config/locales/devise.en.yml index 79b3d5e6..0f3b4143 100644 --- a/config/locales/devise.en.yml +++ b/config/locales/devise.en.yml @@ -35,11 +35,12 @@ en: confirmed: 'Your account was successfully confirmed. You are now signed in.' registrations: signed_up: 'Welcome! You have signed up successfully.' - inactive_signed_up: 'You have signed up successfully. However, we could not sign you in because your account is %{reason}.' updated: 'You updated your account successfully.' destroyed: 'Bye! Your account was successfully cancelled. We hope to see you again soon.' reasons: - inactive: 'inactive' + signed_up_but_unconfirmed: 'A message with a confirmation link has been sent to your email address. Please open the link to activate your account.' + signed_up_but_inactive: 'You have signed up successfully. However, we could not sign you in because your account is not yet activated.' + signed_up_but_locked: 'You have signed up successfully. However, we could not sign you in because your account is locked.' unconfirmed: 'unconfirmed' locked: 'locked' unlocks: diff --git a/db/migrate/20111206092734_devise_create_admins.rb b/db/migrate/20111206092734_devise_create_admins.rb index 03fb5910..6e94741f 100644 --- a/db/migrate/20111206092734_devise_create_admins.rb +++ b/db/migrate/20111206092734_devise_create_admins.rb @@ -1,15 +1,39 @@ class DeviseCreateAdmins < ActiveRecord::Migration def change create_table(:admins) do |t| - t.database_authenticatable :null => false - t.recoverable - t.rememberable - t.trackable + ## Database authenticatable + t.string :email, :null => false, :default => "" + t.string :encrypted_password, :null => false, :default => "" + + ## Recoverable + t.string :reset_password_token + t.datetime :reset_password_sent_at + + ## Rememberable + t.datetime :remember_created_at + + ## Trackable + t.integer :sign_in_count, :default => 0 + t.datetime :current_sign_in_at + t.datetime :last_sign_in_at + t.string :current_sign_in_ip + t.string :last_sign_in_ip # t.encryptable - t.confirmable - # t.lockable :lock_strategy => :failed_attempts, :unlock_strategy => :both - t.token_authenticatable + ## Confirmable + t.string :confirmation_token + t.datetime :confirmed_at + t.datetime :confirmation_sent_at + t.string :unconfirmed_email # Only if using reconfirmable + + ## 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 + + # Token authenticatable + t.string :authentication_token + t.integer :approve, :null => false, :default => 0 t.timestamps diff --git a/db/migrate/20120306231650_devise_create_users.rb b/db/migrate/20120306231650_devise_create_users.rb index 915a976a..0f3195a2 100644 --- a/db/migrate/20120306231650_devise_create_users.rb +++ b/db/migrate/20120306231650_devise_create_users.rb @@ -1,15 +1,38 @@ class DeviseCreateUsers < ActiveRecord::Migration def change create_table(:users) do |t| - t.database_authenticatable :null => false - t.recoverable - t.rememberable - t.trackable - t.token_authenticatable - t.confirmable + ## Database authenticatable + t.string :email, :null => false, :default => "" + t.string :encrypted_password, :null => false, :default => "" + + ## Recoverable + t.string :reset_password_token + t.datetime :reset_password_sent_at + + ## Rememberable + t.datetime :remember_created_at + + ## Trackable + t.integer :sign_in_count, :default => 0 + t.datetime :current_sign_in_at + t.datetime :last_sign_in_at + t.string :current_sign_in_ip + t.string :last_sign_in_ip # t.encryptable - # t.lockable :lock_strategy => :failed_attempts, :unlock_strategy => :both + ## Confirmable + t.string :confirmation_token + t.datetime :confirmed_at + t.datetime :confirmation_sent_at + t.string :unconfirmed_email # Only if using reconfirmable + + ## 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 + + # Token authenticatable + t.string :authentication_token t.timestamps diff --git a/db/migrate/20121123051900_devise_create_demand_users.rb b/db/migrate/20121123051900_devise_create_demand_users.rb index 13410a52..45af068b 100644 --- a/db/migrate/20121123051900_devise_create_demand_users.rb +++ b/db/migrate/20121123051900_devise_create_demand_users.rb @@ -1,15 +1,38 @@ class DeviseCreateDemandUsers < ActiveRecord::Migration def change create_table(:demand_users) do |t| - t.database_authenticatable :null => false - t.recoverable - t.rememberable - t.trackable + ## Database authenticatable + t.string :email, :null => false, :default => "" + t.string :encrypted_password, :null => false, :default => "" + + ## Recoverable + t.string :reset_password_token + t.datetime :reset_password_sent_at + + ## Rememberable + t.datetime :remember_created_at + + ## Trackable + t.integer :sign_in_count, :default => 0 + t.datetime :current_sign_in_at + t.datetime :last_sign_in_at + t.string :current_sign_in_ip + t.string :last_sign_in_ip # t.encryptable - t.confirmable - # t.lockable :lock_strategy => :failed_attempts, :unlock_strategy => :both - t.token_authenticatable + ## Confirmable + t.string :confirmation_token + t.datetime :confirmed_at + t.datetime :confirmation_sent_at + t.string :unconfirmed_email # Only if using reconfirmable + + ## 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 + + # Token authenticatable + t.string :authentication_token t.timestamps -- 2.11.0