mirror of https://github.com/fspc/BikeShed-1.git
Jason Denney
12 years ago
28 changed files with 393 additions and 29 deletions
@ -0,0 +1,51 @@ |
|||
$(document).ready(function(){ |
|||
var MIN_LEN = 3; |
|||
var MAX_SUBMITS = 3; |
|||
var submit_count = 0; |
|||
$("input[name=commit]").click( function(e){ |
|||
console.log("clicked"); |
|||
submit_count += 1; |
|||
//IDs of contact info
|
|||
var contact_info_ids = [ |
|||
"user_email", |
|||
"user_user_profiles_attributes_0_addrStreet1", |
|||
"user_user_profiles_attributes_0_addrCity", |
|||
"user_user_profiles_attributes_0_addrState", |
|||
"user_user_profiles_attributes_0_addrZip", |
|||
"user_user_profiles_attributes_0_phone" |
|||
]; |
|||
var contact_vals = ""; |
|||
var index = 0; |
|||
//see if any contact info exists
|
|||
for( var index in contact_info_ids){ |
|||
contact_vals += $("#"+contact_info_ids[index]).val(); |
|||
} |
|||
if( contact_vals.length >= MIN_LEN || submit_count > MAX_SUBMITS){ |
|||
|
|||
if( submit_count > MAX_SUBMITS ){ |
|||
alert("Fine."); |
|||
} |
|||
return true; |
|||
|
|||
}else{ |
|||
|
|||
switch(submit_count){ |
|||
case 1: |
|||
alert("It appears you have not entered any contact information. " + |
|||
"Please do."); |
|||
break; |
|||
case 2: |
|||
alert("It is highly recommended that you enter at least one form of" + |
|||
" contact information. It is in your best interest."); |
|||
break; |
|||
case 3: |
|||
alert("If something happens to your bicycle, we will not be able to" + |
|||
" notify you. Please enter at least one form of contact."); |
|||
break; |
|||
default: |
|||
alert("Please enter at least one form of contact."); |
|||
} |
|||
return false; |
|||
} |
|||
}); |
|||
}); |
@ -0,0 +1,23 @@ |
|||
class CheckIns < Netzke::Basepack::Grid |
|||
|
|||
def configure(c) |
|||
super |
|||
c.header = false |
|||
c.model = "ActsAsLoggable::Log" |
|||
c.scope = lambda { |rel| rel.where(:log_action_type => ::ActsAsLoggable::UserAction). |
|||
where(:loggable_type => "User"). |
|||
where(:log_action_id => ::ActsAsLoggable::UserAction.find_by_action("CHECKIN")). |
|||
where("start_date >= ?", Time.zone.now.beginning_of_day); |
|||
} |
|||
c.columns = [ |
|||
{ :name => :name, :getter => lambda{ |rec| |
|||
user = User.find_by_id(rec.loggable_id) |
|||
user.nil? ? "" : "#{user.first_name} #{user.last_name}" |
|||
} |
|||
}, |
|||
{ :name => "Status", :getter => lambda{ |rec| rec.start_date == rec.end_date ? "Checked In" : "Checked Out" } }, |
|||
:start_date, |
|||
:end_date, |
|||
] |
|||
end |
|||
end |
@ -0,0 +1,28 @@ |
|||
require 'securerandom' |
|||
class Api::V1::UsersController < Api::V1::BaseController |
|||
|
|||
def password_reset |
|||
if can? :manage, User |
|||
user = User.find_by_id(params[:user_id]) |
|||
render :json => { "error" => "User not found"}, :status => 404 and return if user.nil? |
|||
render :json => { "error" => "Not allowed to reset your own password in this fashion."}, :status => 403 and return if user.id == current_user.id |
|||
|
|||
new_pass = SecureRandom.hex[0,8] |
|||
user.password = new_pass |
|||
user.save |
|||
render :json => { "password" => new_pass}, :status => 200 and return |
|||
else |
|||
render :json => { "error" => "You do not have the permission"}, :status => 403 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,23 @@ |
|||
module DeviseHelper |
|||
# A simple way to show error messages for the current devise resource. If you need |
|||
# to customize this method, you can either overwrite it in your application helpers or |
|||
# copy the views to your application. |
|||
# |
|||
# This method is intended to stay simple and it is unlikely that we are going to change |
|||
# it to add more behavior or options. |
|||
def devise_error_messages! |
|||
return "" if resource.errors.empty? |
|||
|
|||
messages = resource.errors.full_messages.map { |msg| content_tag(:p, msg, :class => "alert") }.join |
|||
sentence = I18n.t("errors.messages.not_saved", |
|||
:count => resource.errors.count, |
|||
:resource => resource.class.model_name.human.downcase) |
|||
|
|||
html = <<-HTML |
|||
<p>#{sentence}</p> |
|||
#{messages} |
|||
HTML |
|||
|
|||
html.html_safe |
|||
end |
|||
end |
@ -0,0 +1,6 @@ |
|||
class AddUsernameToUser < ActiveRecord::Migration |
|||
def change |
|||
add_column :users, :username, :string |
|||
add_index :users, :username, :unique => true |
|||
end |
|||
end |
Loading…
Reference in new issue