From 921ba21a400806af273a1e52fc4258ad978b4f8e Mon Sep 17 00:00:00 2001 From: Will Bradley Date: Sat, 15 Sep 2012 20:41:17 -0700 Subject: [PATCH] Had to modify door log model and add config.yml to avoid storing password in git --- .gitignore | 3 +++ app/controllers/users_controller.rb | 6 +++--- app/models/door_log.rb | 14 +++++++++----- app/models/user.rb | 2 +- app/views/layouts/application.html.erb | 2 -- app/views/users/_form.html.erb | 14 ++++++++++++++ app/views/users/index.html.erb | 2 +- config/config.yml.example | 11 +++++++++++ config/initializers/load_config.rb | 1 + 9 files changed, 43 insertions(+), 12 deletions(-) create mode 100644 config/config.yml.example create mode 100644 config/initializers/load_config.rb diff --git a/.gitignore b/.gitignore index 1aa65a5..705de5c 100644 --- a/.gitignore +++ b/.gitignore @@ -16,3 +16,6 @@ # Ignore compiled assets /public/assets + +# Ignore config file +/config/config.yml diff --git a/app/controllers/users_controller.rb b/app/controllers/users_controller.rb index 5f6e135..fdfdb03 100644 --- a/app/controllers/users_controller.rb +++ b/app/controllers/users_controller.rb @@ -69,7 +69,7 @@ class UsersController < ApplicationController respond_to do |format| if @user.save - format.html { redirect_to @user, :notice => 'User was successfully created.' } + format.html { redirect_to users_url, :notice => 'User was successfully created.' } format.json { render :json => @user, :status => :created, :location => @user } else format.html { render :action => "new" } @@ -85,7 +85,7 @@ class UsersController < ApplicationController respond_to do |format| if @user.update_attributes(params[:user]) - format.html { redirect_to @user, :notice => 'User was successfully updated.' } + format.html { redirect_to users_url, :notice => 'User was successfully updated.' } format.json { head :no_content } else format.html { render :action => "edit" } @@ -101,7 +101,7 @@ class UsersController < ApplicationController @user.destroy respond_to do |format| - format.html { redirect_to users_url } + format.html { redirect_to users_url, :notice => 'User successfully deleted.' } format.json { head :no_content } end end diff --git a/app/models/door_log.rb b/app/models/door_log.rb index 646e5b5..267a893 100644 --- a/app/models/door_log.rb +++ b/app/models/door_log.rb @@ -3,14 +3,18 @@ class DoorLog < ActiveRecord::Base require 'open-uri' def self.download_from_door - # do shit here - source = open("http://192.168.1.177?e=1234").read + # load config values + door_access_url = APP_CONFIG['door_access_url'] + door_access_password = APP_CONFIG['door_access_password'] + + # connect to door access system + source = open("#{door_access_url}?e=#{door_access_password}").read results = source.scan(/authok/) if(results.size > 0) then @end_results = Array.new #only continue if we've got an OK login - source = open("http://192.168.1.177?z").read + source = open("#{door_access_url}?z").read results = source.scan(/(.*): (.*)\r\n/) results.each do |r| @@ -20,9 +24,9 @@ class DoorLog < ActiveRecord::Base end #clear log - open("http://192.168.1.177?y") + open("#{door_access_url}?y") #logout - open("http://192.168.1.177?e=0000") + open("#{door_access_url}?e=0000") if(results.size > 0) then #only return true if we got some kind of decent response diff --git a/app/models/user.rb b/app/models/user.rb index b44fbb7..6277ac3 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -2,7 +2,7 @@ class User < ActiveRecord::Base # Include default devise modules. Others available are: # :token_authenticatable, :confirmable, # :lockable, :timeoutable and :omniauthable - devise :database_authenticatable, :registerable, + devise :database_authenticatable, # :registerable, :recoverable, :rememberable, :trackable, :validatable # Setup accessible (or protected) attributes for your model diff --git a/app/views/layouts/application.html.erb b/app/views/layouts/application.html.erb index b226d38..cb3d6eb 100644 --- a/app/views/layouts/application.html.erb +++ b/app/views/layouts/application.html.erb @@ -10,10 +10,8 @@

<%= notice %>

<%= alert %>

diff --git a/app/views/users/_form.html.erb b/app/views/users/_form.html.erb index 8cd4743..5af47f9 100644 --- a/app/views/users/_form.html.erb +++ b/app/views/users/_form.html.erb @@ -15,6 +15,20 @@ <%= f.label :name %>
<%= f.text_field :name %> +
+ <%= f.label :email %>
+ <%= f.email_field :email %> +
+ <% if @user.id.blank? %> +
+ <%= f.label :password %> (leave blank if you don't want to change it)
+ <%= f.password_field :password, :autocomplete => "off" %> +
+
+ <%= f.label :password_confirmation %>
+ <%= f.password_field :password_confirmation %> +
+<% end %>
<%= f.label :card_id, "Card DB ID" %>
<%= f.number_field :card_id, :in => 10...201 %> diff --git a/app/views/users/index.html.erb b/app/views/users/index.html.erb index 47f3082..22c33aa 100644 --- a/app/views/users/index.html.erb +++ b/app/views/users/index.html.erb @@ -22,7 +22,7 @@ <%= user.card_permissions %> <%= link_to 'Upload', upload_path(user) %> <%= link_to 'Edit', edit_user_path(user) %> - <%= link_to 'Destroy', user, :confirm => 'Are you sure?', :method => :delete %> + <%= link_to 'Destroy', user, :confirm => 'Are you sure? WARNING: THIS DOES NOT REMOVE THE USER FROM THE DOOR SYSTEM! DISABLE THEM FIRST.', :method => :delete %> <% end %> <% end %> diff --git a/config/config.yml.example b/config/config.yml.example new file mode 100644 index 0000000..7149927 --- /dev/null +++ b/config/config.yml.example @@ -0,0 +1,11 @@ +development: + door_access_url: "http://192.168.1.100" + door_access_password: "1234" + +test: + door_access_url: "http://192.168.1.100" + door_access_password: "1234" + +production: + door_access_url: "http://192.168.1.100" + door_access_password: "1234" diff --git a/config/initializers/load_config.rb b/config/initializers/load_config.rb new file mode 100644 index 0000000..e687429 --- /dev/null +++ b/config/initializers/load_config.rb @@ -0,0 +1 @@ +APP_CONFIG = YAML.load_file("#{Rails.root}/config/config.yml")[Rails.env]