Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove token from user table. #8

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 0 additions & 5 deletions app/controllers/application_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
3 changes: 0 additions & 3 deletions app/controllers/session_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -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
Expand Down
3 changes: 1 addition & 2 deletions app/models/flag.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
6 changes: 2 additions & 4 deletions app/models/user.rb
Original file line number Diff line number Diff line change
@@ -1,15 +1,13 @@
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

serialize :user_cache, JSON
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
Expand Down
5 changes: 5 additions & 0 deletions db/migrate/20180917213107_remove_user_tokens.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
class RemoveUserTokens < ActiveRecord::Migration
def change
remove_column :users, :token
end
end
4 changes: 1 addition & 3 deletions db/schema.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand All @@ -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