Skip to content

Instantly share code, notes, and snippets.

@validkeys
Created October 22, 2013 13:51
Show Gist options
  • Select an option

  • Save validkeys/7101159 to your computer and use it in GitHub Desktop.

Select an option

Save validkeys/7101159 to your computer and use it in GitHub Desktop.
class ApplicationController < ActionController::Base
protect_from_forgery with: :null_session
before_filter :authenticate
after_filter :test
serialization_scope :view_context
protected
def current_user
@current_user
end
helper_method :current_user
def default_serializer_options
{root: false}
end
private
def authenticate
if Rails.env == "development" && params[:token]
# logger.debug "-> URL DETECTED"
if set_current_user(params[:token]) == false
head :unauthorized
end
else
authenticate_or_request_with_http_token do |token, options|
set_current_user(token)
end
end
end
def set_current_user(token)
# logger.debug "-> SETTING CURRENT USER #{token}"
user = User.find_by(token: token.to_s)
if user.blank?
# logger.debug "=> NO USER FOUND!"
return false
else
# logger.debug "=> SETTING THE USER!"
@current_user = user
@current_user
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment