<?xml version="1.0" encoding="UTF-8"?>
<commit>
  <added type="array">
    <added>
      <filename>app/controllers/administration/api_keys_controller.rb</filename>
    </added>
    <added>
      <filename>app/views/administration/api_keys/show.html.erb</filename>
    </added>
    <added>
      <filename>db/migrate/20080805202133_add_api_key_to_people.rb</filename>
    </added>
  </added>
  <modified type="array">
    <modified>
      <diff>@@ -50,8 +50,12 @@ class ApplicationController &lt; ActionController::Base
         Person.logged_in = @logged_in = Person.find_by_id(id)
       end
     end
+    
+    def authenticate_user # default
+      authenticate_user_with_http_basic_or_session
+    end
   
-    def authenticate_user
+    def authenticate_user_with_session
       if id = session[:logged_in_id]
         unless person = Person.find_by_id(id)
           session[:logged_in_id] = nil
@@ -77,18 +81,19 @@ class ApplicationController &lt; ActionController::Base
     
     def authenticate_user_with_code_or_session
       unless params[:code] and Person.logged_in = @logged_in = Person.find_by_feed_code(params[:code])
-        authenticate_user
+        authenticate_user_with_session
       end
     end
     
-    def authenticate_user_with_http_basic
-      authenticate_with_http_basic do |username, password|
-        if (key = password.any? ? password : username).any?
-          Person.logged_in = @logged_in = Person.find_by_feed_code(key)
+    def authenticate_user_with_http_basic_or_session
+      authenticate_with_http_basic do |email, api_key|
+        if email.to_s.any? and api_key.to_s.length == 50
+          Person.logged_in = @logged_in = Person.find_by_email_and_api_key(email, api_key)
+          Person.logged_in = @logged_in = nil unless @logged_in.super_admin?
         end
       end
       unless @logged_in
-        authenticate_user
+        authenticate_user_with_session
       end
     end
     </diff>
      <filename>app/controllers/application.rb</filename>
    </modified>
    <modified>
      <diff>@@ -481,11 +481,15 @@ class Person &lt; ActiveRecord::Base
   before_create :update_feed_code
   def update_feed_code
     begin # ensure unique
-      code = (1..50).collect { (i = Kernel.rand(62); i += ((i &lt; 10) ? 48 : ((i &lt; 36) ? 55 : 61 ))).chr }.join
+      code = random_chars(50)
       write_attribute :feed_code, code
     end while Person.count('*', :conditions =&gt; ['feed_code = ?', code]) &gt; 0
   end
   
+  def generate_api_key
+    write_attribute :api_key, random_chars(50)
+  end
+  
   def update_from_params(params)
     person_basics = %w(first_name last_name suffix mobile_phone work_phone fax city state zip birthday anniversary gender address1 address2 city state zip)
     if params[:photo_url] and params[:photo_url].length &gt; 7 # not just &quot;http://&quot;</diff>
      <filename>app/models/person.rb</filename>
    </modified>
    <modified>
      <diff>@@ -71,6 +71,7 @@ ActionController::Routing::Routes.draw do |map|
 
   map.admin 'admin', :controller =&gt; 'administration/dashboards'
   map.namespace :administration, :path_prefix =&gt; 'admin' do |admin|
+    admin.resource :api_key
     admin.resources :updates
     admin.resources :admins
     admin.resources :membership_requests</diff>
      <filename>config/routes.rb</filename>
    </modified>
  </modified>
  <removed type="array"/>
  <parents type="array">
    <parent>
      <id>78744b9b9f919a7c7f975395f39c7428468fcc3b</id>
    </parent>
  </parents>
  <author>
    <name>Tim Morgan</name>
    <email>tim@timmorgan.org</email>
  </author>
  <url>http://github.com/seven1m/onebody/commit/c07a5659540caa54be9dd050b4836e498addc329</url>
  <id>c07a5659540caa54be9dd050b4836e498addc329</id>
  <committed-date>2008-08-05T14:06:47-07:00</committed-date>
  <authored-date>2008-08-05T06:14:00-07:00</authored-date>
  <message>Added API key support and http basic authentication.</message>
  <tree>d7557d1b9ff9b728c1da1fd3ecb33149a702582d</tree>
  <committer>
    <name>Tim Morgan</name>
    <email>tim@timmorgan.org</email>
  </committer>
</commit>
