4 Replies Latest reply on Mar 28, 2014 11:20 AM by Adel Sari

    Custom route and login_required

    Adel Sari

      Hi,

      i have a custom route in my application controller (RhoConnect 4 application) declared like this

      post '/saveData', :login_required => true do

             #my code here

      end

       

      i can access the route from my rhodes app but i receive a 401 error.

      What should i pass to this function (session, login & password) from my rhodes app to be a valid call ?

      thanks

        • Re: Custom route and login_required

          :login_required checks that the request contains authenticated user's session cookie. This cookie is internal to RhoConnect Client when you do the login, so you can't access it directly from the app.

          You would need to call authenticate route POST /rc/v1/app/login again directly (using RESTClient - passing username and password in the JSON body as {"login":"<your_name>","password":<your_password>"} ) , store the returned Session Cookie - and then, use it to call your custom route.

           

          Max.

          1 of 1 people found this helpful
          • Re: Custom route and login_required
            Adel Sari

            i tried this code, but not working

             

            in my rhodes application:

               def sendToServer

                 res = Rho::RHO.get_user_db.execute_sql("select session from client_info")

                 my_session = res[0]['session'].inspect

             

                propertyMap = Hash.new

                propertyMap['url'] = Rho::RhoConfig.syncserver + "/rc/v1/app/saveData"

                propertyMap['headers'] = {'Cookie' => my_session }

                propertyMap['httpVerb'] = "POST"

                propertyMap['body'] = "product_id=" + product_id + "&data=" + $data

                Rho::Network.post(propertyMap, url_for(:action => :sendToServer _callback))

              end

             

            i still get the error 401 (You entered an invalid login/password)