Created
October 22, 2013 13:51
-
-
Save validkeys/7101159 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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