Making it possible for users to easily register existing MACs
This commit is contained in:
		
							parent
							
								
									cad46e45c5
								
							
						
					
					
						commit
						c5e02a51be
					
				@ -12,6 +12,8 @@ end
 | 
				
			|||||||
load_and_authorize_resource :mac, :except => :create
 | 
					load_and_authorize_resource :mac, :except => :create
 | 
				
			||||||
load_and_authorize_resource :user, :through => :mac, :except => [:index, :show, :scan, :import]
 | 
					load_and_authorize_resource :user, :through => :mac, :except => [:index, :show, :scan, :import]
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					before_filter :arp_lookup, :only => :new
 | 
				
			||||||
 | 
					
 | 
				
			||||||
#require "active_record"
 | 
					#require "active_record"
 | 
				
			||||||
require "optparse"
 | 
					require "optparse"
 | 
				
			||||||
#require "rubygems"
 | 
					#require "rubygems"
 | 
				
			||||||
@ -136,7 +138,10 @@ end
 | 
				
			|||||||
    end
 | 
					    end
 | 
				
			||||||
  end
 | 
					  end
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					def arp_lookup
 | 
				
			||||||
 | 
					  @ip = request.env['REMOTE_ADDR']
 | 
				
			||||||
 | 
					  @arp = %x(/usr/sbin/arp -a | grep #{@ip})
 | 
				
			||||||
 | 
					end
 | 
				
			||||||
 | 
					
 | 
				
			||||||
def scan
 | 
					def scan
 | 
				
			||||||
Rails.logger.info "starting scan..."
 | 
					Rails.logger.info "starting scan..."
 | 
				
			||||||
 | 
				
			|||||||
@ -15,6 +15,7 @@ class User < ActiveRecord::Base
 | 
				
			|||||||
  has_many :user_certifications
 | 
					  has_many :user_certifications
 | 
				
			||||||
  has_many :certifications, :through => :user_certifications
 | 
					  has_many :certifications, :through => :user_certifications
 | 
				
			||||||
  has_many :payments
 | 
					  has_many :payments
 | 
				
			||||||
 | 
					  has_many :macs
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  validates_format_of [:twitter_url, :facebook_url, :github_url, :website_url], :with => URI::regexp(%w(http https)), :allow_blank => true
 | 
					  validates_format_of [:twitter_url, :facebook_url, :github_url, :website_url], :with => URI::regexp(%w(http https)), :allow_blank => true
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
				
			|||||||
@ -17,7 +17,8 @@
 | 
				
			|||||||
  </div>
 | 
					  </div>
 | 
				
			||||||
  <div class="field">
 | 
					  <div class="field">
 | 
				
			||||||
    <%= f.label :mac %><br />
 | 
					    <%= f.label :mac %><br />
 | 
				
			||||||
    <%= f.text_field :mac %>
 | 
					    <%= f.text_field :mac, :value => (@mac.mac || @arp || nil) %>
 | 
				
			||||||
 | 
					    <% if @arp.present? %><br/><em>Autodetected from your IP of <%= @ip %></em><% end %>
 | 
				
			||||||
  </div>
 | 
					  </div>
 | 
				
			||||||
  <div class="field">
 | 
					  <div class="field">
 | 
				
			||||||
    <%= f.label :note %><br />
 | 
					    <%= f.label :note %><br />
 | 
				
			||||||
 | 
				
			|||||||
@ -93,6 +93,14 @@
 | 
				
			|||||||
  <% end %>
 | 
					  <% end %>
 | 
				
			||||||
</p>
 | 
					</p>
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					<b>Computers: </b><%= link_to "+ Add", new_mac_path, :class => 'btn' if can? :create, Mac %>
 | 
				
			||||||
 | 
					<ul>
 | 
				
			||||||
 | 
					  <% @user.macs.each do |mac| %>
 | 
				
			||||||
 | 
					    <li><%= link_to mac.mac, mac %></li>
 | 
				
			||||||
 | 
					  <% end %>
 | 
				
			||||||
 | 
					  <% if @user.macs.blank? %><li>n/a</li><% end %>
 | 
				
			||||||
 | 
					</ul>
 | 
				
			||||||
 | 
					
 | 
				
			||||||
<p>
 | 
					<p>
 | 
				
			||||||
  <% if current_user.admin? then %>
 | 
					  <% if current_user.admin? then %>
 | 
				
			||||||
    <b>Payments:</b>
 | 
					    <b>Payments:</b>
 | 
				
			||||||
 | 
				
			|||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user