Implement sessions/create in JSON API

This commit is contained in:
Thibault Jouan
2012-02-26 11:16:52 +00:00
parent 499b06c9e5
commit 5dfafdcc46
6 changed files with 103 additions and 0 deletions

View File

@@ -1,4 +1,7 @@
class Api::ApplicationController < ApplicationController
skip_before_filter :verify_authenticity_token
skip_before_filter :authenticate!, :only => [:cor_preflight]
before_filter :cor_filter
def cor_filter
@@ -12,4 +15,8 @@ class Api::ApplicationController < ApplicationController
head :ok
end
def authenticate!
head :unauthorized if current_user.nil?
end
end

View File

@@ -0,0 +1,14 @@
class Api::V0::SessionsController < Api::ApplicationController
skip_before_filter :authenticate!, :only => [:create]
def create
user = User.find_by_email(params[:session][:email])
if ! user.try(:authenticate?, params[:session][:password])
return render :json => '', :status => :not_found
end
@user = user
self.current_user = @user
end
end