From 50ed8c721a3952fbd85ea7a76dcc7c3b823d2273 Mon Sep 17 00:00:00 2001 From: zackgilbert Date: Mon, 17 Sep 2018 16:41:44 -0500 Subject: [PATCH] Remove token from user table. --- app/controllers/application_controller.rb | 5 ----- app/controllers/session_controller.rb | 3 --- app/models/flag.rb | 3 +-- app/models/user.rb | 6 ++---- db/migrate/20180917213107_remove_user_tokens.rb | 5 +++++ db/schema.rb | 4 +--- 6 files changed, 9 insertions(+), 17 deletions(-) create mode 100644 db/migrate/20180917213107_remove_user_tokens.rb diff --git a/app/controllers/application_controller.rb b/app/controllers/application_controller.rb index a043062..6a29b40 100644 --- a/app/controllers/application_controller.rb +++ b/app/controllers/application_controller.rb @@ -65,11 +65,6 @@ def get_current_user begin foursquare = Foursquare2::Client.new(:oauth_token => cookies.signed[:access_token], :connection_middleware => [Faraday::Response::Logger, FaradayMiddleware::Instrumentation], :api_version => api_version) @current_user ||= User.find_by_uid(foursquare.user('self').id) - # TODO: remove when reomving user.token - # ensure existing users that are logged in have the user's database stored token set in the cookie: - if @current_user.token.present? && !cookies.signed[:access_token].present? - cookies.permanent.signed[:access_token] = @current_user.token - end # set the user access token (so it uses that instead of the database stored): @current_user.access_token = cookies.signed[:access_token] rescue Foursquare2::APIError diff --git a/app/controllers/session_controller.rb b/app/controllers/session_controller.rb index 898fa65..e2c70f0 100644 --- a/app/controllers/session_controller.rb +++ b/app/controllers/session_controller.rb @@ -19,7 +19,6 @@ def callback rescue OAuth2::Error => e flash[:notice] = "Login Failure: " + e.message end - end # Now that we have an access token, let's see if we have a user for this person: @@ -30,8 +29,6 @@ def callback if user @current_user = user - # TODO: token will be going byebye soon - @current_user[:token] = cookies[:access_token] # let's clear their user cache, it seems to be causing problems: @current_user.user_cache = nil @current_user.cached_at = nil diff --git a/app/models/flag.rb b/app/models/flag.rb index f006a6f..10d2ec9 100644 --- a/app/models/flag.rb +++ b/app/models/flag.rb @@ -12,8 +12,7 @@ class Flag < ActiveRecord::Base HOME_CAT_ID = '4bf58dd8d48988d103941735'; def user_token - # TODO: remove the user.oauth_token and ONLY use self.access_token - @token ||= ( self.access_token.present? ) ? self.access_token : user.oauth_token + @token ||= self.access_token end def client diff --git a/app/models/user.rb b/app/models/user.rb index b58607f..ee741ed 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -1,6 +1,5 @@ class User < ActiveRecord::Base - # TODO: remove token - attr_accessible :enabled, :level, :name, :uid, :token + attr_accessible :enabled, :level, :name, :uid attr_accessor :access_token has_many :flags @@ -8,8 +7,7 @@ class User < ActiveRecord::Base MAX_USER_AGE = 1.hour def oauth_token - # TODO: remove the self.token and ONLY use self.access_token - @token ||= ( self.access_token.present? ) ? self.access_token : self.token + @token ||= self.access_token end def foursquare_client diff --git a/db/migrate/20180917213107_remove_user_tokens.rb b/db/migrate/20180917213107_remove_user_tokens.rb new file mode 100644 index 0000000..c967540 --- /dev/null +++ b/db/migrate/20180917213107_remove_user_tokens.rb @@ -0,0 +1,5 @@ +class RemoveUserTokens < ActiveRecord::Migration + def change + remove_column :users, :token + end +end diff --git a/db/schema.rb b/db/schema.rb index 93320e4..6096d57 100644 --- 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 => 20140705230607) do +ActiveRecord::Schema.define(:version => 20180917213107) do create_table "categories_caches", :force => true do |t| t.text "categories", :limit => 16777215 @@ -75,7 +75,6 @@ create_table "users", :force => true do |t| t.string "name" t.string "level" - t.string "token" t.boolean "enabled" t.datetime "created_at", :null => false t.datetime "updated_at", :null => false @@ -85,7 +84,6 @@ t.string "hometown" end - add_index "users", ["token"], :name => "index_users_on_token" add_index "users", ["uid"], :name => "index_users_on_uid" end