mirror of
https://github.com/fspc/BikeShed-1.git
synced 2025-02-28 16:53:23 -05:00
Finished Checkin/out feature for now
-Checkin/out api methods can be used while signed in -Added checkout button in Netzke App, which also signs out in addition to checking out.
This commit is contained in:
parent
d7755f00ed
commit
a00c1ed925
@ -6,6 +6,11 @@ class AppTabPanel < Netzke::Basepack::TabPanel
|
|||||||
c.text = "Sign out #{controller.current_user.email}" if controller.current_user
|
c.text = "Sign out #{controller.current_user.email}" if controller.current_user
|
||||||
end
|
end
|
||||||
|
|
||||||
|
action :check_out do |c|
|
||||||
|
c.icon = :door_out
|
||||||
|
c.text = "CHECK OUT" if controller.current_user
|
||||||
|
end
|
||||||
|
|
||||||
def configure(c)
|
def configure(c)
|
||||||
|
|
||||||
#all users
|
#all users
|
||||||
@ -49,7 +54,7 @@ class AppTabPanel < Netzke::Basepack::TabPanel
|
|||||||
end
|
end
|
||||||
|
|
||||||
c.prevent_header = true
|
c.prevent_header = true
|
||||||
c.tbar = [:sign_out]
|
c.tbar = [:sign_out, :check_out]
|
||||||
c.items = @@app_tab_panel_items
|
c.items = @@app_tab_panel_items
|
||||||
super
|
super
|
||||||
end
|
end
|
||||||
@ -58,6 +63,5 @@ class AppTabPanel < Netzke::Basepack::TabPanel
|
|||||||
#gets js from app_tab_panel/javascripts/sign_out.js
|
#gets js from app_tab_panel/javascripts/sign_out.js
|
||||||
c.mixin :sign_out
|
c.mixin :sign_out
|
||||||
end
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -5,5 +5,17 @@
|
|||||||
url: '/users/sign_out',
|
url: '/users/sign_out',
|
||||||
method: 'DELETE'
|
method: 'DELETE'
|
||||||
});
|
});
|
||||||
|
},
|
||||||
|
onCheckOut: function(){
|
||||||
|
Ext.Ajax.request({
|
||||||
|
url: '/api/v1/checkout',
|
||||||
|
method: 'POST',
|
||||||
|
success: function(response, opts) {
|
||||||
|
Ext.Ajax.request({
|
||||||
|
url: '/users/sign_out',
|
||||||
|
method: 'DELETE'
|
||||||
|
});
|
||||||
|
}
|
||||||
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -5,19 +5,18 @@ class Api::V1::BaseController < ActionController::Base
|
|||||||
|
|
||||||
private
|
private
|
||||||
def authenticate_user
|
def authenticate_user
|
||||||
if params[:token]
|
if params[:username]
|
||||||
@current_user = User.find_by_authentication_token(params[:token])
|
|
||||||
else
|
|
||||||
user = User.find_for_database_authentication( :email => params[:username] )
|
user = User.find_for_database_authentication( :email => params[:username] )
|
||||||
@current_user = user if user && user.valid_password?( params[:password] )
|
@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
|
if @current_user.nil?
|
||||||
@current_user
|
msg = "Username/Password/Token invalid"
|
||||||
|
render :json => {:error => msg }, :status => 403 and return
|
||||||
|
end
|
||||||
|
else
|
||||||
|
authenticate_user!
|
||||||
|
@current_user = current_user
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -1,6 +1,7 @@
|
|||||||
class Api::V1::LogsController < Api::V1::BaseController
|
class Api::V1::LogsController < Api::V1::BaseController
|
||||||
|
|
||||||
def checkin
|
def checkin
|
||||||
|
#must use @current_user since user may not have signed in
|
||||||
if @current_user.checked_in?
|
if @current_user.checked_in?
|
||||||
render :json => { "error" => "You are already checked in."}, :status => 404 and return
|
render :json => { "error" => "You are already checked in."}, :status => 404 and return
|
||||||
else
|
else
|
||||||
@ -10,6 +11,7 @@ class Api::V1::LogsController < Api::V1::BaseController
|
|||||||
end
|
end
|
||||||
|
|
||||||
def checkout
|
def checkout
|
||||||
|
#must use @current_user since user may not have signed in
|
||||||
if !@current_user.checked_in?
|
if !@current_user.checked_in?
|
||||||
render :json => { "error" => "You were not even checked in."}, :status => 404 and return
|
render :json => { "error" => "You were not even checked in."}, :status => 404 and return
|
||||||
else
|
else
|
||||||
|
Loading…
x
Reference in New Issue
Block a user