Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Comparing changes

Choose two branches to see what's changed or to start a new pull request. If you need to, you can also compare across forks.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also compare across forks.
  • 9 commits
  • 208 files changed
  • 0 commit comments
  • 1 contributor
Commits on Mar 19, 2009
@lardawge lardawge Updated to rails 2.3, swfupload beta 5, and uses rack middleware to n…
…egotiate with rails. No more messy cgi hack!
51df82f
Commits on May 14, 2009
@lardawge lardawge Changed so that you only see pictures created my the current_user (th…
…ought it more useful for live applications and because at one point I was looking for a way to do this when I was learning).
ad0ab7d
@lardawge lardawge Removed log files 0a03c4e
@lardawge lardawge Removed debug in show page c4b50b1
Commits on Aug 07, 2010
@lardawge lardawge Updated to rails 3 60971d1
@lardawge lardawge Remove rogue folder f2dc3b3
Commits on Aug 08, 2010
@lardawge lardawge Now works with session store f2a3e67
Commits on Jan 25, 2013
@lardawge lardawge Move README to markdown bf95065
@lardawge lardawge Add badge indicating status of repo cc2d446
Showing with 12,377 additions and 5,746 deletions.
  1. +6 −0 .gitignore
  2. +32 −0 Gemfile
  3. +78 −0 Gemfile.lock
  4. +0 −39 README
  5. +22 −0 README.md
  6. +2 −5 Rakefile
  7. +0 −19 app/controllers/application.rb
  8. +5 −0 app/controllers/application_controller.rb
  9. +2 −6 app/controllers/assets_controller.rb
  10. +3 −5 app/controllers/sessions_controller.rb
  11. +0 −1  app/helpers/application_helper.rb
  12. +4 −0 app/helpers/assets_helper.rb
  13. +36 −0 app/middleware/flash_session_cookie_middleware.rb
  14. +14 −15 app/models/asset.rb
  15. +23 −11 app/models/user.rb
  16. +0 −1  app/views/assets/edit.html.erb
  17. +4 −4 app/views/assets/index.html.erb
  18. +1 −1  app/views/assets/new.html.erb
  19. +1 −3 app/views/assets/show.html.erb
  20. +3 −3 app/views/layouts/{layout.html.erb → application.html.erb}
  21. +4 −5 app/views/sessions/new.html.erb
  22. +4 −0 config.ru
  23. +43 −0 config/application.rb
  24. +13 −109 config/boot.rb
  25. +3 −0  config/database.yml
  26. +4 −69 config/environment.rb
  27. +18 −13 config/environments/development.rb
  28. +43 −16 config/environments/production.rb
  29. +30 −17 config/environments/test.rb
  30. +7 −0 config/initializers/backtrace_silencers.rb
  31. +2 −2 config/initializers/inflections.rb
  32. +0 −15 config/initializers/new_rails_defaults.rb
  33. +7 −0 config/initializers/secret_token.rb
  34. +8 −0 config/initializers/session_store.rb
  35. +3 −0  config/initializers/swfupload_middleware_loader.rb
  36. +0 −30 config/initializers/swfupload_session_hack.rb
  37. +5 −0 config/locales/en.yml
  38. +46 −27 config/routes.rb
  39. +6 −9 db/migrate/20080731103639_create_assets.rb
  40. +1 −1  db/migrate/{20080731103753_create_users.rb → 20100807024304_create_users.rb}
  41. +12 −15 db/schema.rb
  42. +8 −0 db/seeds.rb
  43. +0 −2  doc/README_FOR_APP
  44. +9 −7 lib/authenticated_system.rb
  45. +1 −1  lib/authenticated_test_helper.rb
  46. 0  public/favicon.ico → lib/tasks/.gitkeep
  47. 0  log/production.log
  48. +15 −19 public/404.html
  49. +15 −19 public/422.html
  50. +15 −19 public/500.html
  51. BIN  public/assets/.DS_Store
  52. +0 −10 public/dispatch.cgi
  53. +0 −24 public/dispatch.fcgi
  54. +0 −10 public/dispatch.rb
  55. BIN  public/flash/swfupload.swf
  56. +2 −0  public/javascripts/application.js
  57. +965 −0 public/javascripts/controls.js
  58. +974 −0 public/javascripts/dragdrop.js
  59. +1,123 −0 public/javascripts/effects.js
  60. +6,001 −0 public/javascripts/prototype.js
  61. +175 −0 public/javascripts/rails.js
  62. +0 −5 public/robots.txt
  63. 0  log/test.log → public/stylesheets/.gitkeep
  64. +0 −3  script/about
  65. +0 −3  script/console
  66. +0 −3  script/dbconsole
  67. +0 −3  script/destroy
  68. +0 −3  script/generate
  69. +0 −3  script/performance/benchmarker
  70. +0 −3  script/performance/profiler
  71. +0 −3  script/performance/request
  72. +0 −3  script/plugin
  73. +0 −3  script/process/inspector
  74. +0 −3  script/process/reaper
  75. +0 −3  script/process/spawner
  76. +6 −0 script/rails
  77. +0 −3  script/runner
  78. +0 −3  script/server
  79. +18 −9 test/fixtures/users.yml
  80. +2 −8 test/functional/sessions_controller_test.rb
  81. +1 −7 test/functional/users_controller_test.rb
  82. +9 −0 test/performance/browsing_test.rb
  83. +3 −28 test/test_helper.rb
  84. +2 −2 test/unit/user_test.rb
  85. BIN  tmp/.DS_Store
  86. 0  log/server.log → vendor/plugins/.gitkeep
  87. +0 −2  vendor/plugins/attachment_fu/.gitignore
  88. +0 −35 vendor/plugins/attachment_fu/CHANGELOG
  89. +0 −186 vendor/plugins/attachment_fu/README
  90. +0 −22 vendor/plugins/attachment_fu/Rakefile
  91. +0 −14 vendor/plugins/attachment_fu/amazon_s3.yml.tpl
  92. +0 −16 vendor/plugins/attachment_fu/init.rb
  93. +0 −5 vendor/plugins/attachment_fu/install.rb
  94. +0 −93 vendor/plugins/attachment_fu/lib/geometry.rb
  95. +0 −473 vendor/plugins/attachment_fu/lib/technoweenie/attachment_fu.rb
  96. +0 −39 vendor/plugins/attachment_fu/lib/technoweenie/attachment_fu/backends/db_file_backend.rb
  97. +0 −101 vendor/plugins/attachment_fu/lib/technoweenie/attachment_fu/backends/file_system_backend.rb
  98. +0 −303 vendor/plugins/attachment_fu/lib/technoweenie/attachment_fu/backends/s3_backend.rb
  99. +0 −59 vendor/plugins/attachment_fu/lib/technoweenie/attachment_fu/processors/core_image_processor.rb
  100. +0 −54 vendor/plugins/attachment_fu/lib/technoweenie/attachment_fu/processors/gd2_processor.rb
  101. +0 −61 vendor/plugins/attachment_fu/lib/technoweenie/attachment_fu/processors/image_science_processor.rb
  102. +0 −59 vendor/plugins/attachment_fu/lib/technoweenie/attachment_fu/processors/mini_magick_processor.rb
  103. +0 −54 vendor/plugins/attachment_fu/lib/technoweenie/attachment_fu/processors/rmagick_processor.rb
  104. +0 −16 vendor/plugins/attachment_fu/test/backends/db_file_test.rb
  105. +0 −80 vendor/plugins/attachment_fu/test/backends/file_system_test.rb
  106. +0 −119 vendor/plugins/attachment_fu/test/backends/remote/s3_test.rb
  107. +0 −77 vendor/plugins/attachment_fu/test/base_attachment_tests.rb
  108. +0 −70 vendor/plugins/attachment_fu/test/basic_test.rb
  109. +0 −18 vendor/plugins/attachment_fu/test/database.yml
  110. +0 −67 vendor/plugins/attachment_fu/test/extra_attachment_test.rb
  111. +0 −148 vendor/plugins/attachment_fu/test/fixtures/attachment.rb
  112. BIN  vendor/plugins/attachment_fu/test/fixtures/files/fake/rails.png
  113. +0 −1  vendor/plugins/attachment_fu/test/fixtures/files/foo.txt
  114. BIN  vendor/plugins/attachment_fu/test/fixtures/files/rails.png
  115. +0 −101 vendor/plugins/attachment_fu/test/geometry_test.rb
  116. +0 −37 vendor/plugins/attachment_fu/test/processors/core_image_test.rb
  117. +0 −31 vendor/plugins/attachment_fu/test/processors/gd2_test.rb
  118. +0 −31 vendor/plugins/attachment_fu/test/processors/image_science_test.rb
  119. +0 −31 vendor/plugins/attachment_fu/test/processors/mini_magick_test.rb
  120. +0 −255 vendor/plugins/attachment_fu/test/processors/rmagick_test.rb
  121. +0 −108 vendor/plugins/attachment_fu/test/schema.rb
  122. +0 −150 vendor/plugins/attachment_fu/test/test_helper.rb
  123. +0 −55 vendor/plugins/attachment_fu/test/validation_test.rb
  124. +0 −27 vendor/plugins/attachment_fu/vendor/red_artisan/core_image/filters/color.rb
  125. +0 −31 vendor/plugins/attachment_fu/vendor/red_artisan/core_image/filters/effects.rb
  126. +0 −25 vendor/plugins/attachment_fu/vendor/red_artisan/core_image/filters/perspective.rb
  127. +0 −25 vendor/plugins/attachment_fu/vendor/red_artisan/core_image/filters/quality.rb
  128. +0 −47 vendor/plugins/attachment_fu/vendor/red_artisan/core_image/filters/scale.rb
  129. +0 −32 vendor/plugins/attachment_fu/vendor/red_artisan/core_image/filters/watermark.rb
  130. +0 −123 vendor/plugins/attachment_fu/vendor/red_artisan/core_image/processor.rb
  131. +20 −0 vendor/plugins/dynamic_form/MIT-LICENSE
  132. +13 −0 vendor/plugins/dynamic_form/README
  133. +10 −0 vendor/plugins/dynamic_form/Rakefile
  134. +5 −0 vendor/plugins/dynamic_form/init.rb
  135. +300 −0 vendor/plugins/dynamic_form/lib/action_view/helpers/dynamic_form.rb
  136. +8 −0 vendor/plugins/dynamic_form/lib/action_view/locale/en.yml
  137. +42 −0 vendor/plugins/dynamic_form/test/dynamic_form_i18n_test.rb
  138. +370 −0 vendor/plugins/dynamic_form/test/dynamic_form_test.rb
  139. +9 −0 vendor/plugins/dynamic_form/test/test_helper.rb
  140. +0 −20 vendor/plugins/restful-authentication/.gitignore
  141. +20 −0 vendor/plugins/restful-authentication/LICENSE
  142. +0 −176 vendor/plugins/restful-authentication/README
  143. +176 −0 vendor/plugins/restful-authentication/README.textile
  144. +10 −0 vendor/plugins/restful-authentication/Rakefile
  145. +0 −1  vendor/plugins/restful-authentication/generators/authenticated/USAGE
  146. +0 −478 vendor/plugins/restful-authentication/generators/authenticated/authenticated_generator.rb
  147. +0 −50 vendor/plugins/restful-authentication/generators/authenticated/lib/insert_routes.rb
  148. +0 −25 vendor/plugins/restful-authentication/generators/authenticated/templates/mailer.rb
  149. +0 −69 vendor/plugins/restful-authentication/generators/authenticated/templates/model.rb
  150. +0 −11 vendor/plugins/restful-authentication/generators/authenticated/templates/observer.rb
  151. +0 −22 vendor/plugins/restful-authentication/generators/authenticated/templates/stories/rest_auth_stories.rb
  152. +0 −49 vendor/plugins/restful-authentication/generators/authenticated/templates/stories/steps/ra_navigation_steps.rb
  153. +0 −179 vendor/plugins/restful-authentication/generators/authenticated/templates/stories/steps/ra_resource_steps.rb
  154. +0 −171 vendor/plugins/restful-authentication/generators/authenticated/templates/stories/steps/ra_response_steps.rb
  155. +0 −153 vendor/plugins/restful-authentication/generators/authenticated/templates/stories/steps/user_steps.rb
  156. +0 −186 vendor/plugins/restful-authentication/generators/authenticated/templates/stories/users/accounts.story
  157. +0 −31 vendor/plugins/restful-authentication/generators/authenticated/templates/test/mailer_test.rb
  158. +3 −3 vendor/plugins/restful-authentication/init.rb
  159. +0 −1  vendor/plugins/restful-authentication/install.rb
  160. +24 −27 vendor/plugins/restful-authentication/lib/authentication.rb
  161. +7 −10 vendor/plugins/restful-authentication/lib/authentication/by_cookie_token.rb
  162. +2 −3 vendor/plugins/restful-authentication/lib/authentication/by_password.rb
  163. +2 −3 vendor/plugins/restful-authentication/lib/authorization.rb
  164. +1 −2  vendor/plugins/restful-authentication/lib/authorization/aasm_roles.rb
  165. +1 −2  vendor/plugins/restful-authentication/lib/authorization/stateful_roles.rb
  166. +1 −0  vendor/plugins/restful-authentication/lib/generators/authenticated/USAGE
  167. +524 −0 vendor/plugins/restful-authentication/lib/generators/authenticated/authenticated_generator.rb
  168. +2 −2 vendor/plugins/restful-authentication/{ → lib}/generators/authenticated/templates/_model_partial.html.erb
  169. +1 −1  ...s/authenticated/templates/activation.html.erb → lib/generators/authenticated/templates/activation.erb}
  170. +9 −7 vendor/plugins/restful-authentication/{ → lib}/generators/authenticated/templates/authenticated_system.rb
  171. +2 −2 ...lugins/restful-authentication/{ → lib}/generators/authenticated/templates/authenticated_test_helper.rb
  172. +3 −5 vendor/plugins/restful-authentication/{ → lib}/generators/authenticated/templates/controller.rb
  173. +109 −0 vendor/plugins/restful-authentication/lib/generators/authenticated/templates/features/accounts.feature
  174. +44 −44 ...lates/stories/users/sessions.story → lib/generators/authenticated/templates/features/sessions.feature}
  175. +9 −0 ...r/plugins/restful-authentication/lib/generators/authenticated/templates/features/step_definitions/ra_env.rb
  176. +48 −0 ...tful-authentication/lib/generators/authenticated/templates/features/step_definitions/ra_navigation_steps.rb
  177. +178 −0 ...estful-authentication/lib/generators/authenticated/templates/features/step_definitions/ra_resource_steps.rb
  178. +169 −0 ...estful-authentication/lib/generators/authenticated/templates/features/step_definitions/ra_response_steps.rb
  179. +6 −6 ...er.rb → lib/generators/authenticated/templates/features/step_definitions/rest_auth_features_helper.rb}
  180. +131 −0 ...ugins/restful-authentication/lib/generators/authenticated/templates/features/step_definitions/user_steps.rb
  181. 0  vendor/plugins/restful-authentication/{ → lib}/generators/authenticated/templates/helper.rb
  182. +4 −4 vendor/plugins/restful-authentication/{ → lib}/generators/authenticated/templates/login.html.erb
  183. +26 −0 vendor/plugins/restful-authentication/lib/generators/authenticated/templates/mailer.rb
  184. +3 −3 vendor/plugins/restful-authentication/{ → lib}/generators/authenticated/templates/migration.rb
  185. +87 −0 vendor/plugins/restful-authentication/lib/generators/authenticated/templates/model.rb
  186. +13 −16 vendor/plugins/restful-authentication/{ → lib}/generators/authenticated/templates/model_controller.rb
  187. 0  vendor/plugins/restful-authentication/{ → lib}/generators/authenticated/templates/model_helper.rb
  188. 0  vendor/plugins/restful-authentication/{ → lib}/generators/authenticated/templates/model_helper_spec.rb
  189. +11 −0 vendor/plugins/restful-authentication/lib/generators/authenticated/templates/observer.rb
  190. +5 −5 vendor/plugins/restful-authentication/{ → lib}/generators/authenticated/templates/signup.html.erb
  191. +1 −1  ...mplates/signup_notification.html.erb → lib/generators/authenticated/templates/signup_notification.erb}
  192. 0  vendor/plugins/restful-authentication/{ → lib}/generators/authenticated/templates/site_keys.rb
  193. 0  ...ful-authentication/{ → lib}/generators/authenticated/templates/spec/controllers/access_control_spec.rb
  194. +1 −0  ...thentication/{ → lib}/generators/authenticated/templates/spec/controllers/authenticated_system_spec.rb
  195. +3 −3 ...uthentication/{ → lib}/generators/authenticated/templates/spec/controllers/sessions_controller_spec.rb
  196. +2 −2 ...l-authentication/{ → lib}/generators/authenticated/templates/spec/controllers/users_controller_spec.rb
  197. 0  vendor/plugins/restful-authentication/{ → lib}/generators/authenticated/templates/spec/fixtures/users.yml
  198. 0  ...s/restful-authentication/{ → lib}/generators/authenticated/templates/spec/helpers/users_helper_spec.rb
  199. +14 −14 ...or/plugins/restful-authentication/{ → lib}/generators/authenticated/templates/spec/models/user_spec.rb
  200. +2 −8 vendor/plugins/restful-authentication/{ → lib}/generators/authenticated/templates/test/functional_test.rb
  201. +32 −0 vendor/plugins/restful-authentication/lib/generators/authenticated/templates/test/mailer_test.rb
  202. +2 −8 ...ugins/restful-authentication/{ → lib}/generators/authenticated/templates/test/model_functional_test.rb
  203. +2 −2 vendor/plugins/restful-authentication/{ → lib}/generators/authenticated/templates/test/unit_test.rb
  204. +33 −0 vendor/plugins/restful-authentication/lib/tasks/auth.rake
  205. +2 −3 vendor/plugins/restful-authentication/lib/trustification.rb
  206. +3 −3 vendor/plugins/restful-authentication/lib/trustification/email_validation.rb
  207. +1 −1  vendor/plugins/restful-authentication/notes/Tradeoffs.txt
  208. +32 −0 vendor/plugins/restful-authentication/restful-authentication.gemspec
View
6 .gitignore
@@ -0,0 +1,6 @@
+.bundle
+.DS_Store
+db/*.sqlite3
+log/*.log
+tmp/**/*
+
View
32 Gemfile
@@ -0,0 +1,32 @@
+source 'http://rubygems.org'
+
+gem 'rails', '3.0.0.rc'
+
+# Bundle edge Rails instead:
+# gem 'rails', :git => 'git://github.com/rails/rails.git'
+
+gem 'sqlite3-ruby', :require => 'sqlite3'
+gem 'paperclip'
+gem 'mime-types', :require => 'mime/types'
+
+# Use unicorn as the web server
+# gem 'unicorn'
+
+# Deploy with Capistrano
+# gem 'capistrano'
+
+# To use debugger
+# gem 'ruby-debug'
+
+# Bundle the extra gems:
+# gem 'bj'
+# gem 'nokogiri', '1.4.1'
+# gem 'sqlite3-ruby', :require => 'sqlite3'
+# gem 'aws-s3', :require => 'aws/s3'
+
+# Bundle gems for the local environment. Make sure to
+# put test-only gems in this group so their generators
+# and rake tasks are available in development mode:
+# group :development, :test do
+# gem 'webrat'
+# end
View
78 Gemfile.lock
@@ -0,0 +1,78 @@
+GEM
+ remote: http://rubygems.org/
+ specs:
+ abstract (1.0.0)
+ actionmailer (3.0.0.rc)
+ actionpack (= 3.0.0.rc)
+ mail (~> 2.2.5)
+ actionpack (3.0.0.rc)
+ activemodel (= 3.0.0.rc)
+ activesupport (= 3.0.0.rc)
+ builder (~> 2.1.2)
+ erubis (~> 2.6.6)
+ i18n (~> 0.4.1)
+ rack (~> 1.2.1)
+ rack-mount (~> 0.6.9)
+ rack-test (~> 0.5.4)
+ tzinfo (~> 0.3.22)
+ activemodel (3.0.0.rc)
+ activesupport (= 3.0.0.rc)
+ builder (~> 2.1.2)
+ i18n (~> 0.4.1)
+ activerecord (3.0.0.rc)
+ activemodel (= 3.0.0.rc)
+ activesupport (= 3.0.0.rc)
+ arel (~> 0.4.0)
+ tzinfo (~> 0.3.22)
+ activeresource (3.0.0.rc)
+ activemodel (= 3.0.0.rc)
+ activesupport (= 3.0.0.rc)
+ activesupport (3.0.0.rc)
+ arel (0.4.0)
+ activesupport (>= 3.0.0.beta)
+ builder (2.1.2)
+ erubis (2.6.6)
+ abstract (>= 1.0.0)
+ i18n (0.4.1)
+ mail (2.2.5)
+ activesupport (>= 2.3.6)
+ mime-types
+ treetop (>= 1.4.5)
+ mime-types (1.16)
+ paperclip (2.3.3)
+ activerecord
+ activesupport
+ polyglot (0.3.1)
+ rack (1.2.1)
+ rack-mount (0.6.9)
+ rack (>= 1.0.0)
+ rack-test (0.5.4)
+ rack (>= 1.0)
+ rails (3.0.0.rc)
+ actionmailer (= 3.0.0.rc)
+ actionpack (= 3.0.0.rc)
+ activerecord (= 3.0.0.rc)
+ activeresource (= 3.0.0.rc)
+ activesupport (= 3.0.0.rc)
+ bundler (>= 1.0.0.rc.1)
+ railties (= 3.0.0.rc)
+ railties (3.0.0.rc)
+ actionpack (= 3.0.0.rc)
+ activesupport (= 3.0.0.rc)
+ rake (>= 0.8.3)
+ thor (~> 0.14.0)
+ rake (0.8.7)
+ sqlite3-ruby (1.3.1)
+ thor (0.14.0)
+ treetop (1.4.8)
+ polyglot (>= 0.3.1)
+ tzinfo (0.3.22)
+
+PLATFORMS
+ ruby
+
+DEPENDENCIES
+ mime-types
+ paperclip
+ rails (= 3.0.0.rc)
+ sqlite3-ruby
View
39 README
@@ -1,39 +0,0 @@
-swfupload-rails-authentication
-==============================
-
-Demo Rails 2.1.2 app showing SWFUpload working in tandem with restful-authentication, CSRF protection and attachment_fu.
-
-The demo has been updated to use SWFUpload v2.2.0 Beta 2, which supports Flash Player 10.
-
-Requirements
-============
-
-Rails 2.1
-ImageMagick
-mini_magick gem
-mime-types gem
-
-
-Usage
-=====
-
-rake db:schema:load
-rake db:fixtures:load
-script/server
-
-
-Login
-=====
-
-The restful authentication test user;
-
-username: quentin
-password: monkey
-
-
-References
-==========
-
-http://seventytwo.co.uk/posts/making-swfupload-and-rails-work-together
-http://blog.airbladesoftware.com/2007/8/8/uploading-files-with-swfupload
-http://blog.inquirylabs.com/2006/12/09/getting-the-_session_id-from-swfupload/
View
22 README.md
@@ -0,0 +1,22 @@
+# swfupload-rails-authentication
+
+Demo Rails 3.0.0.rc app showing SWFUpload working in tandem with restful-authentication, CSRF protection and paperclip.
+
+[![Still Maintained](http://stillmaintained.com/lardawge/swfupload-rails-authentication.png)](http://stillmaintained.com/lardawge/swfupload-rails-authentication)
+
+As you can see by the above badge, I am not keeping this updated. Please fork and update if are so inclined.
+
+## Usage
+
+```bash
+gem install bundler --pre
+bundle install
+rake db:migrate
+rake db:seed
+rails s
+```
+
+## Login Credentials
+
+username: quentin<br>
+password: monkey
View
7 Rakefile
@@ -1,10 +1,7 @@
# Add your own tasks in files placed in lib/tasks ending in .rake,
# for example lib/tasks/capistrano.rake, and they will automatically be available to Rake.
-require(File.join(File.dirname(__FILE__), 'config', 'boot'))
-
+require File.expand_path('../config/application', __FILE__)
require 'rake'
-require 'rake/testtask'
-require 'rake/rdoctask'
-require 'tasks/rails'
+SwfuploadRailsAuthentication::Application.load_tasks
View
19 app/controllers/application.rb
@@ -1,19 +0,0 @@
-# Filters added to this controller apply to all controllers in the application.
-# Likewise, all the methods added will be available for all controllers.
-
-class ApplicationController < ActionController::Base
-
- include AuthenticatedSystem
-
- helper :all # include all helpers, all the time
-
- # See ActionController::RequestForgeryProtection for details
- # Uncomment the :secret if you're not using the cookie session store
- protect_from_forgery #:secret => 'd307747927b72d71553b39b15089e7da'
-
- # See ActionController::Base for details
- # Uncomment this to filter the contents of submitted sensitive data parameters
- # from your application log (in this case, all fields with names like "password").
- # filter_parameter_logging :password
-
-end
View
5 app/controllers/application_controller.rb
@@ -0,0 +1,5 @@
+require 'lib/authenticated_system'
+class ApplicationController < ActionController::Base
+ include AuthenticatedSystem
+ protect_from_forgery
+end
View
8 app/controllers/assets_controller.rb
@@ -1,15 +1,11 @@
class AssetsController < ApplicationController
-
- layout 'layout'
-
- session :cookie_only => false, :only => :create
before_filter :login_required
# GET /assets
# GET /assets.xml
def index
- @assets = Asset.masters
+ @assets = current_user.assets
respond_to do |format|
format.html # index.html.erb
@@ -55,7 +51,7 @@ def create
@asset.user = current_user
@asset.save!
- format.html { render :text => @asset.public_filename(:thumb) }
+ format.html { render :text => @asset.image.url(:thumb) }
format.xml { render :nothing => true }
else
if @asset.save
View
8 app/controllers/sessions_controller.rb
@@ -18,8 +18,7 @@ def create
self.current_user = user
new_cookie_flag = (params[:remember_me] == "1")
handle_remember_cookie! new_cookie_flag
- redirect_back_or_default('/')
- flash[:notice] = "Logged in successfully"
+ redirect_back_or_default('/', :notice => "Logged in successfully")
else
note_failed_signin
@login = params[:login]
@@ -30,14 +29,13 @@ def create
def destroy
logout_killing_session!
- flash[:notice] = "You have been logged out."
- redirect_back_or_default('/')
+ redirect_back_or_default('/', :notice => "You have been logged out.")
end
protected
# Track failed login attempts
def note_failed_signin
- flash[:error] = "Couldn't log you in as '#{params[:login]}'"
+ flash.now[:error] = "Couldn't log you in as '#{params[:login]}'"
logger.warn "Failed login for '#{params[:login]}' from #{request.remote_ip} at #{Time.now.utc}"
end
end
View
1  app/helpers/application_helper.rb
@@ -1,3 +1,2 @@
-# Methods added to this helper will be available to all templates in the application.
module ApplicationHelper
end
View
4 app/helpers/assets_helper.rb
@@ -1,2 +1,6 @@
module AssetsHelper
+ def new_asset_path_with_session_information
+ session_key = Rails.application.config.session_options[:key]
+ assets_path(session_key => cookies[session_key], request_forgery_protection_token => form_authenticity_token)
+ end
end
View
36 app/middleware/flash_session_cookie_middleware.rb
@@ -0,0 +1,36 @@
+require 'rack/utils'
+
+class FlashSessionCookieMiddleware
+ def initialize(app, session_key = '_session_id')
+ @app = app
+ @session_key = session_key
+ end
+
+ def call(env)
+ if env['HTTP_USER_AGENT'] =~ /^(Adobe|Shockwave) Flash/
+ req = Rack::Request.new(env)
+ params = ::Rack::Utils.parse_query(env['QUERY_STRING'])
+ env['HTTP_COOKIE'] = [ @session_key, params[@session_key] ].join('=').freeze unless params[@session_key].nil?
+ end
+ @app.call(env)
+ end
+end
+
+require 'rack/utils'
+
+#class FlashSessionCookieMiddleware
+# def initialize(app, session_key = '_session_id')
+# @app = app
+# @session_key = session_key
+# end
+#
+# def call(env)
+# if env['HTTP_USER_AGENT'] =~ /^(Adobe|Shockwave) Flash/
+# req = Rack::Request.new(env)
+# env['HTTP_COOKIE'] = [ @session_key, ::Rack::Utils.escape(req.params[@session_key]) ].join('=').freeze unless req.params[@session_key].nil?
+# env['HTTP_ACCEPT'] = "#{req.params['_http_accept']}".freeze unless req.params['_http_accept'].nil?
+# end
+#
+# @app.call(env)
+# end
+#end
View
29 app/models/asset.rb
@@ -1,29 +1,28 @@
-require 'mime/types'
-
class Asset < ActiveRecord::Base
-
- # Relationships
+
belongs_to :user
+
+ has_attached_file :image,
+ :styles => {:thumb => "150x150#"},
+ :whiny_thumbnails => true,
+ :url => "/asset_images/:style/:basename.:extension",
+ :path => ":rails_root/public/asset_images/:style/:basename.:extension"
- has_attachment :storage => :file_system,
- :max_size => 5.megabytes,
- :resize_to => '800x600>',
- :thumbnails => { :thumb => '150x150>' },
- :processor => :MiniMagick
-
-
# Validations
- validates_as_attachment
+ validates_attachment_content_type :image,
+ :content_type => ['image/jpeg', 'image/pjpeg', 'image/jpg', 'image/tiff', 'image/tif'],
+ :message => 'Picture must be a jpeg, tif or pdf file type'
+ validates_attachment_size :image, :in => 1..26.megabyte
- #
- named_scope :masters, :conditions => {:parent_id => nil}
+ attr_protected :image_file_name, :image_content_type, :image_size
+
# Map file extensions to mime types.
# Thanks to bug in Flash 8 the content type is always set to application/octet-stream.
# From: http://blog.airbladesoftware.com/2007/8/8/uploading-files-with-swfupload
def swf_uploaded_data=(data)
data.content_type = MIME::Types.type_for(data.original_filename)
- self.uploaded_data = data
+ self.image = data
end
end
View
34 app/models/user.rb
@@ -5,18 +5,21 @@ class User < ActiveRecord::Base
include Authentication::ByPassword
include Authentication::ByCookieToken
- validates_presence_of :login
- validates_length_of :login, :within => 3..40
- validates_uniqueness_of :login, :case_sensitive => false
- validates_format_of :login, :with => RE_LOGIN_OK, :message => MSG_LOGIN_BAD
+ has_many :assets, :dependent => :destroy
- validates_format_of :name, :with => RE_NAME_OK, :message => MSG_NAME_BAD, :allow_nil => true
- validates_length_of :name, :maximum => 100
+ validates :login, :presence => true,
+ :uniqueness => true,
+ :length => { :within => 3..40 },
+ :format => { :with => Authentication.login_regex, :message => Authentication.bad_login_message }
- validates_presence_of :email
- validates_length_of :email, :within => 6..100 #r@a.wk
- validates_uniqueness_of :email, :case_sensitive => false
- validates_format_of :email, :with => RE_EMAIL_OK, :message => MSG_EMAIL_BAD
+ validates :name, :format => { :with => Authentication.name_regex, :message => Authentication.bad_name_message },
+ :length => { :maximum => 100 },
+ :allow_nil => true
+
+ validates :email, :presence => true,
+ :uniqueness => true,
+ :format => { :with => Authentication.email_regex, :message => Authentication.bad_email_message },
+ :length => { :within => 6..100 }
@@ -34,10 +37,19 @@ class User < ActiveRecord::Base
# This will also let us return a human error message.
#
def self.authenticate(login, password)
- u = find_by_login(login) # need to get the salt
+ return nil if login.blank? || password.blank?
+ u = find_by_login(login.downcase) # need to get the salt
u && u.authenticated?(password) ? u : nil
end
+ def login=(value)
+ write_attribute :login, (value ? value.downcase : nil)
+ end
+
+ def email=(value)
+ write_attribute :email, (value ? value.downcase : nil)
+ end
+
protected
View
1  app/views/assets/edit.html.erb
@@ -1 +0,0 @@
-<h1>Edit</h1>
View
8 app/views/assets/index.html.erb
@@ -12,10 +12,10 @@
<% unless @assets.blank? %>
<% @assets.each do |asset| -%>
<tr>
- <td><%= link_to image_tag(asset.public_filename(:thumb)), asset %></td>
- <td><%= number_to_human_size(asset.size) %></td>
- <td><%= h asset.content_type %></td>
- <td><%= h asset.user.login %></td>
+ <td><%= link_to image_tag(asset.image.url(:thumb)), asset %></td>
+ <td><%= number_to_human_size(asset.image.size) %></td>
+ <td><%= asset.image.content_type %></td>
+ <td><%= asset.user.login %></td>
<td><%= asset.updated_at.to_s(:full) %></td>
</tr>
<% end -%>
View
2  app/views/assets/new.html.erb
@@ -5,7 +5,7 @@
window.onload = function () {
swfu = new SWFUpload({
- upload_url : '<%= assets_path -%>?_swfupload_demo_session=<%= u session.session_id %>',
+ upload_url : '<%= new_asset_path_with_session_information %>',
flash_url : '/flash/swfupload.swf',
// Button settings
View
4 app/views/assets/show.html.erb
@@ -1,5 +1,3 @@
-<%= image_tag(@asset.public_filename) %>
-
-<%= debug @asset %>
+<%= image_tag(@asset.image.url) %>
<%= link_to 'back', assets_path %>
View
6 app/views/layouts/layout.html.erb → app/views/layouts/application.html.erb
@@ -1,4 +1,4 @@
-<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
+<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en-GB">
<head>
@@ -6,9 +6,9 @@
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<title>SWFUpload Test</title>
-
<%= stylesheet_link_tag 'screen', 'swfupload', :media => 'screen' %>
<%= javascript_include_tag 'swfupload', 'swfupload_handlers' %>
+ <%= csrf_meta_tag %>
</head>
@@ -17,4 +17,4 @@
<%= yield %>
</div>
</body>
-</html>
View
9 app/views/sessions/new.html.erb
@@ -1,14 +1,13 @@
<h1>Log In</h1>
-
-<% form_tag session_path do -%>
-<p><label for="login">Login</label><br/>
+<%= form_tag session_path do -%>
+<p><%= label_tag 'login' %><br />
<%= text_field_tag 'login', @login %></p>
-<p><label for="password">Password</label><br/>
+<p><%= label_tag 'password' %><br/>
<%= password_field_tag 'password', nil %></p>
<!-- Uncomment this if you want this functionality
-<p><label for="remember_me">Remember me:</label>
+<p><%= label_tag 'remember_me', 'Remember me' %>
<%= check_box_tag 'remember_me', '1', @remember_me %></p>
-->
View
4 config.ru
@@ -0,0 +1,4 @@
+# This file is used by Rack-based servers to start the application.
+
+require ::File.expand_path('../config/environment', __FILE__)
+run SwfuploadRailsAuthentication::Application
View
43 config/application.rb
@@ -0,0 +1,43 @@
+require File.expand_path('../boot', __FILE__)
+
+require 'rails/all'
+
+# If you have a Gemfile, require the gems listed there, including any gems
+# you've limited to :test, :development, or :production.
+Bundler.require(:default, Rails.env) if defined?(Bundler)
+
+module SwfuploadRailsAuthentication
+ class Application < Rails::Application
+ # Settings in config/environments/* take precedence over those specified here.
+ # Application configuration should go into files in config/initializers
+ # -- all .rb files in that directory are automatically loaded.
+ #raise Rails.application.config.session_options[:key].inspect
+
+ # Custom directories with classes and modules you want to be autoloadable.
+ # config.autoload_paths += %W(#{config.root}/extras)
+
+ # Only load the plugins named here, in the order given (default is alphabetical).
+ # :all can be used as a placeholder for all plugins not explicitly named.
+ # config.plugins = [ :exception_notification, :ssl_requirement, :all ]
+
+ # Activate observers that should always be running.
+ # config.active_record.observers = :cacher, :garbage_collector, :forum_observer
+
+ # Set Time.zone default to the specified zone and make Active Record auto-convert to this zone.
+ # Run "rake -D time" for a list of tasks for finding time zone names. Default is UTC.
+ # config.time_zone = 'Central Time (US & Canada)'
+
+ # The default locale is :en and all translations from config/locales/*.rb,yml are auto loaded.
+ # config.i18n.load_path += Dir[Rails.root.join('my', 'locales', '*.{rb,yml}').to_s]
+ # config.i18n.default_locale = :de
+
+ # JavaScript files you want as :defaults (application.js is always included).
+ # config.action_view.javascript_expansions[:defaults] = %w(jquery rails)
+
+ # Configure the default encoding used in templates for Ruby 1.9.
+ config.encoding = "utf-8"
+
+ # Configure sensitive parameters which will be filtered from the log file.
+ config.filter_parameters += [:password]
+ end
+end
View
122 config/boot.rb
@@ -1,109 +1,13 @@
-# Don't change this file!
-# Configure your app in config/environment.rb and config/environments/*.rb
-
-RAILS_ROOT = "#{File.dirname(__FILE__)}/.." unless defined?(RAILS_ROOT)
-
-module Rails
- class << self
- def boot!
- unless booted?
- preinitialize
- pick_boot.run
- end
- end
-
- def booted?
- defined? Rails::Initializer
- end
-
- def pick_boot
- (vendor_rails? ? VendorBoot : GemBoot).new
- end
-
- def vendor_rails?
- File.exist?("#{RAILS_ROOT}/vendor/rails")
- end
-
- def preinitialize
- load(preinitializer_path) if File.exist?(preinitializer_path)
- end
-
- def preinitializer_path
- "#{RAILS_ROOT}/config/preinitializer.rb"
- end
- end
-
- class Boot
- def run
- load_initializer
- Rails::Initializer.run(:set_load_path)
- end
- end
-
- class VendorBoot < Boot
- def load_initializer
- require "#{RAILS_ROOT}/vendor/rails/railties/lib/initializer"
- Rails::Initializer.run(:install_gem_spec_stubs)
- end
- end
-
- class GemBoot < Boot
- def load_initializer
- self.class.load_rubygems
- load_rails_gem
- require 'initializer'
- end
-
- def load_rails_gem
- if version = self.class.gem_version
- gem 'rails', version
- else
- gem 'rails'
- end
- rescue Gem::LoadError => load_error
- $stderr.puts %(Missing the Rails #{version} gem. Please `gem install -v=#{version} rails`, update your RAILS_GEM_VERSION setting in config/environment.rb for the Rails version you do have installed, or comment out RAILS_GEM_VERSION to use the latest version installed.)
- exit 1
- end
-
- class << self
- def rubygems_version
- Gem::RubyGemsVersion if defined? Gem::RubyGemsVersion
- end
-
- def gem_version
- if defined? RAILS_GEM_VERSION
- RAILS_GEM_VERSION
- elsif ENV.include?('RAILS_GEM_VERSION')
- ENV['RAILS_GEM_VERSION']
- else
- parse_gem_version(read_environment_rb)
- end
- end
-
- def load_rubygems
- require 'rubygems'
-
- unless rubygems_version >= '0.9.4'
- $stderr.puts %(Rails requires RubyGems >= 0.9.4 (you have #{rubygems_version}). Please `gem update --system` and try again.)
- exit 1
- end
-
- rescue LoadError
- $stderr.puts %(Rails requires RubyGems >= 0.9.4. Please install RubyGems and try again: http://rubygems.rubyforge.org)
- exit 1
- end
-
- def parse_gem_version(text)
- $1 if text =~ /^[^#]*RAILS_GEM_VERSION\s*=\s*["']([!~<>=]*\s*[\d.]+)["']/
- end
-
- private
- def read_environment_rb
- File.read("#{RAILS_ROOT}/config/environment.rb")
- end
- end
- end
-end
-
-# All that for this:
-Rails.boot!
+require 'rubygems'
+
+# Set up gems listed in the Gemfile.
+gemfile = File.expand_path('../../Gemfile', __FILE__)
+begin
+ ENV['BUNDLE_GEMFILE'] = gemfile
+ require 'bundler'
+ Bundler.setup
+rescue Bundler::GemNotFound => e
+ STDERR.puts e.message
+ STDERR.puts "Try running `bundle install`."
+ exit!
+end if File.exist?(gemfile)
View
3  config/database.yml
@@ -3,6 +3,7 @@
development:
adapter: sqlite3
database: db/development.sqlite3
+ pool: 5
timeout: 5000
# Warning: The database defined as "test" will be erased and
@@ -11,9 +12,11 @@ development:
test:
adapter: sqlite3
database: db/test.sqlite3
+ pool: 5
timeout: 5000
production:
adapter: sqlite3
database: db/production.sqlite3
+ pool: 5
timeout: 5000
View
73 config/environment.rb
@@ -1,70 +1,5 @@
-# Be sure to restart your server when you modify this file
+# Load the rails application
+require File.expand_path('../application', __FILE__)
-# Uncomment below to force Rails into production mode when
-# you don't control web/app server and can't set it the proper way
-# ENV['RAILS_ENV'] ||= 'production'
-
-# Specifies gem version of Rails to use when vendor/rails is not present
-RAILS_GEM_VERSION = '2.1.2' unless defined? RAILS_GEM_VERSION
-
-# Bootstrap the Rails environment, frameworks, and default configuration
-require File.join(File.dirname(__FILE__), 'boot')
-
-Rails::Initializer.run do |config|
- # Settings in config/environments/* take precedence over those specified here.
- # Application configuration should go into files in config/initializers
- # -- all .rb files in that directory are automatically loaded.
- # See Rails::Configuration for more options.
-
- # Skip frameworks you're not going to use. To use Rails without a database
- # you must remove the Active Record framework.
- # config.frameworks -= [ :active_record, :active_resource, :action_mailer ]
-
- # Specify gems that this application depends on.
- # They can then be installed with "rake gems:install" on new installations.
- # config.gem "bj"
- # config.gem "hpricot", :version => '0.6', :source => "http://code.whytheluckystiff.net"
- # config.gem "aws-s3", :lib => "aws/s3"
-
- config.gem 'mini_magick'
- config.gem 'mime-types', :lib => 'mime/types'
-
- # Only load the plugins named here, in the order given. By default, all plugins
- # in vendor/plugins are loaded in alphabetical order.
- # :all can be used as a placeholder for all plugins not explicitly named
- # config.plugins = [ :exception_notification, :ssl_requirement, :all ]
-
- # Add additional load paths for your own custom dirs
- # config.load_paths += %W( #{RAILS_ROOT}/extras )
-
- # Force all environments to use the same logger level
- # (by default production uses :info, the others :debug)
- # config.log_level = :debug
-
- # Make Time.zone default to the specified zone, and make Active Record store time values
- # in the database in UTC, and return them converted to the specified local zone.
- # Run "rake -D time" for a list of tasks for finding time zone names. Uncomment to use default local time.
- config.time_zone = 'UTC'
-
- # Your secret key for verifying cookie session data integrity.
- # If you change this key, all old sessions will become invalid!
- # Make sure the secret is at least 30 characters and all random,
- # no regular words or you'll be exposed to dictionary attacks.
- config.action_controller.session = {
- :session_key => '_swfupload_demo_session',
- :secret => '1a72951ead92ea6e739efa07a4fcb2ca5a752f2e1143609d11a2d217eaa8cfa827d5f1c97af1470797db9fb417d0c6af0fe2b486f5c2760a5e258a8793c89294'
- }
-
- # Use the database for sessions instead of the cookie-based default,
- # which shouldn't be used to store highly confidential information
- # (create the session table with "rake db:sessions:create")
- # config.action_controller.session_store = :active_record_store
-
- # Use SQL instead of Active Record's schema dumper when creating the test database.
- # This is necessary if your schema can't be completely dumped by the schema dumper,
- # like if you have constraints or database-specific column types
- # config.active_record.schema_format = :sql
-
- # Activate observers that should always be running
- # config.active_record.observers = :cacher, :garbage_collector
-end
+# Initialize the rails application
+SwfuploadRailsAuthentication::Application.initialize!
View
31 config/environments/development.rb
@@ -1,17 +1,22 @@
-# Settings specified here will take precedence over those in config/environment.rb
+SwfuploadRailsAuthentication::Application.configure do
+ # Settings specified here will take precedence over those in config/environment.rb
-# In the development environment your application's code is reloaded on
-# every request. This slows down response time but is perfect for development
-# since you don't have to restart the webserver when you make code changes.
-config.cache_classes = false
+ # In the development environment your application's code is reloaded on
+ # every request. This slows down response time but is perfect for development
+ # since you don't have to restart the webserver when you make code changes.
+ config.cache_classes = false
-# Log error messages when you accidentally call methods on nil.
-config.whiny_nils = true
+ # Log error messages when you accidentally call methods on nil.
+ config.whiny_nils = true
-# Show full error reports and disable caching
-config.action_controller.consider_all_requests_local = true
-config.action_view.debug_rjs = true
-config.action_controller.perform_caching = false
+ # Show full error reports and disable caching
+ config.consider_all_requests_local = true
+ config.action_view.debug_rjs = true
+ config.action_controller.perform_caching = false
-# Don't care if the mailer can't send
-config.action_mailer.raise_delivery_errors = false
+ config.action_mailer.raise_delivery_errors = false
+
+ # Print deprecation notices to the Rails logger
+ config.active_support.deprecation = :log
+end
View
59 config/environments/production.rb
@@ -1,22 +1,49 @@
-# Settings specified here will take precedence over those in config/environment.rb
+SwfuploadRailsAuthentication::Application.configure do
+ # Settings specified here will take precedence over those in config/environment.rb
-# The production environment is meant for finished, "live" apps.
-# Code is not reloaded between requests
-config.cache_classes = true
+ # The production environment is meant for finished, "live" apps.
+ # Code is not reloaded between requests
+ config.cache_classes = true
-# Use a different logger for distributed setups
-# config.logger = SyslogLogger.new
+ # Full error reports are disabled and caching is turned on
+ config.consider_all_requests_local = false
+ config.action_controller.perform_caching = true
-# Full error reports are disabled and caching is turned on
-config.action_controller.consider_all_requests_local = false
-config.action_controller.perform_caching = true
-config.action_view.cache_template_loading = true
+ # Specifies the header that your server uses for sending files
+ config.action_dispatch.x_sendfile_header = "X-Sendfile"
-# Use a different cache store in production
-# config.cache_store = :mem_cache_store
+ # For nginx:
+ # config.action_dispatch.x_sendfile_header = 'X-Accel-Redirect'
-# Enable serving of images, stylesheets, and javascripts from an asset server
-# config.action_controller.asset_host = "http://assets.example.com"
+ # If you have no front-end server that supports something like X-Sendfile,
+ # just comment this out and Rails will serve the files
-# Disable delivery errors, bad email addresses will be ignored
-# config.action_mailer.raise_delivery_errors = false
+ # See everything in the log (default is :info)
+ # config.log_level = :debug
+
+ # Use a different logger for distributed setups
+ # config.logger = SyslogLogger.new
+
+ # Use a different cache store in production
+ # config.cache_store = :mem_cache_store
+
+ # Disable Rails's static asset server
+ # In production, Apache or nginx will already do this
+ config.serve_static_assets = false
+
+ # Enable serving of images, stylesheets, and javascripts from an asset server
+ # config.action_controller.asset_host = "http://assets.example.com"
+
+ # Disable delivery errors, bad email addresses will be ignored
+ # config.action_mailer.raise_delivery_errors = false
+
+ # Enable threaded mode
+ # config.threadsafe!
+
+ # Enable locale fallbacks for I18n (makes lookups for any locale fall back to
+ # the I18n.default_locale when a translation can not be found)
+ config.i18n.fallbacks = true
+
+ # Send deprecation notices to registered listeners
+ config.active_support.deprecation = :notify
+end
View
47 config/environments/test.rb
@@ -1,22 +1,35 @@
-# Settings specified here will take precedence over those in config/environment.rb
+SwfuploadRailsAuthentication::Application.configure do
+ # Settings specified here will take precedence over those in config/environment.rb
-# The test environment is used exclusively to run your application's
-# test suite. You never need to work with it otherwise. Remember that
-# your test database is "scratch space" for the test suite and is wiped
-# and recreated between test runs. Don't rely on the data there!
-config.cache_classes = true
+ # The test environment is used exclusively to run your application's
+ # test suite. You never need to work with it otherwise. Remember that
+ # your test database is "scratch space" for the test suite and is wiped
+ # and recreated between test runs. Don't rely on the data there!
+ config.cache_classes = true
-# Log error messages when you accidentally call methods on nil.
-config.whiny_nils = true
+ # Log error messages when you accidentally call methods on nil.
+ config.whiny_nils = true
-# Show full error reports and disable caching
-config.action_controller.consider_all_requests_local = true
-config.action_controller.perform_caching = false
+ # Show full error reports and disable caching
+ config.consider_all_requests_local = true
+ config.action_controller.perform_caching = false
-# Disable request forgery protection in test environment
-config.action_controller.allow_forgery_protection = false
+ # Raise exceptions instead of rendering exception templates
+ config.action_dispatch.show_exceptions = false
-# Tell Action Mailer not to deliver emails to the real world.
-# The :test delivery method accumulates sent emails in the
-# ActionMailer::Base.deliveries array.
-config.action_mailer.delivery_method = :test
+ # Disable request forgery protection in test environment
+ config.action_controller.allow_forgery_protection = false
+
+ # Tell Action Mailer not to deliver emails to the real world.
+ # The :test delivery method accumulates sent emails in the
+ # ActionMailer::Base.deliveries array.
+ config.action_mailer.delivery_method = :test
+
+ # Use SQL instead of Active Record's schema dumper when creating the test database.
+ # This is necessary if your schema can't be completely dumped by the schema dumper,
+ # like if you have constraints or database-specific column types
+ # config.active_record.schema_format = :sql
+
+ # Print deprecation notices to the stderr
+ config.active_support.deprecation = :stderr
+end
View
7 config/initializers/backtrace_silencers.rb
@@ -0,0 +1,7 @@
+# Be sure to restart your server when you modify this file.
+
+# You can add backtrace silencers for libraries that you're using but don't wish to see in your backtraces.
+# Rails.backtrace_cleaner.add_silencer { |line| line =~ /my_noisy_library/ }
+
+# You can also remove all the silencers if you're trying to debug a problem that might stem from framework code.
+# Rails.backtrace_cleaner.remove_silencers!
View
4 config/initializers/inflections.rb
@@ -1,8 +1,8 @@
# Be sure to restart your server when you modify this file.
-# Add new inflection rules using the following format
+# Add new inflection rules using the following format
# (all these examples are active by default):
-# Inflector.inflections do |inflect|
+# ActiveSupport::Inflector.inflections do |inflect|
# inflect.plural /^(ox)$/i, '\1en'
# inflect.singular /^(ox)en/i, '\1'
# inflect.irregular 'person', 'people'
View
15 config/initializers/new_rails_defaults.rb
@@ -1,15 +0,0 @@
-# These settings change the behavior of Rails 2 apps and will be defaults
-# for Rails 3. You can remove this initializer when Rails 3 is released.
-
-# Include Active Record class name as root for JSON serialized output.
-ActiveRecord::Base.include_root_in_json = true
-
-# Store the full class name (including module namespace) in STI type column.
-ActiveRecord::Base.store_full_sti_class = true
-
-# Use ISO 8601 format for JSON serialized times and dates.
-ActiveSupport.use_standard_json_time_format = true
-
-# Don't escape HTML entities in JSON, leave that for the #json_escape helper.
-# if you're including raw json in an HTML page.
-ActiveSupport.escape_html_entities_in_json = false
View
7 config/initializers/secret_token.rb
@@ -0,0 +1,7 @@
+# Be sure to restart your server when you modify this file.
+
+# Your secret key for verifying the integrity of signed cookies.
+# If you change this key, all old signed cookies will become invalid!
+# Make sure the secret is at least 30 characters and all random,
+# no regular words or you'll be exposed to dictionary attacks.
+SwfuploadRailsAuthentication::Application.config.secret_token = '7774c0c0f9a622a048efdfcfc5a96ae33285e47a8e32c8d7b00888284854d31b5fbe8afa031d64878afb6086bdc35d5a64ef7ad948a139ed87e93469942d8957'
View
8 config/initializers/session_store.rb
@@ -0,0 +1,8 @@
+# Be sure to restart your server when you modify this file.
+
+SwfuploadRailsAuthentication::Application.config.session_store :cookie_store, :key => '_swfupload_authentication_session'
+
+# Use the database for sessions instead of the cookie-based default,
+# which shouldn't be used to store highly confidential information
+# (create the session table with "rake db:sessions:create")
+# SwfuploadRailsAuthentication::Application.config.session_store :active_record_store
View
3  config/initializers/swfupload_middleware_loader.rb
@@ -0,0 +1,3 @@
+if defined?(::Rails.configuration) && ::Rails.configuration.respond_to?(:middleware)
+ ::Rails.configuration.middleware.insert_after 'ActionDispatch::Cookies', FlashSessionCookieMiddleware, ::Rails.configuration.session_options[:key]
+end
View
30 config/initializers/swfupload_session_hack.rb
@@ -1,30 +0,0 @@
-# hacks for swfupload + cookie store to work
-# see http://blog.airbladesoftware.com/2007/8/8/uploading-files-with-swfupload
-
-class CGI::Session
- alias original_initialize initialize
- def initialize(request, option = {})
- session_key = option['session_key'] || '_session_id'
- query_string = if (qs = request.env_table["QUERY_STRING"]) and qs != ""
- qs
- elsif (ru = request.env_table["REQUEST_URI"][0..-1]).include?("?")
- ru[(ru.index("?") + 1)..-1]
- end
- if query_string and query_string.include?(session_key)
- option['session_data'] = CGI.unescape(query_string.scan(/#{session_key}=(.*?)(&.*?)*$/).flatten.first)
- end
- original_initialize(request, option)
- end
-end
-
-class CGI::Session::CookieStore
- alias original_initialize initialize
- def initialize(session, options = {})
- @session_data = options['session_data']
- original_initialize(session, options)
- end
-
- def read_cookie
- @session_data || @session.cgi.cookies[@cookie_options['name']].first
- end
-end
View
5 config/locales/en.yml
@@ -0,0 +1,5 @@
+# Sample localization file for English. Add more files in this directory for other locales.
+# See http://github.com/svenfuchs/rails-i18n/tree/master/rails%2Flocale for starting points.
+
+en:
+ hello: "Hello world"
View
73 config/routes.rb
@@ -1,48 +1,67 @@
-ActionController::Routing::Routes.draw do |map|
- # The priority is based upon order of creation: first created -> highest priority.
+SwfuploadRailsAuthentication::Application.routes.draw do
+ resource :session, :only => [:new, :create, :destroy]
+ resources :assets
+
+ match 'signup' => 'users#new', :as => :signup
+ match 'register' => 'users#create', :as => :register
+ match 'login' => 'sessions#new', :as => :login
+ match 'logout' => 'sessions#destroy', :as => :logout
+ match '/activate/:activation_code' => 'users#activate', :as => :activate, :activation_code => nil
+
+ # The priority is based upon order of creation:
+ # first created -> highest priority.
# Sample of regular route:
- # map.connect 'products/:id', :controller => 'catalog', :action => 'view'
+ # match 'products/:id' => 'catalog#view'
# Keep in mind you can assign values other than :controller and :action
# Sample of named route:
- # map.purchase 'products/:id/purchase', :controller => 'catalog', :action => 'purchase'
+ # match 'products/:id/purchase' => 'catalog#purchase', :as => :purchase
# This route can be invoked with purchase_url(:id => product.id)
# Sample resource route (maps HTTP verbs to controller actions automatically):
- # map.resources :products
+ # resources :products
# Sample resource route with options:
- # map.resources :products, :member => { :short => :get, :toggle => :post }, :collection => { :sold => :get }
+ # resources :products do
+ # member do
+ # get :short
+ # post :toggle
+ # end
+ #
+ # collection do
+ # get :sold
+ # end
+ # end
# Sample resource route with sub-resources:
- # map.resources :products, :has_many => [ :comments, :sales ], :has_one => :seller
-
+ # resources :products do
+ # resources :comments, :sales
+ # resource :seller
+ # end
+
# Sample resource route with more complex sub-resources
- # map.resources :products do |products|
- # products.resources :comments
- # products.resources :sales, :collection => { :recent => :get }
+ # resources :products do
+ # resources :comments
+ # resources :sales do
+ # get :recent, :on => :collection
+ # end
# end
# Sample resource route within a namespace:
- # map.namespace :admin do |admin|
- # # Directs /admin/products/* to Admin::ProductsController (app/controllers/admin/products_controller.rb)
- # admin.resources :products
+ # namespace :admin do
+ # # Directs /admin/products/* to Admin::ProductsController
+ # # (app/controllers/admin/products_controller.rb)
+ # resources :products
# end
- # You can have the root of your site routed with map.root -- just remember to delete public/index.html.
- map.root :controller => "assets"
-
- map.logout '/logout', :controller => 'sessions', :action => 'destroy'
- map.login '/login', :controller => 'sessions', :action => 'new'
-
- map.resource :session
-
- map.resources :assets
-
+ # You can have the root of your site routed with "root"
+ # just remember to delete public/index.html.
+ # root :to => "welcome#index"
+ root :to => "assets#index"
# See how all your routes lay out with "rake routes"
- # Install the default routes as the lowest priority.
- map.connect ':controller/:action/:id'
- map.connect ':controller/:action/:id.:format'
+ # This is a legacy wild controller route that's not recommended for RESTful applications.
+ # Note: This route will make all actions in every controller accessible via GET requests.
+ # match ':controller(/:action(/:id(.:format)))'
end
View
15 db/migrate/20080731103639_create_assets.rb
@@ -1,15 +1,12 @@
class CreateAssets < ActiveRecord::Migration
def self.up
create_table :assets do |t|
- t.string :name
- t.string :filename
- t.string :content_type
- t.integer :size
- t.integer :width
- t.integer :height
- t.string :thumbnail
- t.integer :user_id
- t.integer :parent_id
+ t.string :image_file_name
+ t.string :image_content_type
+ t.integer :image_file_size
+ t.datetime :image_updated_at
+ t.references :user
+
t.timestamps
end
end
View
2  db/migrate/20080731103753_create_users.rb → db/migrate/20100807024304_create_users.rb
@@ -1,6 +1,6 @@
class CreateUsers < ActiveRecord::Migration
def self.up
- create_table "users", :force => true do |t|
+ create_table "users" do |t|
t.column :login, :string, :limit => 40
t.column :name, :string, :limit => 100, :default => '', :null => true
t.column :email, :string, :limit => 100
View
27 db/schema.rb
@@ -1,26 +1,23 @@
-# This file is auto-generated from the current state of the database. Instead of editing this file,
-# please use the migrations feature of Active Record to incrementally modify your database, and
-# then regenerate this schema definition.
+# This file is auto-generated from the current state of the database. Instead
+# of editing this file, please use the migrations feature of Active Record to
+# incrementally modify your database, and then regenerate this schema definition.
#
-# Note that this schema.rb definition is the authoritative source for your database schema. If you need
-# to create the application database on another system, you should be using db:schema:load, not running
-# all the migrations from scratch. The latter is a flawed and unsustainable approach (the more migrations
+# Note that this schema.rb definition is the authoritative source for your
+# database schema. If you need to create the application database on another
+# system, you should be using db:schema:load, not running all the migrations
+# from scratch. The latter is a flawed and unsustainable approach (the more migrations
# you'll amass, the slower it'll run and the greater likelihood for issues).
#
# It's strongly recommended to check this file into your version control system.
-ActiveRecord::Schema.define(:version => 20080731103753) do
+ActiveRecord::Schema.define(:version => 20100807024304) do
create_table "assets", :force => true do |t|
- t.string "name"
- t.string "filename"
- t.string "content_type"
- t.integer "size"
- t.integer "width"
- t.integer "height"
- t.string "thumbnail"
+ t.string "image_file_name"
+ t.string "image_content_type"
+ t.integer "image_file_size"
+ t.datetime "image_updated_at"
t.integer "user_id"
- t.integer "parent_id"
t.datetime "created_at"
t.datetime "updated_at"
end
View
8 db/seeds.rb
@@ -0,0 +1,8 @@
+# This file should contain all the record creation needed to seed the database with its default values.
+# The data can then be loaded with the rake db:seed (or created alongside the db with db:setup).
+#
+# Examples:
+#
+# cities = City.create([{ :name => 'Chicago' }, { :name => 'Copenhagen' }])
+# Mayor.create(:name => 'Daley', :city => cities.first)
+User.create!(:login => 'quentin', :email => 'quentin@example.com', :password => 'monkey', :password_confirmation => 'monkey', :created_at => 5.days.ago.to_s(:db) )
View
2  doc/README_FOR_APP
@@ -1,2 +0,0 @@
-Use this README file to introduce your application and point to useful places in the API for learning more.
-Run "rake doc:app" to generate API documentation for your models, controllers, helpers, and libraries.
View
16 lib/authenticated_system.rb
@@ -31,7 +31,7 @@ def current_user=(new_user)
# current_user.login != "bob"
# end
#
- def authorized?(action=nil, resource=nil, *args)
+ def authorized?(action = action_name, resource = nil)
logged_in?
end
@@ -68,8 +68,10 @@ def access_denied
redirect_to new_session_path
end
# format.any doesn't work in rails version < http://dev.rubyonrails.org/changeset/8987
- # you may want to change format.any to e.g. format.any(:js, :xml)
- format.any do
+ # Add any other API formats here. (Some browsers, notably IE6, send Accept: */* and trigger
+ # the 'format.any' block incorrectly. See http://bit.ly/ie6_borken or http://bit.ly/ie6_borken2
+ # for a workaround.)
+ format.any(:json, :xml) do
request_http_basic_authentication 'Web Password'
end
end
@@ -86,8 +88,8 @@ def store_location
# to the passed default. Set an appropriately modified
# after_filter :store_location, :only => [:index, :new, :show, :edit]
# for any controller you want to be bounce-backable.
- def redirect_back_or_default(default)
- redirect_to(session[:return_to] || default)
+ def redirect_back_or_default(default, options = {})
+ redirect_to((session[:return_to] || default), options)
session[:return_to] = nil
end
@@ -120,7 +122,7 @@ def login_from_basic_auth
# Called from #current_user. Finaly, attempt to login by an expiring token in the cookie.
# for the paranoid: we _should_ be storing user_token = hash(cookie_token, request IP)
def login_from_cookie
- user = cookies[:auth_token] && User.find_by_remember_token(cookies[:auth_token])
+ user = cookies[:auth_token] && User.find_by_remember_token(cookies[:auth_token].value)
if user && user.remember_token?
self.current_user = user
handle_remember_cookie! false # freshen cookie token (keeping date)
@@ -164,7 +166,7 @@ def valid_remember_cookie?
end
# Refresh the cookie auth token if it exists, create it otherwise
- def handle_remember_cookie! new_cookie_flag
+ def handle_remember_cookie!(new_cookie_flag)
return unless @current_user
case
when valid_remember_cookie? then @current_user.refresh_token # keeping same expiry date
View
2  lib/authenticated_test_helper.rb
@@ -1,7 +1,7 @@
module AuthenticatedTestHelper
# Sets the current user in the session from the user fixtures.
def login_as(user)
- @request.session[:user_id] = user ? users(user).id : nil
+ @request.session[:user_id] = user ? (user.is_a?(User) ? user.id : users(user).id) : nil
end
def authorize_as(user)
View
0  public/favicon.ico → lib/tasks/.gitkeep
File renamed without changes
View
0  log/production.log
No changes.
View
34 public/404.html
@@ -1,23 +1,19 @@
-<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
- "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
-
-<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
-
+<!DOCTYPE html>
+<html>
<head>
- <meta http-equiv="content-type" content="text/html; charset=UTF-8" />
<title>The page you were looking for doesn't exist (404)</title>
- <style type="text/css">
- body { background-color: #fff; color: #666; text-align: center; font-family: arial, sans-serif; }
- div.dialog {
- width: 25em;
- padding: 0 4em;
- margin: 4em auto 0 auto;
- border: 1px solid #ccc;
- border-right-color: #999;
- border-bottom-color: #999;
- }
- h1 { font-size: 100%; color: #f00; line-height: 1.5em; }
- </style>
+ <style type="text/css">
+ body { background-color: #fff; color: #666; text-align: center; font-family: arial, sans-serif; }
+ div.dialog {
+ width: 25em;
+ padding: 0 4em;
+ margin: 4em auto 0 auto;
+ border: 1px solid #ccc;
+ border-right-color: #999;
+ border-bottom-color: #999;
+ }
+ h1 { font-size: 100%; color: #f00; line-height: 1.5em; }
+ </style>
</head>
<body>
@@ -27,4 +23,4 @@
<p>You may have mistyped the address or the page may have moved.</p>
</div>
</body>
-</html>
+</html>
View
34 public/422.html
@@ -1,23 +1,19 @@
-<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
- "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
-
-<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
-
+<!DOCTYPE html>
+<html>
<head>
- <meta http-equiv="content-type" content="text/html; charset=UTF-8" />
<title>The change you wanted was rejected (422)</title>
- <style type="text/css">
- body { background-color: #fff; color: #666; text-align: center; font-family: arial, sans-serif; }
- div.dialog {
- width: 25em;
- padding: 0 4em;
- margin: 4em auto 0 auto;
- border: 1px solid #ccc;
- border-right-color: #999;
- border-bottom-color: #999;
- }
- h1 { font-size: 100%; color: #f00; line-height: 1.5em; }
- </style>
+ <style type="text/css">
+ body { background-color: #fff; color: #666; text-align: center; font-family: arial, sans-serif; }
+ div.dialog {
+ width: 25em;
+ padding: 0 4em;
+ margin: 4em auto 0 auto;
+ border: 1px solid #ccc;
+ border-right-color: #999;
+ border-bottom-color: #999;
+ }
+ h1 { font-size: 100%; color: #f00; line-height: 1.5em; }
+ </style>
</head>
<body>
@@ -27,4 +23,4 @@
<p>Maybe you tried to change something you didn't have access to.</p>
</div>
</body>
-</html>
+</html>
View
34 public/500.html
@@ -1,23 +1,19 @@
-<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
- "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
-
-<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
-
+<!DOCTYPE html>
+<html>
<head>
- <meta http-equiv="content-type" content="text/html; charset=UTF-8" />
<title>We're sorry, but something went wrong (500)</title>
- <style type="text/css">
- body { background-color: #fff; color: #666; text-align: center; font-family: arial, sans-serif; }
- div.dialog {
- width: 25em;
- padding: 0 4em;
- margin: 4em auto 0 auto;
- border: 1px solid #ccc;
- border-right-color: #999;
- border-bottom-color: #999;
- }
- h1 { font-size: 100%; color: #f00; line-height: 1.5em; }
- </style>
+ <style type="text/css">
+ body { background-color: #fff; color: #666; text-align: center; font-family: arial, sans-serif; }
+ div.dialog {
+ width: 25em;
+ padding: 0 4em;
+ margin: 4em auto 0 auto;
+ border: 1px solid #ccc;
+ border-right-color: #999;
+ border-bottom-color: #999;
+ }
+ h1 { font-size: 100%; color: #f00; line-height: 1.5em; }
+ </style>
</head>
<body>
@@ -27,4 +23,4 @@
<p>We've been notified about this issue and we'll take a look at it shortly.</p>
</div>
</body>
-</html>
+</html>
View
BIN  public/assets/.DS_Store
Binary file not shown
View
10 public/dispatch.cgi
@@ -1,10 +0,0 @@
-#!/opt/local/bin/ruby
-
-require File.dirname(__FILE__) + "/../config/environment" unless defined?(RAILS_ROOT)
-
-# If you're using RubyGems and mod_ruby, this require should be changed to an absolute path one, like:
-# "/usr/local/lib/ruby/gems/1.8/gems/rails-0.8.0/lib/dispatcher" -- otherwise performance is severely impaired
-require "dispatcher"
-
-ADDITIONAL_LOAD_PATHS.reverse.each { |dir| $:.unshift(dir) if File.directory?(dir) } if defined?(Apache::RubyRun)
-Dispatcher.dispatch
View
24 public/dispatch.fcgi
@@ -1,24 +0,0 @@
-#!/opt/local/bin/ruby
-#
-# You may specify the path to the FastCGI crash log (a log of unhandled
-# exceptions which forced the FastCGI instance to exit, great for debugging)
-# and the number of requests to process before running garbage collection.
-#
-# By default, the FastCGI crash log is RAILS_ROOT/log/fastcgi.crash.log
-# and the GC period is nil (turned off). A reasonable number of requests
-# could range from 10-100 depending on the memory footprint of your app.
-#
-# Example:
-# # Default log path, normal GC behavior.
-# RailsFCGIHandler.process!
-#
-# # Default log path, 50 requests between GC.
-# RailsFCGIHandler.process! nil, 50
-#
-# # Custom log path, normal GC behavior.
-# RailsFCGIHandler.process! '/var/log/myapp_fcgi_crash.log'
-#
-require File.dirname(__FILE__) + "/../config/environment"
-require 'fcgi_handler'
-
-RailsFCGIHandler.process!
View
10 public/dispatch.rb
@@ -1,10 +0,0 @@
-#!/opt/local/bin/ruby
-
-require File.dirname(__FILE__) + "/../config/environment" unless defined?(RAILS_ROOT)
-
-# If you're using RubyGems and mod_ruby, this require should be changed to an absolute path one, like:
-# "/usr/local/lib/ruby/gems/1.8/gems/rails-0.8.0/lib/dispatcher" -- otherwise performance is severely impaired
-require "dispatcher"
-
-ADDITIONAL_LOAD_PATHS.reverse.each { |dir| $:.unshift(dir) if File.directory?(dir) } if defined?(Apache::RubyRun)
-Dispatcher.dispatch
View
BIN  public/flash/swfupload.swf
Binary file not shown
View
2  public/javascripts/application.js
@@ -0,0 +1,2 @@
+// Place your application-specific JavaScript functions and classes here
+// This file is automatically included by javascript_include_tag :defaults
View
965 public/javascripts/controls.js
@@ -0,0 +1,965 @@
+// script.aculo.us controls.js v1.8.3, Thu Oct 08 11:23:33 +0200 2009
+
+// Copyright (c) 2005-2009 Thomas Fuchs (http://script.aculo.us, http://mir.aculo.us)
+// (c) 2005-2009 Ivan Krstic (http://blogs.law.harvard.edu/ivan)
+// (c) 2005-2009 Jon Tirsen (http://www.tirsen.com)
+// Contributors:
+// Richard Livsey
+// Rahul Bhargava
+// Rob Wills
+//
+// script.aculo.us is freely distributable under the terms of an MIT-style license.
+// For details, see the script.aculo.us web site: http://script.aculo.us/
+
+// Autocompleter.Base handles all the autocompletion functionality
+// that's independent of the data source for autocompletion. This
+// includes drawing the autocompletion menu, observing keyboard
+// and mouse events, and similar.
+//
+// Specific autocompleters need to provide, at the very least,
+// a getUpdatedChoices function that will be invoked every time
+// the text inside the monitored textbox changes. This method
+// should get the text for which to provide autocompletion by
+// invoking this.getToken(), NOT by directly accessing
+// this.element.value. This is to allow incremental tokenized
+// autocompletion. Specific auto-completion logic (AJAX, etc)
+// belongs in getUpdatedChoices.
+//
+// Tokenized incremental autocompletion is enabled automatically
+// when an autocompleter is instantiated with the 'tokens' option
+// in the options parameter, e.g.:
+// new Ajax.Autocompleter('id','upd', '/url/', { tokens: ',' });
+// will incrementally autocomplete with a comma as the token.
+// Additionally, ',' in the above example can be replaced with
+// a token array, e.g. { tokens: [',', '\n'] } which
+// enables autocompletion on multiple tokens. This is most
+// useful when one of the tokens is \n (a newline), as it
+// allows smart autocompletion after linebreaks.
+
+if(typeof Effect == 'undefined')
+ throw("controls.js requires including script.aculo.us' effects.js library");
+
+var Autocompleter = { };
+Autocompleter.Base = Class.create({
+ baseInitialize: function(element, update, options) {
+ element = $(element);
+ this.element = element;
+ this.update = $(update);
+ this.hasFocus = false;
+ this.changed = false;
+ this.active = false;
+ this.index = 0;
+ this.entryCount = 0;
+ this.oldElementValue = this.element.value;
+
+ if(this.setOptions)
+ this.setOptions(options);
+ else
+ this.options = options || { };
+
+ this.options.paramName = this.options.paramName || this.element.name;
+ this.options.tokens = this.options.tokens || [];
+ this.options.frequency = this.options.frequency || 0.4;
+ this.options.minChars = this.options.minChars || 1;
+ this.options.onShow = this.options.onShow ||
+ function(element, update){
+ if(!update.style.position || update.style.position=='absolute') {
+ update.style.position = 'absolute';
+ Position.clone(element, update, {
+ setHeight: false,
+ offsetTop: element.offsetHeight
+ });
+ }
+ Effect.Appear(update,{duration:0.15});
+ };
+ this.options.onHide = this.options.onHide ||
+ function(element, update){ new Effect.Fade(update,{duration:0.15}) };
+
+ if(typeof(this.options.tokens) == 'string')
+ this.options.tokens = new Array(this.options.tokens);
+ // Force carriage returns as token delimiters anyway
+ if (!this.options.tokens.include('\n'))
+ this.options.tokens.push('\n');
+
+ this.observer = null;
+
+ this.element.setAttribute('autocomplete','off');
+
+ Element.hide(this.update);
+
+ Event.observe(this.element, 'blur', this.onBlur.bindAsEventListener(this));
+ Event.observe(this.element, 'keydown', this.onKeyPress.bindAsEventListener(this));
+ },
+
+ show: function() {
+ if(Element.getStyle(this.update, 'display')=='none') this.options.onShow(this.element, this.update);
+ if(!this.iefix &&
+ (Prototype.Browser.IE) &&
+ (Element.getStyle(this.update, 'position')=='absolute')) {
+ new Insertion.After(this.update,
+ '<iframe id="' + this.update.id + '_iefix" '+
+ 'style="display:none;position:absolute;filter:progid:DXImageTransform.Microsoft.Alpha(opacity=0);" ' +
+ 'src="javascript:false;" frameborder="0" scrolling="no"></iframe>');
+ this.iefix = $(this.update.id+'_iefix');
+ }
+ if(this.iefix) setTimeout(this.fixIEOverlapping.bind(this), 50);
+ },
+
+ fixIEOverlapping: function() {
+ Position.clone(this.update, this.iefix, {setTop:(!this.update.style.height)});
+ this.iefix.style.zIndex = 1;
+ this.update.style.zIndex = 2;
+ Element.show(this.iefix);
+ },
+
+ hide: function() {
+ this.stopIndicator();
+ if(Element.getStyle(this.update, 'display')!='none') this.options.onHide(this.element, this.update);
+ if(this.iefix) Element.hide(this.iefix);
+ },
+
+ startIndicator: function() {
+ if(this.options.indicator) Element.show(this.options.indicator);
+ },
+
+ stopIndicator: function() {
+ if(this.options.indicator) Element.hide(this.options.indicator);
+ },
+
+ onKeyPress: function(event) {
+ if(this.active)
+ switch(event.keyCode) {
+ case Event.KEY_TAB:
+ case Event.KEY_RETURN:
+ this.selectEntry();
+ Event.stop(event);
+ case Event.KEY_ESC:
+ this.hide();
+ this.active = false;
+ Event.stop(event);
+ return;
+ case Event.KEY_LEFT:
+ case Event.KEY_RIGHT:
+ return;
+ case Event.KEY_UP:
+ this.markPrevious();
+ this.render();
+ Event.stop(event);
+ return;
+ case Event.KEY_DOWN:
+ this.markNext();
+ this.render();
+ Event.stop(event);
+ return;
+ }
+ else
+ if(event.keyCode==Event.KEY_TAB || event.keyCode==Event.KEY_RETURN ||
+ (Prototype.Browser.WebKit > 0 && event.keyCode == 0)) return;
+
+ this.changed = true;
+ this.hasFocus = true;
+
+ if(this.observer) clearTimeout(this.observer);
+ this.observer =
+ setTimeout(this.onObserverEvent.bind(this), this.options.frequency*1000);
+ },
+
+ activate: function() {
+ this.changed = false;
+ this.hasFocus = true;
+ this.getUpdatedChoices();
+ },
+
+ onHover: function(event) {
+ var element = Event.findElement(event, 'LI');
+ if(this.index != element.autocompleteIndex)
+ {
+ this.index = element.autocompleteIndex;
+ this.render();
+ }
+ Event.stop(event);
+ },
+
+ onClick: function(event) {
+ var element = Event.findElement(event, 'LI');
+ this.index = element.autocompleteIndex;
+ this.selectEntry();
+ this.hide();
+ },
+
+ onBlur: function(event) {
+ // needed to make click events working
+ setTimeout(this.hide.bind(this), 250);
+ this.hasFocus = false;
+ this.active = false;
+ },
+
+ render: function() {
+ if(this.entryCount > 0) {
+ for (var i = 0; i < this.entryCount; i++)
+ this.index==i ?
+ Element.addClassName(this.getEntry(i),"selected") :
+ Element.removeClassName(this.getEntry(i),"selected");
+ if(this.hasFocus) {
+ this.show();
+ this.active = true;
+ }
+ } else {
+ this.active = false;
+ this.hide();
+ }
+ },
+
+ markPrevious: function() {
+ if(this.index > 0) this.index--;
+ else this.index = this.entryCount-1;
+ this.getEntry(this.index).scrollIntoView(true);
+ },
+
+ markNext: function() {
+ if(this.index < this.entryCount-1) this.index++;
+ else this.index = 0;
+ this.getEntry(this.index).scrollIntoView(false);
+ },
+
+ getEntry: function(index) {