Initial stab at check-in feature

This commit is contained in:
Jason Denney
2013-05-19 15:43:44 -04:00
parent c504252541
commit d7755f00ed
8 changed files with 147 additions and 1 deletions
+23
View File
@@ -0,0 +1,23 @@
class Api::V1::BaseController < ActionController::Base
respond_to :json
before_filter :authenticate_user
private
def authenticate_user
if params[:token]
@current_user = User.find_by_authentication_token(params[:token])
else
user = User.find_for_database_authentication( :email => params[:username] )
@current_user = user if user && user.valid_password?( params[:password] )
end
unless @current_user
render :json => {:error => "Username/Password/Token invalid" }, :status => 403
end
end
def current_user
@current_user
end
end
+20
View File
@@ -0,0 +1,20 @@
class Api::V1::LogsController < Api::V1::BaseController
def checkin
if @current_user.checked_in?
render :json => { "error" => "You are already checked in."}, :status => 404 and return
else
@current_user.checkin
render :nothing => true, :status => 204 and return
end
end
def checkout
if !@current_user.checked_in?
render :json => { "error" => "You were not even checked in."}, :status => 404 and return
else
@current_user.checkout
render :nothing => true, :status => 204 and return
end
end
end