Guest User

Untitled

a guest
Jun 18th, 2018
89
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.13 KB | None | 0 0
  1. class ApiController < ApplicationController
  2. skip_filter :authenticate
  3. before_filter :json_authenticate
  4.  
  5. def index
  6. respond_to do |format|
  7. format.html { render :nothing => true }
  8. format.json {
  9. if params[:client]
  10. if client = Client.find(:all,:conditions=>["name ilike ?", "%#{params[:client]}%"])
  11. if client.empty?
  12. render :json => {:message => "No Such Client"}
  13. else
  14. render :json => {:message => client}
  15. end
  16. end
  17. else
  18. render :json => {:message => "No Client Name Provided, Don't be an Animal."}
  19. end
  20. }
  21. end
  22. end
  23.  
  24. protected
  25. def json_authenticate
  26. respond_to do |format|
  27. format.html { render :nothing => true}
  28. format.json {
  29. if (username = params[:username]) && (password = params[:password])
  30. if user = User.authenticate(username,password)
  31. @user = user
  32. else
  33. render :json => {:message => "Authentication Failed"}
  34. end
  35. else
  36. render :json => {:message => "Authentication Failed"}
  37. end
  38. }
  39. end
  40. end
  41.  
  42. end
Add Comment
Please, Sign In to add comment