From 99f24fe144df59bfe48e7ef3e1a8349209aaaddc Mon Sep 17 00:00:00 2001 From: Will Bradley Date: Sun, 2 Sep 2012 04:12:26 -0700 Subject: [PATCH] Reinstalled devise to user model and migration --- app/models/user.rb | 8 +++ config/initializers/devise.rb | 2 +- config/routes.rb | 2 + .../20120902105919_add_devise_to_users.rb | 60 +++++++++++++++++++ db/schema.rb | 19 +++++- 5 files changed, 87 insertions(+), 4 deletions(-) create mode 100644 db/migrate/20120902105919_add_devise_to_users.rb diff --git a/app/models/user.rb b/app/models/user.rb index ee833fd..b44fbb7 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -1,4 +1,12 @@ class User < ActiveRecord::Base + # Include default devise modules. Others available are: + # :token_authenticatable, :confirmable, + # :lockable, :timeoutable and :omniauthable + devise :database_authenticatable, :registerable, + :recoverable, :rememberable, :trackable, :validatable + + # Setup accessible (or protected) attributes for your model + attr_accessible :email, :password, :password_confirmation, :remember_me require 'open-uri' attr_accessible :card_id, :card_number, :card_permissions, :name diff --git a/config/initializers/devise.rb b/config/initializers/devise.rb index 4dcb333..3edeff1 100644 --- a/config/initializers/devise.rb +++ b/config/initializers/devise.rb @@ -82,7 +82,7 @@ Devise.setup do |config| config.stretches = Rails.env.test? ? 1 : 10 # Setup a pepper to generate the encrypted password. - # config.pepper = "eced55b3a4acf0aa9187e0e705474f780fc8480f8bfb7009b672b0ecaef204b3a4669cdbab82df033d4234f39d4db3c64d4857d2823e8aa9fa4c55c1a9c6e4c9" + # config.pepper = "a2406b0a0ef9399b1367e2a43c435e4e946b5e1ee75644af793405515ce3361c2fe47bcec51a1095f480cf08ab6d7073b12034c92e6e63779245f968a88888f9" # ==> Configuration for :confirmable # A period that the user is allowed to access the website even without diff --git a/config/routes.rb b/config/routes.rb index edc026d..75af558 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -1,5 +1,7 @@ Dooraccess::Application.routes.draw do + devise_for :users + match 'users/upload_all' => 'users#upload_all', :as => :upload_all resources :users match 'users/:id/upload' => 'users#upload', :as => :upload diff --git a/db/migrate/20120902105919_add_devise_to_users.rb b/db/migrate/20120902105919_add_devise_to_users.rb new file mode 100644 index 0000000..143b363 --- /dev/null +++ b/db/migrate/20120902105919_add_devise_to_users.rb @@ -0,0 +1,60 @@ +class AddDeviseToUsers < ActiveRecord::Migration + def self.up + change_table(:users) do |t| + ## 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 + + ## 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 + + + # Uncomment below if timestamps were not included in your original model. + # t.timestamps + end + + @users = User.all + @users.each do |u| + u.email = (100000*rand()).to_s+"@example.com" + u.save + end + + + add_index :users, :email, :unique => true + add_index :users, :reset_password_token, :unique => true + # add_index :users, :confirmation_token, :unique => true + # add_index :users, :unlock_token, :unique => true + # add_index :users, :authentication_token, :unique => true + end + + def self.down + # By default, we don't want to make any assumption about how to roll back a migration when your + # model already existed. Please edit below which fields you would like to remove in this migration. + raise ActiveRecord::IrreversibleMigration + end +end diff --git a/db/schema.rb b/db/schema.rb index 9c563a1..82c56e2 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -10,7 +10,7 @@ # # It's strongly recommended to check this file into your version control system. -ActiveRecord::Schema.define(:version => 20120825041626) do +ActiveRecord::Schema.define(:version => 20120902105919) do create_table "door_logs", :force => true do |t| t.string "key" @@ -24,8 +24,21 @@ ActiveRecord::Schema.define(:version => 20120825041626) do t.integer "card_id" t.string "card_number" t.integer "card_permissions" - t.datetime "created_at", :null => false - t.datetime "updated_at", :null => false + t.datetime "created_at", :null => false + t.datetime "updated_at", :null => false + t.string "email", :default => "", :null => false + t.string "encrypted_password", :default => "", :null => false + t.string "reset_password_token" + t.datetime "reset_password_sent_at" + t.datetime "remember_created_at" + 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" 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 + end