mirror of https://github.com/fspc/BikeShed-1.git
John N. Milner
12 years ago
27 changed files with 303 additions and 65 deletions
@ -0,0 +1,43 @@ |
|||
$("#checkin_menu").show(); |
|||
$("#checkin").click( function(e){ |
|||
var username = $("#user_email").val(); |
|||
var password = $("#user_password").val(); |
|||
$.ajax({ |
|||
type: 'POST', |
|||
url: '/api/v1/checkin', |
|||
dataType: 'json', |
|||
contentType: 'application/json', |
|||
processData: false, |
|||
data: JSON.stringify({"username": username, "password": password }), |
|||
complete: function() { }, |
|||
success: function(data) { |
|||
alert("Checked IN!"); |
|||
$("#user_email").val(''); |
|||
$("#user_password").val(''); |
|||
}, |
|||
error: function(data,textStatus) { |
|||
alert( "Error: " + JSON.parse(data.responseText)["error"]); |
|||
} |
|||
}) |
|||
}); |
|||
$("#checkout").click( function(e){ |
|||
var username = $("#user_email").val(); |
|||
var password = $("#user_password").val(); |
|||
$.ajax({ |
|||
type: 'POST', |
|||
url: '/api/v1/checkout', |
|||
dataType: 'json', |
|||
contentType: 'application/json', |
|||
processData: false, |
|||
data: JSON.stringify({"username": username, "password": password }), |
|||
complete: function() { }, |
|||
success: function(data) { |
|||
alert("Checked OUT!"); |
|||
$("#user_email").val(''); |
|||
$("#user_password").val(''); |
|||
}, |
|||
error: function(data,textStatus) { |
|||
alert( "Error: " + JSON.parse(data.responseText)["error"]); |
|||
} |
|||
}) |
|||
}); |
@ -0,0 +1,21 @@ |
|||
class UserRoleJoins < Netzke::Basepack::Grid |
|||
def configure(c) |
|||
super |
|||
c.model = "UserRoleJoin" |
|||
c.header = false |
|||
c.title = "User Roles" |
|||
c.columns = [ |
|||
{ :name => :user__first_name, :text => "First"}, |
|||
{ :name => :user__last_name, :text => "Last"}, |
|||
{ :name => :role__role, :text => "Role"}, |
|||
:created_at, |
|||
:updated_at, |
|||
:ends ] |
|||
end |
|||
|
|||
#override with nil to remove actions |
|||
def default_bbar |
|||
[ :apply, :add_in_form, :search ] |
|||
end |
|||
|
|||
end |
@ -1,15 +0,0 @@ |
|||
class UserRoles < Netzke::Basepack::Grid |
|||
|
|||
def configure(c) |
|||
super |
|||
c.model = "UserRole" |
|||
c.title = "User Roles" |
|||
c.columns = [ :role, :created_at, :updated_at, :ends ] |
|||
end |
|||
|
|||
#override with nil to remove actions |
|||
def default_bbar |
|||
[ :apply, :add_in_form, :search ] |
|||
end |
|||
|
|||
end |
@ -0,0 +1,22 @@ |
|||
class Api::V1::BaseController < ActionController::Base |
|||
respond_to :json |
|||
|
|||
before_filter :authenticate_user |
|||
|
|||
private |
|||
def authenticate_user |
|||
if params[:username] |
|||
user = User.find_for_database_authentication( :email => params[:username] ) |
|||
@current_user = user if user && user.valid_password?( params[:password] ) |
|||
|
|||
if @current_user.nil? |
|||
msg = "Username/Password/Token invalid" |
|||
render :json => {:error => msg }, :status => 403 and return |
|||
end |
|||
else |
|||
authenticate_user! |
|||
@current_user = current_user |
|||
end |
|||
end |
|||
end |
|||
|
@ -0,0 +1,22 @@ |
|||
class Api::V1::LogsController < Api::V1::BaseController |
|||
|
|||
def checkin |
|||
#must use @current_user since user may not have signed in |
|||
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 |
|||
#must use @current_user since user may not have signed in |
|||
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 |
@ -0,0 +1,16 @@ |
|||
class Role < ActiveRecord::Base |
|||
attr_accessible :role |
|||
|
|||
has_many :user_role_joins |
|||
has_many :users, through: :user_role_joins |
|||
validates_uniqueness_of :role |
|||
|
|||
|
|||
def to_s |
|||
self.role |
|||
end |
|||
|
|||
def ==(other) |
|||
self.role == other.role |
|||
end |
|||
end |
@ -1,11 +0,0 @@ |
|||
class UserRole < ActiveRecord::Base |
|||
attr_accessible :role |
|||
|
|||
belongs_to :user |
|||
|
|||
self.per_page = 15 |
|||
|
|||
def to_s |
|||
self.role |
|||
end |
|||
end |
@ -0,0 +1,13 @@ |
|||
class UserRoleJoin < ActiveRecord::Base |
|||
self.table_name = :user_role_joins |
|||
attr_accessible :role_id, :user_id, :ends |
|||
|
|||
belongs_to :user |
|||
belongs_to :role |
|||
|
|||
validate :role_id, presence: true, numericality: true |
|||
validate :user_id, presence: true, numericality: true |
|||
validates_uniqueness_of :user_id, :scope => :role_id |
|||
|
|||
self.per_page = 15 |
|||
end |
@ -0,0 +1,9 @@ |
|||
class AlterUserRoles < ActiveRecord::Migration |
|||
def change |
|||
rename_table :user_roles, :user_role_joins |
|||
change_table :user_role_joins do |t| |
|||
t.rename :role, :role_id |
|||
t.change :role_id, :integer |
|||
end |
|||
end |
|||
end |
@ -0,0 +1,8 @@ |
|||
class AddRoles < ActiveRecord::Migration |
|||
def change |
|||
create_table(:roles) do |t| |
|||
t.string :role |
|||
t.timestamps |
|||
end |
|||
end |
|||
end |
@ -0,0 +1,5 @@ |
|||
class AlterUser < ActiveRecord::Migration |
|||
def change |
|||
remove_column :users, :user_role_id |
|||
end |
|||
end |
@ -0,0 +1,9 @@ |
|||
user: |
|||
id: 1 |
|||
role: user |
|||
staff: |
|||
id: 2 |
|||
role: staff |
|||
admin: |
|||
id: 3 |
|||
role: admin |
@ -1,5 +1,5 @@ |
|||
FactoryGirl.define do |
|||
factory :user_role do |
|||
factory :role do |
|||
factory :role_staff do |
|||
role 'staff' |
|||
end |
Loading…
Reference in new issue