Advertisement
Guest User

Untitled

a guest
Nov 28th, 2016
82
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.17 KB | None | 0 0
  1. curl -H "Authorization: Basic dHJ1bXBAdHJ1bXAuY29tOmZvb2Jhcg==n" http://localhost:3000/api/v1/token
  2.  
  3. SyntaxError: unexpected tIDENTIFIER, expecting end-of-input
  4. ...HJ1bXAuY29tOmZvb2Jhcg==n" http://localhost:3000/api/v1/token
  5. ... ^
  6.  
  7. namespace :api, defaults: {format: 'json'} do
  8. namespace :v1 do
  9.  
  10. get :token, controller: 'sessions'
  11.  
  12. resources :users, only: [:index, :create, :show, :update, :destroy], shallow: true do
  13. resources :galleries
  14. resources :categories
  15. resources :images
  16. end
  17. end
  18. end
  19. end
  20.  
  21. def token
  22. authenticate_with_http_basic do |email, password|
  23. user = User.find_by(email: email)
  24. if user && user.password == password
  25.  
  26.  
  27. render json: SessionSerializer.new(user, root: false).to_json, status: 201
  28. else
  29. render json: { error: 'Incorrect credentials'}, status: 401
  30. end
  31. end
  32.  
  33. end
  34.  
  35. module Api
  36. module V1
  37. class SessionSerializer < ActiveModel::Serializer
  38. attribute :token
  39. def token
  40. object.authentication_token
  41. end
  42. end
  43. end
  44.  
  45. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement