I have a question about this, but first some givens:
I understand that in this example that the only response is in json
which can be tested with the browser, and I've done this. So the
session controller is being executed, and json back is good to go.
However, if I try to run a curl test it doesn't work for me. I get a
json response back saying saying that i need to sign in:
<code:json>
{"error":"You need to sign in or sign up before continuing."}
</code:json>
Here is what I used to test:
<code:commandline>
curl -H "Content-Type:application/json" -H "Accept:application/json" \
-d "{\"user\":{\"user_email\":\"
us...@test.com\",\"user_password\":
\"please\"}}" \
http://localhost:3000/users/sign_in
</code:commandline>
What the heck, i tried a non resource block version too :-P
(result=nada)
<code:commandline>
curl -H "Content-Type:application/json" -H "Accept:application/json" \
-d "{\"user_email\":\"
us...@test.com\",\"user_password\":\"please\"}" \
http://localhost:3000/users/sign_in
</code:commandline>
Anyone have any answers? Would appreciate the help, thanks in advance.
On Aug 16, 7:17 am, tekknikk <
tekkn...@gmail.com> wrote:
> Here's my approach rejsonresponse for both success and failure.
> for
> rails 2.3 / devise 1.0.8, i've copied the sessions controller
> completely, changed the create and added sign_in_and_redirect. I've
> also done something similar with the registrations controller for
> sign_up.
> Would like to compare notes with you.
> def sign_in_and_redirect(resource_or_scope, resource=nil,
> skip=false)
> scope = Devise::Mapping.find_scope!(resource_or_scope)
> resource ||= resource_or_scope
> sign_in(scope, resource) unless skip
> respond_to do |format|
> format.html {redirect_to stored_location_for(scope) ||
> after_sign_in_path_for(resource) }
> format.json{ render :json=> { :success => true, :session_id
> =>
> request.session_options[:id], :resource => resource,
> :redirect => $some_path } }
> end
> end
> def create
> build_resource
> if resource = authenticate(resource_name)
> set_flash_message :notice, :signed_in
> sign_in_and_redirect(resource_name, resource, true)
> elsif [:custom, :redirect].include?(warden.result)
> throw :warden, :scope => resource_name
> else
> set_now_flash_message :alert, (warden.message || :invalid)
> clean_up_passwords(build_resource)
> respond_to do |format|
> format.html { render_with_scope :new }
> format.json{ render :json=> {:success => false, :status =>
> warden.message}}
> end
> end
> end
>
> On Aug 14, 10:52 am, Keegan Poppen <
keegan.pop...@gmail.com> wrote:
>
>
>
> > Hi--
>
> > So I know that this question has come up a couple of different times
> > over this list, but it doesn't seem like there has really been much
> > response / activity so I'd figured again:
>
> > In a mobile web application that I'm developing right now I need to be
> > able to send anAJAXrequest to log in and get aJSONresponse back,