diff --git a/app/controllers/admin_controller.rb b/app/controllers/admin_controller.rb index 1c5c160..f82afc5 100755 --- a/app/controllers/admin_controller.rb +++ b/app/controllers/admin_controller.rb @@ -1,5 +1,4 @@ class AdminController < ApplicationController - before_filter :administrative, :if => :admin_param skip_before_filter :has_info @@ -67,5 +66,4 @@ class AdminController < ApplicationController def admin_param params[:admin_id] != '1' end - end diff --git a/app/controllers/api/v1/mobile_controller.rb b/app/controllers/api/v1/mobile_controller.rb index 63a575d..f4c01e3 100644 --- a/app/controllers/api/v1/mobile_controller.rb +++ b/app/controllers/api/v1/mobile_controller.rb @@ -1,5 +1,4 @@ class Api::V1::MobileController < ApplicationController - skip_before_filter :authenticated before_filter :mobile_request? @@ -30,5 +29,4 @@ class Api::V1::MobileController < ApplicationController request.user_agent =~ /ios|android/i end end - end diff --git a/app/controllers/api/v1/users_controller.rb b/app/controllers/api/v1/users_controller.rb index 5ee6797..643e5f9 100644 --- a/app/controllers/api/v1/users_controller.rb +++ b/app/controllers/api/v1/users_controller.rb @@ -1,57 +1,54 @@ class Api::V1::UsersController < ApplicationController + skip_before_filter :authenticated + before_filter :valid_api_token + before_filter :extrapolate_user - skip_before_filter :authenticated - before_filter :valid_api_token - before_filter :extrapolate_user + respond_to :json - respond_to :json + def index + # We removed the .as_json code from the model, just seemed like extra work. + # dunno, maybe useful at a later time? + #respond_with @user.admin ? User.all.as_json : @user.as_json + respond_with @user.admin ? User.all : @user + end - def index - # We removed the .as_json code from the model, just seemed like extra work. - # dunno, maybe useful at a later time? - #respond_with @user.admin ? User.all.as_json : @user.as_json + def show + respond_with @user.as_json + end - respond_with @user.admin ? User.all : @user - end + private - def show - respond_with @user.as_json - end + def valid_api_token + authenticate_or_request_with_http_token do |token, options| + # TODO :add some functionality to check if the HTTP Header is valid + identify_user(token) + end + end -private + def identify_user(token="") + # We've had issues with URL encoding, etc. causing issues so just to be safe + # we will go ahead and unescape the user's token + unescape_token(token) + @clean_token =~ /(.*?)-(.*)/ + id = $1 + hash = $2 + (id && hash) ? true : false + check_hash(id, hash) ? true : false + end - def valid_api_token - authenticate_or_request_with_http_token do |token, options| - # TODO :add some functionality to check if the HTTP Header is valid - identify_user(token) - end - end + def check_hash(id, hash) + digest = OpenSSL::Digest::SHA1.hexdigest("#{ACCESS_TOKEN_SALT}:#{id}") + hash == digest + end - def identify_user(token="") - # We've had issues with URL encoding, etc. causing issues so just to be safe - # we will go ahead and unescape the user's token - unescape_token(token) - @clean_token =~ /(.*?)-(.*)/ - id = $1 - hash = $2 - (id && hash) ? true : false - check_hash(id, hash) ? true : false - end - - def check_hash(id, hash) - digest = OpenSSL::Digest::SHA1.hexdigest("#{ACCESS_TOKEN_SALT}:#{id}") - hash == digest - end - - # We had some issues with the token and url encoding... - # this is an attempt to normalize the data. - def unescape_token(token="") - @clean_token = CGI::unescape(token) - end - - # Added a method to make it easy to figure out who the user is. - def extrapolate_user - @user = User.find_by_id(@clean_token.split("-").first) - end + # We had some issues with the token and url encoding... + # this is an attempt to normalize the data. + def unescape_token(token="") + @clean_token = CGI::unescape(token) + end + # Added a method to make it easy to figure out who the user is. + def extrapolate_user + @user = User.find_by_id(@clean_token.split("-").first) + end end diff --git a/app/controllers/application_controller.rb b/app/controllers/application_controller.rb index 5ba7518..dcf7d08 100755 --- a/app/controllers/application_controller.rb +++ b/app/controllers/application_controller.rb @@ -1,5 +1,4 @@ class ApplicationController < ActionController::Base - before_filter :authenticated, :has_info, :create_analytic helper_method :current_user, :is_admin?, :sanitize_font @@ -53,5 +52,4 @@ class ApplicationController < ActionController::Base css # css if css.match(/\A[0-9]+([\%]|pt)\z/) end - end diff --git a/app/controllers/benefit_forms_controller.rb b/app/controllers/benefit_forms_controller.rb index da34c50..23546ba 100644 --- a/app/controllers/benefit_forms_controller.rb +++ b/app/controllers/benefit_forms_controller.rb @@ -4,7 +4,6 @@ class BenefitFormsController < ApplicationController @benefits = Benefits.new end - def download begin path = params[:name] @@ -26,7 +25,6 @@ class BenefitFormsController < ApplicationController redirect_to user_benefit_forms_path(:user_id => current_user.user_id) end - =begin # More secure version def download @@ -47,6 +45,4 @@ class BenefitFormsController < ApplicationController end end =end - - end diff --git a/app/controllers/dashboard_controller.rb b/app/controllers/dashboard_controller.rb index 9ce2834..4bb1c20 100755 --- a/app/controllers/dashboard_controller.rb +++ b/app/controllers/dashboard_controller.rb @@ -1,5 +1,4 @@ class DashboardController < ApplicationController - skip_before_filter :has_info def home @@ -10,5 +9,4 @@ class DashboardController < ApplicationController cookies[:font] = params[:font] end end - end diff --git a/app/controllers/messages_controller.rb b/app/controllers/messages_controller.rb index 706f103..83b992c 100644 --- a/app/controllers/messages_controller.rb +++ b/app/controllers/messages_controller.rb @@ -33,5 +33,4 @@ class MessagesController < ApplicationController end end end - end \ No newline at end of file diff --git a/app/controllers/password_resets_controller.rb b/app/controllers/password_resets_controller.rb index 533643a..98ebdab 100644 --- a/app/controllers/password_resets_controller.rb +++ b/app/controllers/password_resets_controller.rb @@ -1,7 +1,6 @@ class PasswordResetsController < ApplicationController skip_before_filter :authenticated - def reset_password user = Marshal.load(Base64.decode64(params[:user])) unless params[:user].nil? diff --git a/app/controllers/pay_controller.rb b/app/controllers/pay_controller.rb index 2089179..6245c62 100644 --- a/app/controllers/pay_controller.rb +++ b/app/controllers/pay_controller.rb @@ -39,5 +39,4 @@ class PayController < ApplicationController format.json {render :json => {:account_num => decrypted || "No Data" }} end end - end diff --git a/app/controllers/performance_controller.rb b/app/controllers/performance_controller.rb index 767fc65..1ba6aa8 100644 --- a/app/controllers/performance_controller.rb +++ b/app/controllers/performance_controller.rb @@ -3,5 +3,4 @@ class PerformanceController < ApplicationController def index @perf = current_user.performance end - end diff --git a/app/controllers/retirement_controller.rb b/app/controllers/retirement_controller.rb index b3663fc..541b083 100644 --- a/app/controllers/retirement_controller.rb +++ b/app/controllers/retirement_controller.rb @@ -3,5 +3,4 @@ class RetirementController < ApplicationController def index @info = current_user.retirement end - end diff --git a/app/controllers/schedule_controller.rb b/app/controllers/schedule_controller.rb index f9d8a57..65caa2e 100644 --- a/app/controllers/schedule_controller.rb +++ b/app/controllers/schedule_controller.rb @@ -1,4 +1,5 @@ class ScheduleController < ApplicationController + def create message = false @@ -55,5 +56,4 @@ class ScheduleController < ApplicationController end return vals end - end diff --git a/app/controllers/sessions_controller.rb b/app/controllers/sessions_controller.rb index 4b90e41..fdf2edc 100755 --- a/app/controllers/sessions_controller.rb +++ b/app/controllers/sessions_controller.rb @@ -1,35 +1,34 @@ class SessionsController < ApplicationController - skip_before_filter :has_info skip_before_filter :authenticated, :only => [:new, :create] def new - @url = params[:url] - redirect_to home_dashboard_index_path if current_user + @url = params[:url] + redirect_to home_dashboard_index_path if current_user end def create - path = params[:url].present? ? params[:url] : home_dashboard_index_path - begin - # Normalize the email address, why not - user = User.authenticate(params[:email].to_s.downcase, params[:password]) - # @url = params[:url] + path = params[:url].present? ? params[:url] : home_dashboard_index_path + begin + # Normalize the email address, why not + user = User.authenticate(params[:email].to_s.downcase, params[:password]) + # @url = params[:url] rescue Exception => e - end + end - if user - if params[:remember_me] - cookies.permanent[:auth_token] = user.auth_token if User.where(:user_id => user.user_id).exists? - else - session[:user_id] = user.user_id if User.where(:user_id => user.user_id).exists? - end - redirect_to path + if user + if params[:remember_me] + cookies.permanent[:auth_token] = user.auth_token if User.where(:user_id => user.user_id).exists? else - # Removed this code, just doesn't seem specific enough! - # flash[:error] = "Either your username and password is incorrect" - flash[:error] = e.message - render "new" + session[:user_id] = user.user_id if User.where(:user_id => user.user_id).exists? end + redirect_to path + else + # Removed this code, just doesn't seem specific enough! + # flash[:error] = "Either your username and password is incorrect" + flash[:error] = e.message + render "new" + end end def destroy @@ -37,5 +36,4 @@ class SessionsController < ApplicationController reset_session redirect_to root_path end - end diff --git a/app/controllers/tutorials_controller.rb b/app/controllers/tutorials_controller.rb index 3a294d5..d8e977b 100755 --- a/app/controllers/tutorials_controller.rb +++ b/app/controllers/tutorials_controller.rb @@ -1,5 +1,4 @@ class TutorialsController < ApplicationController - skip_before_filter :has_info skip_before_filter :authenticated @@ -18,16 +17,16 @@ class TutorialsController < ApplicationController end def xss - @code = %{ -
  • - - Welcome, <%= current_user.first_name.html_safe %> -
  • - } + @code = %{ +
  • + + Welcome, <%= current_user.first_name.html_safe %> +
  • + } end def broken_auth @@ -45,15 +44,15 @@ class TutorialsController < ApplicationController event.preventDefault(); $.ajax(\{ url: "/example", - data: valuesToSubmit, - type: "POST", - success: function(response) \{ - alert('success!'); - }, - error: function(event) \{ - alert('failure!'); - \} - \}); + data: valuesToSubmit, + type: "POST", + success: function(response) \{ + alert('success!'); + }, + error: function(event) \{ + alert('failure!'); + \} + \}); \}); \} } @@ -95,5 +94,4 @@ class TutorialsController < ApplicationController def metaprogramming end - end diff --git a/app/controllers/users_controller.rb b/app/controllers/users_controller.rb index 9a48c27..1fb5d4a 100755 --- a/app/controllers/users_controller.rb +++ b/app/controllers/users_controller.rb @@ -1,9 +1,7 @@ class UsersController < ApplicationController - skip_before_filter :has_info skip_before_filter :authenticated, :only => [:new, :create] - def new @user = User.new end @@ -52,5 +50,4 @@ class UsersController < ApplicationController redirect_to user_account_settings_path(:user_id => current_user.user_id) end end - end diff --git a/app/controllers/work_info_controller.rb b/app/controllers/work_info_controller.rb index 2238259..29727f4 100644 --- a/app/controllers/work_info_controller.rb +++ b/app/controllers/work_info_controller.rb @@ -1,5 +1,4 @@ class WorkInfoController < ApplicationController - def index @user = User.find_by_user_id(params[:user_id]) if !(@user) || @user.admin @@ -18,5 +17,4 @@ class WorkInfoController < ApplicationController end end =end - end diff --git a/app/models/analytics.rb b/app/models/analytics.rb index 6690504..2d9fbe5 100644 --- a/app/models/analytics.rb +++ b/app/models/analytics.rb @@ -4,16 +4,16 @@ class Analytics < ActiveRecord::Base scope :hits_by_ip, ->(ip,col="*") { select("#{col}").where(:ip_address => ip).order("id DESC")} def self.count_by_col(col) - calculate(:count, col) + calculate(:count, col) end def self.parse_field(field) - valid_fields = ["ip_address", "referrer", "user_agent"] + valid_fields = ["ip_address", "referrer", "user_agent"] - if valid_fields.include?(field) - field - else - "1" - end + if valid_fields.include?(field) + field + else + "1" + end end end diff --git a/app/models/benefits.rb b/app/models/benefits.rb index 9b0feb5..4a1cb9d 100644 --- a/app/models/benefits.rb +++ b/app/models/benefits.rb @@ -1,20 +1,20 @@ class Benefits < ActiveRecord::Base - attr_accessor :backup + attr_accessor :backup - def self.save(file, backup=false) - data_path = Rails.root.join("public", "data") - full_file_name = "#{data_path}/#{file.original_filename}" - f = File.open(full_file_name, "wb+") - f.write file.read - f.close - make_backup(file, data_path, full_file_name) if backup == "true" - end + def self.save(file, backup=false) + data_path = Rails.root.join("public", "data") + full_file_name = "#{data_path}/#{file.original_filename}" + f = File.open(full_file_name, "wb+") + f.write file.read + f.close + make_backup(file, data_path, full_file_name) if backup == "true" + end - def self.make_backup(file, data_path, full_file_name) + def self.make_backup(file, data_path, full_file_name) if File.exists?(full_file_name) silence_streams(STDERR) { system("cp #{full_file_name} #{data_path}/bak#{Time.now.to_i}_#{file.original_filename}") } end - end + end =begin def self.make_backup(file, data_path, full_file_name) @@ -22,17 +22,16 @@ class Benefits < ActiveRecord::Base end =end - def self.silence_streams(*streams) - on_hold = streams.collect { |stream| stream.dup } - streams.each do |stream| - stream.reopen(RUBY_PLATFORM =~ /mswin/ ? 'NUL:' : '/dev/null') - stream.sync = true - end - yield - ensure - streams.each_with_index do |stream, i| - stream.reopen(on_hold[i]) - end - end - + def self.silence_streams(*streams) + on_hold = streams.collect { |stream| stream.dup } + streams.each do |stream| + stream.reopen(RUBY_PLATFORM =~ /mswin/ ? 'NUL:' : '/dev/null') + stream.sync = true + end + yield + ensure + streams.each_with_index do |stream, i| + stream.reopen(on_hold[i]) + end + end end diff --git a/app/models/key_management.rb b/app/models/key_management.rb index f15c339..70adbd1 100644 --- a/app/models/key_management.rb +++ b/app/models/key_management.rb @@ -2,5 +2,4 @@ class KeyManagement < ActiveRecord::Base attr_accessible :iv, :user_id belongs_to :work_info belongs_to :user - end diff --git a/app/models/paid_time_off.rb b/app/models/paid_time_off.rb index 8c980b6..409d355 100644 --- a/app/models/paid_time_off.rb +++ b/app/models/paid_time_off.rb @@ -14,5 +14,4 @@ class PaidTimeOff < ActiveRecord::Base def sick_days_taken_percentage result = self.sick_days_taken.to_f / self.sick_days_earned.to_f * 100.0 end - end diff --git a/app/models/pay.rb b/app/models/pay.rb index 56616b1..2218d11 100644 --- a/app/models/pay.rb +++ b/app/models/pay.rb @@ -1,5 +1,4 @@ class Pay < ActiveRecord::Base - # mass-assignable attributes attr_accessible :bank_account_num, :bank_routing_num, :percent_of_deposit @@ -21,5 +20,4 @@ class Pay < ActiveRecord::Base def encrypt_bank_account_num self.bank_account_num = Encryption.encrypt_sensitive_value(self.bank_account_num) end - end diff --git a/app/models/user.rb b/app/models/user.rb index 7af6ed9..9c5cc7f 100755 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -1,7 +1,6 @@ require 'encryption' class User < ActiveRecord::Base - attr_accessible :email, :admin, :first_name, :last_name, :user_id, :password, :password_confirmation validates :password, :presence => true, :confirmation => true, @@ -49,18 +48,18 @@ class User < ActiveRecord::Base end =end -private + private def self.authenticate(email, password) - auth = nil - user = find_by_email(email) - raise "#{email} doesn't exist!" if !(user) - if user.password == Digest::MD5.hexdigest(password) - auth = user - else - raise "Incorrect Password!" - end - return auth + auth = nil + user = find_by_email(email) + raise "#{email} doesn't exist!" if !(user) + if user.password == Digest::MD5.hexdigest(password) + auth = user + else + raise "Incorrect Password!" + end + return auth end =begin @@ -76,11 +75,11 @@ private =end def assign_user_id - unless @skip_user_id_assign.present? || self.user_id.present? + unless @skip_user_id_assign.present? || self.user_id.present? user = User.order("user_id").last uid = user.user_id.to_i + 1 if user && user.user_id && !(User.exists?(:user_id => "#{user.user_id.to_i + 1}")) self.user_id = uid.to_s if uid - end + end end def hash_password @@ -96,5 +95,4 @@ private self[column] = Encryption.encrypt_sensitive_value(self.user_id) end while User.exists?(column => self[column]) end - end diff --git a/app/models/work_info.rb b/app/models/work_info.rb index e594766..2816dfa 100644 --- a/app/models/work_info.rb +++ b/app/models/work_info.rb @@ -4,27 +4,26 @@ class WorkInfo < ActiveRecord::Base has_one :key_management, :foreign_key => :user_id, :primary_key => :user_id, :dependent => :destroy #before_save :encrypt_ssn - # We should probably use this def last_four - "***-**-" << self.decrypt_ssn[-4,4] + "***-**-" << self.decrypt_ssn[-4,4] end def encrypt_ssn - aes = OpenSSL::Cipher::Cipher.new(cipher_type) - aes.encrypt - aes.key = key - aes.iv = iv if iv != nil - self.encrypted_ssn = aes.update(self.SSN) + aes.final - self.SSN = nil + aes = OpenSSL::Cipher::Cipher.new(cipher_type) + aes.encrypt + aes.key = key + aes.iv = iv if iv != nil + self.encrypted_ssn = aes.update(self.SSN) + aes.final + self.SSN = nil end def decrypt_ssn - aes = OpenSSL::Cipher::Cipher.new(cipher_type) - aes.decrypt - aes.key = key - aes.iv = iv if iv != nil - aes.update(self.encrypted_ssn) + aes.final + aes = OpenSSL::Cipher::Cipher.new(cipher_type) + aes.decrypt + aes.key = key + aes.iv = iv if iv != nil + aes.update(self.encrypted_ssn) + aes.final end def key @@ -40,5 +39,4 @@ class WorkInfo < ActiveRecord::Base def cipher_type 'aes-256-cbc' end - end diff --git a/app/views/admin/dashboard.html.erb b/app/views/admin/dashboard.html.erb index 7998520..854f39c 100755 --- a/app/views/admin/dashboard.html.erb +++ b/app/views/admin/dashboard.html.erb @@ -1,70 +1,60 @@
    -
    -
    -
    - -
    -
    -
    -
    - -
    -
    -
    -
    -
    -
    -
    - - Manage Users -
    -
    -
    +
    +
    +
    + +
    +
    -
    -
    -
    -
    -
    +
    +
    + +
    +
    +
    +
    +
    +
    +
    + Manage Users +
    +
    +
    +
    +
    +
    +
    +
    <%= javascript_include_tag "jquery.dataTables.js"%> \ No newline at end of file diff --git a/app/views/benefit_forms/index.html.erb b/app/views/benefit_forms/index.html.erb index a212c20..818ab08 100644 --- a/app/views/benefit_forms/index.html.erb +++ b/app/views/benefit_forms/index.html.erb @@ -1,134 +1,126 @@
    -
    +
    -
    +
    -
    -
    -
    -
    - Health Insurance -
    -
    - -
    - Click on PDF to download

    - <%= link_to download_path(:type => "File", :name => "public/docs/Health_n_Stuff.pdf") do %> -
    -
    - - - PDF - -
    +
    +
    +
    +
    + Health Insurance +
    +
    + +
    + Click on PDF to download

    + <%= link_to download_path(:type => "File", :name => "public/docs/Health_n_Stuff.pdf") do %> +
    +
    + + + PDF + +
    -
    - <% end %> -
    - -
    -
    +
    + <% end %> +
    + +
    +
    -
    -
    -
    -
    - Dental Insurance -
    -
    - -
    - Click on PDF to download

    - <%= link_to download_path(:type => "File", :name => "public/docs/Dental_n_Stuff.pdf") do %> -
    -
    - - - PDF - -
    +
    +
    +
    +
    + Dental Insurance +
    +
    + +
    + Click on PDF to download

    + <%= link_to download_path(:type => "File", :name => "public/docs/Dental_n_Stuff.pdf") do %> +
    +
    + + + PDF + +
    -
    - <% end %> -
    - -
    -
    -
    -
    -
    -
    -
    -
    - Health Insurance -
    -
    - -
    -
    -

    Upload file

    - <%= form_for @benefits, :url => upload_path, :html => { :action => "upload", :multipart => true, :id => "fi" } do |f| %> - -
    -
    - <%= hidden_field "benefits", "backup", :value => false %> - - - - Add file - <%= f.file_field :upload %> - - -

    Nothing selected -
    -
    - -
    -
    -
    -
    -
    - -
    -
    - - -
    - <% end %> -
    -
    -
    +
    + <% end %> +
    + +
    +
    +
    +
    +
    +
    +
    +
    + Health Insurance +
    +
    + +
    +
    +

    Upload file

    + <%= form_for @benefits, :url => upload_path, :html => { :action => "upload", :multipart => true, :id => "fi" } do |f| %> + +
    +
    + <%= hidden_field "benefits", "backup", :value => false %> + + + + Add file + <%= f.file_field :upload %> + + +

    Nothing selected +
    +
    + +
    +
    +
    +
    +
    + +
    +
    + + +
    + <% end %> +
    +
    +
    -
    -
    -
    -
    -
    -
    +
    +
    +
    +
    +
    +
    - - \ No newline at end of file diff --git a/app/views/dashboard/home.html.erb b/app/views/dashboard/home.html.erb index 8276848..8fc9788 100755 --- a/app/views/dashboard/home.html.erb +++ b/app/views/dashboard/home.html.erb @@ -1,172 +1,167 @@
    - -
    - -
    -
    - <% if @user.paid_time_off %> - <%= render :partial => "layouts/dashboard/dashboard_stats"%> - <% end %> -
    -
    -
    +
    +
    +
    + <% if @user.paid_time_off %> + <%= render :partial => "layouts/dashboard/dashboard_stats"%> + <% end %> +
    +
    +
    diff --git a/app/views/layouts/admin/_analytics.html.erb b/app/views/layouts/admin/_analytics.html.erb index 52928bb..be676a0 100644 --- a/app/views/layouts/admin/_analytics.html.erb +++ b/app/views/layouts/admin/_analytics.html.erb @@ -18,16 +18,16 @@ <% @analytics.each do |a|%> - + <% a.attributes.each do |k,v| %> <%= v %> <% end %> - <% end %> + <% end %> - +
    @@ -36,11 +36,10 @@ \ No newline at end of file diff --git a/app/views/layouts/admin/_get_all_users.html.erb b/app/views/layouts/admin/_get_all_users.html.erb index ee4dca2..8f3bf5d 100755 --- a/app/views/layouts/admin/_get_all_users.html.erb +++ b/app/views/layouts/admin/_get_all_users.html.erb @@ -18,25 +18,25 @@ <% @users.each do |u|%> - - - <%= "#{u.first_name} #{u.last_name}"%> - - - <%= u.email%> - - - <%= u.admin ? %{