diff --git a/app/models/user.rb b/app/models/user.rb index 2af7dc2..909fb64 100755 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -81,5 +81,11 @@ private end end end + + def generate_token(column) + begin + self[column] = SecureRandom.urlsafe_base64 + end while User.exists?(column => self[column]) + end end diff --git a/db/migrate/20140312002642_add_auth_token_to_users.rb b/db/migrate/20140312002642_add_auth_token_to_users.rb new file mode 100644 index 0000000..2c83ac1 --- /dev/null +++ b/db/migrate/20140312002642_add_auth_token_to_users.rb @@ -0,0 +1,5 @@ +class AddAuthTokenToUsers < ActiveRecord::Migration + def change + add_column :users, :auth_token, :string + end +end diff --git a/db/schema.rb b/db/schema.rb index b7ded3a..2ec1d36 100755 --- a/db/schema.rb +++ b/db/schema.rb @@ -11,7 +11,7 @@ # # It's strongly recommended to check this file into your version control system. -ActiveRecord::Schema.define(:version => 20131113200708) do +ActiveRecord::Schema.define(:version => 20140312002642) do create_table "benefits", :force => true do |t| t.datetime "created_at", :null => false @@ -83,6 +83,7 @@ ActiveRecord::Schema.define(:version => 20131113200708) do t.integer "user_id" t.datetime "created_at", :null => false t.datetime "updated_at", :null => false + t.string "auth_token" end create_table "work_infos", :force => true do |t|