mirror of
https://github.com/heartcombo/devise.git
synced 2022-11-09 12:18:31 -05:00
Devise migratable.
This commit is contained in:
parent
b3f68ab287
commit
f00d29c97a
5 changed files with 69 additions and 27 deletions
29
README.rdoc
29
README.rdoc
|
@ -39,27 +39,20 @@ Devise must be setted up within the model (or models) you want to use, and devis
|
||||||
|
|
||||||
We're assuming here you want a User model. First of all you have to setup a migration with the following fields:
|
We're assuming here you want a User model. First of all you have to setup a migration with the following fields:
|
||||||
|
|
||||||
# required
|
create_table :users do
|
||||||
t.string :email, :null => false
|
t.authenticable
|
||||||
t.string :encrypted_password, :null => false
|
t.confirmable
|
||||||
t.string :password_salt, :null => false
|
t.recoverable
|
||||||
|
t.rememberable
|
||||||
# required for confirmable
|
t.timestamps
|
||||||
t.string :confirmation_token
|
end
|
||||||
t.datetime :confirmation_sent_at
|
|
||||||
t.datetime :confirmed_at
|
|
||||||
|
|
||||||
# required for recoverable
|
|
||||||
t.string :reset_password_token
|
|
||||||
|
|
||||||
# required for rememberable
|
|
||||||
t.string :remember_token
|
|
||||||
|
|
||||||
You may also want to add some indexes to improve performance:
|
You may also want to add some indexes to improve performance:
|
||||||
|
|
||||||
add_index :your_table, :email
|
add_index :your_table, :email
|
||||||
add_index :your_table, :confirmation_token # for confirmable
|
add_index :your_table, :confirmation_token # for confirmable
|
||||||
add_index :your_table, :reset_password_token # for recoverable
|
add_index :your_table, :reset_password_token # for recoverable
|
||||||
|
add_index :your_table, :remember_token # for rememberable
|
||||||
|
|
||||||
Now let's setup a User model adding the devise line to have your authentication working:
|
Now let's setup a User model adding the devise line to have your authentication working:
|
||||||
|
|
||||||
|
@ -164,9 +157,9 @@ After signing in a user, confirming it's account or updating it's password, devi
|
||||||
Devise let's you setup as many roles as you want, so let's say you already have this User model and also want an Admin model with the same authentication stuff, but not confirmation or password recovery. Just follow the same steps:
|
Devise let's you setup as many roles as you want, so let's say you already have this User model and also want an Admin model with the same authentication stuff, but not confirmation or password recovery. Just follow the same steps:
|
||||||
|
|
||||||
# Create a migration with the required fields
|
# Create a migration with the required fields
|
||||||
t.string :email, :null => false
|
create_table :admins do |t|
|
||||||
t.string :encrypted_password, :null => false
|
t.authenticable
|
||||||
t.string :password_salt, :null => false
|
end
|
||||||
|
|
||||||
# Inside your Admin model
|
# Inside your Admin model
|
||||||
devise :validatable
|
devise :validatable
|
||||||
|
|
2
TODO
2
TODO
|
@ -8,7 +8,6 @@
|
||||||
* Devise::BruteForceProtection
|
* Devise::BruteForceProtection
|
||||||
* Devise::MagicColumns
|
* Devise::MagicColumns
|
||||||
* Devise::Invitable
|
* Devise::Invitable
|
||||||
* Devise::Migratable
|
|
||||||
|
|
||||||
== Done
|
== Done
|
||||||
|
|
||||||
|
@ -16,6 +15,7 @@
|
||||||
* Devise::Confirmable
|
* Devise::Confirmable
|
||||||
* Devise::Recoverable
|
* Devise::Recoverable
|
||||||
* Devise::Validatable
|
* Devise::Validatable
|
||||||
|
* Devise::Migratable
|
||||||
* SessionsController
|
* SessionsController
|
||||||
* PasswordsController
|
* PasswordsController
|
||||||
* ConfirmationsController
|
* ConfirmationsController
|
||||||
|
|
|
@ -46,4 +46,5 @@ require 'devise/routes'
|
||||||
# able to create default filters.
|
# able to create default filters.
|
||||||
Rails.configuration.after_initialize do
|
Rails.configuration.after_initialize do
|
||||||
ActiveRecord::Base.extend Devise::ActiveRecord
|
ActiveRecord::Base.extend Devise::ActiveRecord
|
||||||
|
ActiveRecord::ConnectionAdapters::TableDefinition.send :include, Devise::Migrations
|
||||||
end
|
end
|
||||||
|
|
51
lib/devise/migrations.rb
Normal file
51
lib/devise/migrations.rb
Normal file
|
@ -0,0 +1,51 @@
|
||||||
|
module Devise
|
||||||
|
# Helpers to migration:
|
||||||
|
#
|
||||||
|
# create_table :accounts do |t|
|
||||||
|
# t.authenticable
|
||||||
|
# t.confirmable
|
||||||
|
# t.recoverable
|
||||||
|
# t.rememberable
|
||||||
|
# t.timestamps
|
||||||
|
# end
|
||||||
|
#
|
||||||
|
# However this method does not add indexes. If you need them, here is the declaration:
|
||||||
|
#
|
||||||
|
# add_index "accounts", ["email"], :name => "email", :unique => true
|
||||||
|
# add_index "accounts", ["remember_token"], :name => "remember_token", :unique => true
|
||||||
|
# add_index "accounts", ["confirmation_token"], :name => "confirmation_token", :unique => true
|
||||||
|
# add_index "accounts", ["reset_password_token"], :name => "reset_password_token", :unique => true
|
||||||
|
#
|
||||||
|
module Migrations
|
||||||
|
|
||||||
|
# Creates email, encrypted_password and password_salt.
|
||||||
|
#
|
||||||
|
def authenticable
|
||||||
|
string :email, :limit => 100, :null => false
|
||||||
|
string :encrypted_password, :limit => 40, :null => false
|
||||||
|
string :password_salt, :limit => 20, :null => false
|
||||||
|
end
|
||||||
|
|
||||||
|
# Creates confirmation_token, confirmed_at and confirmation_sent_at.
|
||||||
|
#
|
||||||
|
def confirmable
|
||||||
|
string :confirmation_token, :limit => 40, :null => true
|
||||||
|
datetime :confirmed_at
|
||||||
|
datetime :confirmation_sent_at
|
||||||
|
end
|
||||||
|
|
||||||
|
# Creates reset_password_token.
|
||||||
|
#
|
||||||
|
def recoverable
|
||||||
|
string :reset_password_token, :limit => 40, :null => true
|
||||||
|
end
|
||||||
|
|
||||||
|
# Creates remember_token and remember_expires_at.
|
||||||
|
#
|
||||||
|
def rememberable
|
||||||
|
string :remember_token, :limit => 40, :null => true
|
||||||
|
datetime :remember_expires_at
|
||||||
|
end
|
||||||
|
|
||||||
|
end
|
||||||
|
end
|
|
@ -16,15 +16,12 @@ ActiveRecord::Base.establish_connection(:adapter => "sqlite3", :database => ":me
|
||||||
ActiveRecord::Schema.define(:version => 1) do
|
ActiveRecord::Schema.define(:version => 1) do
|
||||||
[:users, :admins].each do |table|
|
[:users, :admins].each do |table|
|
||||||
create_table table do |t|
|
create_table table do |t|
|
||||||
t.string :email, :null => false
|
t.authenticable
|
||||||
t.string :encrypted_password, :null => false
|
|
||||||
t.string :password_salt, :null => false
|
|
||||||
if table == :users
|
if table == :users
|
||||||
t.string :confirmation_token
|
t.confirmable
|
||||||
t.datetime :confirmation_sent_at
|
t.recoverable
|
||||||
t.datetime :confirmed_at
|
t.rememberable
|
||||||
t.string :reset_password_token
|
|
||||||
t.string :remember_token
|
|
||||||
end
|
end
|
||||||
|
|
||||||
t.timestamps
|
t.timestamps
|
||||||
|
|
Loading…
Reference in a new issue