Skip to content

Commit

Permalink
Merge pull request #7838 from spark-solutions/feature/extract-api-key…
Browse files Browse the repository at this point in the history
…-renders

Extract invalid_api_key and must_specify_api_key
  • Loading branch information
damianlegawiec committed Mar 14, 2017
2 parents 9fd370c + 7e9c4db commit 3a2f1a0
Showing 1 changed file with 10 additions and 2 deletions.
12 changes: 10 additions & 2 deletions api/app/controllers/spree/api/base_controller.rb
Expand Up @@ -64,15 +64,23 @@ def authenticate_user
return if @current_api_user

if requires_authentication? && api_key.blank? && order_token.blank?
render "spree/api/errors/must_specify_api_key", status: 401 and return
must_specify_api_key and return
elsif order_token.blank? && (requires_authentication? || api_key.present?)
render "spree/api/errors/invalid_api_key", status: 401 and return
invalid_api_key and return
else
# An anonymous user
@current_api_user = Spree.user_class.new
end
end

def invalid_api_key
render "spree/api/errors/invalid_api_key", status: 401
end

def must_specify_api_key
render "spree/api/errors/must_specify_api_key", status: 401
end

def load_user_roles
@current_user_roles = @current_api_user ? @current_api_user.spree_roles.pluck(:name) : []
end
Expand Down

0 comments on commit 3a2f1a0

Please sign in to comment.