Skip to content

Instantly share code, notes, and snippets.

@jasdeepsingh
Created November 3, 2011 00:03
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jasdeepsingh/1335367 to your computer and use it in GitHub Desktop.
Save jasdeepsingh/1335367 to your computer and use it in GitHub Desktop.
Sessions Controller
class SessionsController < Devise::SessionsController
skip_before_filter :verify_authenticity_token
def create
#resource = warden.authenticate!(:scope => resource_name, :recall => :failure)
resource = warden.authenticate!(:scope => resource_name, :recall => "sessions#failure" )
if !resource.blank?
flash[:notice] = "Signed in successfully!"
end
return sign_in_and_redirect(resource_name, resource)
end
def sign_in_and_redirect(resource_or_scope, resource=nil)
scope = Devise::Mapping.find_scope!(resource_or_scope)
resource ||= resource_or_scope
sign_in(scope, resource) unless warden.user(scope) == resource
return render :json => {:success => true, :redirect => stored_location_for(scope), :user => resource.authentication_token}
end
def failure
return render:json => {:success => false, :errors => ["Login failed."]}
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment