Monday 15 April 2013

ruby on rails - Simple Authlogic Question: JSON login? -


I have established a very simple site that allows me to log in, out and register. Except that I removed the "username" from the users, removed the table and relevant scenes, so only one email address is required)

Now I have a new login operation Trying to do that I can log in via JSON.

me the http: // app: 3000 / apilogin? Email = my@email.com& I would like to be able to get a request on the password I = P4ssw0rd and the Rail Application comes from the request of the IP address (if the login was correct) and the related feedback (in JSON)

So far I have a section of controllers / user_sessions_controller.rb so that it goes:

  class UserSessionsController & lt; ApplicationController # ... def new_api response_to do | Format | Format.json end end end  

to routes.rb :

  map.apilogin "apilogin" ,: Controller = & Gt; "User_sessions" ,: verb = & gt; "New_api"  

But what am I at a loss as I have put in views / user_sessions / new_api.json.rb ! Can you help

You do not have to define any view - just Jason back controller, just suitable

  def new_api @user_session = UserSession.new ({: email = & gt; parameter [: email],: password => params [: password]}) response_to do | Format | If @ user_session.save format.json {render: json = & gt; {: Success = & gt; True}} and format.json {rendere: json = & gt; {: Success = & gt; Wrong, message = & gt; 'Incorrect username or password'} ,: position => : Unauthorized} End End  

No comments:

Post a Comment