Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- curl -H "Authorization: Basic dHJ1bXBAdHJ1bXAuY29tOmZvb2Jhcg==n" http://localhost:3000/api/v1/token
- SyntaxError: unexpected tIDENTIFIER, expecting end-of-input
- ...HJ1bXAuY29tOmZvb2Jhcg==n" http://localhost:3000/api/v1/token
- ... ^
- namespace :api, defaults: {format: 'json'} do
- namespace :v1 do
- get :token, controller: 'sessions'
- resources :users, only: [:index, :create, :show, :update, :destroy], shallow: true do
- resources :galleries
- resources :categories
- resources :images
- end
- end
- end
- end
- def token
- authenticate_with_http_basic do |email, password|
- user = User.find_by(email: email)
- if user && user.password == password
- render json: SessionSerializer.new(user, root: false).to_json, status: 201
- else
- render json: { error: 'Incorrect credentials'}, status: 401
- end
- end
- end
- module Api
- module V1
- class SessionSerializer < ActiveModel::Serializer
- attribute :token
- def token
- object.authentication_token
- end
- end
- end
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement