Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class ApiController < ApplicationController
- skip_filter :authenticate
- before_filter :json_authenticate
- def index
- respond_to do |format|
- format.html { render :nothing => true }
- format.json {
- if params[:client]
- if client = Client.find(:all,:conditions=>["name ilike ?", "%#{params[:client]}%"])
- if client.empty?
- render :json => {:message => "No Such Client"}
- else
- render :json => {:message => client}
- end
- end
- else
- render :json => {:message => "No Client Name Provided, Don't be an Animal."}
- end
- }
- end
- end
- protected
- def json_authenticate
- respond_to do |format|
- format.html { render :nothing => true}
- format.json {
- if (username = params[:username]) && (password = params[:password])
- if user = User.authenticate(username,password)
- @user = user
- else
- render :json => {:message => "Authentication Failed"}
- end
- else
- render :json => {:message => "Authentication Failed"}
- end
- }
- end
- end
- end
Add Comment
Please, Sign In to add comment