Skip to content

Instantly share code, notes, and snippets.

@jsooriah
Created January 23, 2014 07:34
Show Gist options
  • Save jsooriah/8574465 to your computer and use it in GitHub Desktop.
Save jsooriah/8574465 to your computer and use it in GitHub Desktop.
class Api::V1::SessionsController < Devise::SessionsController
prepend_before_filter :require_no_authentication, :only => [:create]
skip_before_filter :verify_authenticity_token, :if => Proc.new { |c| c.request.format == 'application/json' }
before_filter :validate_auth_token, :except => :create
include Devise::Controllers::Helpers
include ApiHelper
respond_to :json
def create
resource = User.find_for_database_authentication(:email => params[:user][:email])
return failure unless resource
if resource.valid_password?(params[:user][:password])
sign_in(:user, resource)
resource.ensure_authentication_token!
render :json=> {:success => true, :token => resource.authentication_token}
return
end
failure
end
@jsooriah
Copy link
Author

Started POST "/users/sign_in.json" for 127.0.0.1 at 2014-01-23 01:19:48 +0100
Processing by Devise::SessionsController#create as JSON
Parameters: {"password"=>"[FILTERED]", "email"=>"ashley@example.com", "session"=>{"password"=>"[FILTERED]", "format"=>"json", "email"=>"ashley@example.com"}}
Completed 401 Unauthorized in 6ms
Processing by Devise::SessionsController#new as JSON
Parameters: {"password"=>"[FILTERED]", "email"=>"ashley@example.com", "session"=>{"password"=>"[FILTERED]", "format"=>"json", "email"=>"ashley@example.com"}}
Completed 406 Not Acceptable in 165ms

ActionController::UnknownFormat (ActionController::UnknownFormat):
actionpack (4.0.0) lib/action_controller/metal/mime_responds.rb:372:in retrieve_collector_from_mimes' actionpack (4.0.0) lib/action_controller/metal/mime_responds.rb:327:inrespond_with'
devise (3.0.3) app/controllers/devise/sessions_controller.rb:10:in `new'

@bartocc
Copy link

bartocc commented Jan 23, 2014

Salut Joël,

Il me semble déjà que tu as un problème de routes.

Ton POST "/users/sign_in.json" tape sur Devise::SessionsController#create alors qu'il devrait taper sur Api::V1::SessionsController#create me semble-t-il

@jsooriah
Copy link
Author

yo !

je pensais justement à ça ce matin !!

Many Thanks bartocc !

Et excellent année ;) !

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment