Skip to content

Commit

Permalink
Updated to rails 3
Browse files Browse the repository at this point in the history
  • Loading branch information
lardawge committed Aug 7, 2010
1 parent c4b50b1 commit 60971d1
Show file tree
Hide file tree
Showing 202 changed files with 12,344 additions and 5,696 deletions.
6 changes: 6 additions & 0 deletions .gitignore
@@ -0,0 +1,6 @@
.bundle
.DS_Store
db/*.sqlite3
log/*.log
tmp/**/*

32 changes: 32 additions & 0 deletions 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
78 changes: 78 additions & 0 deletions 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
37 changes: 0 additions & 37 deletions README

This file was deleted.

18 changes: 18 additions & 0 deletions README.rdoc
@@ -0,0 +1,18 @@
= swfupload-rails-authentication

Demo Rails 3.0.0.rc app showing SWFUpload working in tandem with restful-authentication, CSRF protection and paperclip.

== Usage

gem install bundler --pre
bundle install
rake db:migrate
rake db:seed
rails s

== Login

The restful authentication test user;

username: quentin
password: monkey
7 changes: 2 additions & 5 deletions 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
20 changes: 3 additions & 17 deletions app/controllers/application_controller.rb
@@ -1,19 +1,5 @@
# Filters added to this controller apply to all controllers in the application.
# Likewise, all the methods added will be available for all controllers.

require 'lib/authenticated_system'
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
protect_from_forgery
end
4 changes: 1 addition & 3 deletions app/controllers/assets_controller.rb
@@ -1,6 +1,4 @@
class AssetsController < ApplicationController

layout 'layout'

before_filter :login_required

Expand Down Expand Up @@ -53,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
Expand Down
8 changes: 3 additions & 5 deletions app/controllers/sessions_controller.rb
Expand Up @@ -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]
Expand All @@ -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
1 change: 0 additions & 1 deletion 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
2 changes: 1 addition & 1 deletion app/helpers/assets_helper.rb
@@ -1,6 +1,6 @@
module AssetsHelper
def new_asset_path_with_session_information
session_key = ActionController::Base.session_options[:key]
session_key = Rails.application.config.session_options[:key]
assets_path(session_key => cookies[session_key], request_forgery_protection_token => form_authenticity_token)
end
end
22 changes: 21 additions & 1 deletion app/middleware/flash_session_cookie_middleware.rb
Expand Up @@ -8,9 +8,29 @@ def initialize(app, session_key = '_session_id')

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
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
29 changes: 14 additions & 15 deletions 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

0 comments on commit 60971d1

Please sign in to comment.