Skip to content
Browse files

initial commit

  • Loading branch information...
0 parents commit ad8a136317ec20c0a94576e980804f17a0497cde @NoamB NoamB committed Jan 30, 2011
Showing with 10,985 additions and 0 deletions.
  1. +7 −0 .gitignore
  2. +28 −0 Gemfile
  3. +155 −0 Gemfile.lock
  4. +256 −0 README
  5. +7 −0 Rakefile
  6. +17 −0 app/controllers/application_controller.rb
  7. +30 −0 app/controllers/password_resets_controller.rb
  8. +26 −0 app/controllers/user_sessions_controller.rb
  9. +95 −0 app/controllers/users_controller.rb
  10. +2 −0 app/helpers/application_helper.rb
  11. +2 −0 app/helpers/password_resets_helper.rb
  12. +2 −0 app/helpers/user_sessions_helper.rb
  13. +2 −0 app/helpers/users_helper.rb
  14. +25 −0 app/mailers/my_mailer.rb
  15. +12 −0 app/mailers/user_mailer.rb
  16. +10 −0 app/models/user.rb
  17. +23 −0 app/views/layouts/application.html.erb
  18. +17 −0 app/views/my_mailer/activation_needed_email.html.erb
  19. +9 −0 app/views/my_mailer/activation_needed_email.text.erb
  20. +17 −0 app/views/my_mailer/activation_success_email.html.erb
  21. +9 −0 app/views/my_mailer/activation_success_email.text.erb
  22. +16 −0 app/views/my_mailer/reset_password_email.html.erb
  23. +8 −0 app/views/my_mailer/reset_password_email.text.erb
  24. +30 −0 app/views/password_resets/_form.html.erb
  25. +5 −0 app/views/password_resets/edit.html.erb
  26. +20 −0 app/views/user_mailer/password_reset_instructions.html.erb
  27. +8 −0 app/views/user_mailer/password_reset_instructions.text.erb
  28. +6 −0 app/views/user_sessions/_forgot_password_form.html.erb
  29. +17 −0 app/views/user_sessions/_form.html.erb
  30. +2 −0 app/views/user_sessions/create.html.erb
  31. +2 −0 app/views/user_sessions/destroy.html.erb
  32. +6 −0 app/views/user_sessions/edit.html.erb
  33. +9 −0 app/views/user_sessions/new.html.erb
  34. +29 −0 app/views/users/_form.html.erb
  35. +6 −0 app/views/users/edit.html.erb
  36. +24 −0 app/views/users/index.html.erb
  37. +5 −0 app/views/users/new.html.erb
  38. +25 −0 app/views/users/show.html.erb
  39. +4 −0 config.ru
  40. +44 −0 config/application.rb
  41. +13 −0 config/boot.rb
  42. +39 −0 config/database.yml
  43. +5 −0 config/environment.rb
  44. +36 −0 config/environments/development.rb
  45. +49 −0 config/environments/production.rb
  46. +35 −0 config/environments/test.rb
  47. +7 −0 config/initializers/backtrace_silencers.rb
  48. +10 −0 config/initializers/inflections.rb
  49. +5 −0 config/initializers/mime_types.rb
  50. +7 −0 config/initializers/secret_token.rb
  51. +8 −0 config/initializers/session_store.rb
  52. +5 −0 config/locales/en.yml
  53. +72 −0 config/routes.rb
  54. +17 −0 db/migrate/20101210151424_create_users.rb
  55. +15 −0 db/migrate/20101224223622_add_activation_to_users.rb
  56. +15 −0 db/migrate/20101224223623_add_remember_me_token_to_users.rb
  57. +9 −0 db/migrate/20101224223624_add_password_reset_to_users.rb
  58. +32 −0 db/schema.rb
  59. +7 −0 db/seeds.rb
  60. +2 −0 doc/README_FOR_APP
  61. 0 lib/tasks/.gitkeep
  62. +26 −0 public/404.html
  63. +26 −0 public/422.html
  64. +26 −0 public/500.html
  65. 0 public/favicon.ico
  66. BIN public/images/rails.png
  67. +2 −0 public/javascripts/application.js
  68. +965 −0 public/javascripts/controls.js
  69. +974 −0 public/javascripts/dragdrop.js
  70. +1,123 −0 public/javascripts/effects.js
  71. +6,001 −0 public/javascripts/prototype.js
  72. +175 −0 public/javascripts/rails.js
  73. +5 −0 public/robots.txt
  74. 0 public/stylesheets/.gitkeep
  75. +60 −0 public/stylesheets/scaffold.css
  76. +6 −0 script/rails
  77. +33 −0 spec/controllers/password_resets_controller_spec.rb
  78. +15 −0 spec/helpers/password_resets_helper_spec.rb
  79. +5 −0 spec/views/password_resets/create.html.erb_spec.rb
  80. +5 −0 spec/views/password_resets/edit.html.erb_spec.rb
  81. +5 −0 spec/views/password_resets/new.html.erb_spec.rb
  82. +5 −0 spec/views/password_resets/update.html.erb_spec.rb
  83. +8 −0 test/fixtures/users.yml
  84. +8 −0 test/functional/user_mailer_test.rb
  85. +19 −0 test/functional/user_sessions_controller_test.rb
  86. +49 −0 test/functional/users_controller_test.rb
  87. +9 −0 test/performance/browsing_test.rb
  88. +14 −0 test/test_helper.rb
  89. +4 −0 test/unit/helpers/user_sessions_helper_test.rb
  90. +4 −0 test/unit/helpers/users_helper_test.rb
  91. +8 −0 test/unit/user_test.rb
7 .gitignore
@@ -0,0 +1,7 @@
+.bundle
+db/*.sqlite3
+log/*.log
+tmp/**/*
+.rvmrc
+rvm*
+vendor
28 Gemfile
@@ -0,0 +1,28 @@
+source 'http://rubygems.org'
+
+gem 'rails', '3.0.3'
+gem 'mysql2'
+
+# Deploy with Capistrano
+# gem 'capistrano'
+
+# To use debugger (ruby-debug for Ruby 1.8.7+, ruby-debug19 for Ruby 1.9.2+)
+# gem 'ruby-debug'
+
+
+# Bundle the extra gems:
+gem 'sorcery'
+
+# 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 'ruby-debug19'
+ gem 'capybara'
+ gem 'database_cleaner'
+ gem 'cucumber-rails'
+ gem 'cucumber'
+ gem 'rspec-rails'
+ gem 'spork'
+ gem 'launchy'
+end
155 Gemfile.lock
@@ -0,0 +1,155 @@
+GEM
+ remote: http://rubygems.org/
+ specs:
+ abstract (1.0.0)
+ actionmailer (3.0.3)
+ actionpack (= 3.0.3)
+ mail (~> 2.2.9)
+ actionpack (3.0.3)
+ activemodel (= 3.0.3)
+ activesupport (= 3.0.3)
+ builder (~> 2.1.2)
+ erubis (~> 2.6.6)
+ i18n (~> 0.4)
+ rack (~> 1.2.1)
+ rack-mount (~> 0.6.13)
+ rack-test (~> 0.5.6)
+ tzinfo (~> 0.3.23)
+ activemodel (3.0.3)
+ activesupport (= 3.0.3)
+ builder (~> 2.1.2)
+ i18n (~> 0.4)
+ activerecord (3.0.3)
+ activemodel (= 3.0.3)
+ activesupport (= 3.0.3)
+ arel (~> 2.0.2)
+ tzinfo (~> 0.3.23)
+ activeresource (3.0.3)
+ activemodel (= 3.0.3)
+ activesupport (= 3.0.3)
+ activesupport (3.0.3)
+ archive-tar-minitar (0.5.2)
+ arel (2.0.6)
+ builder (2.1.2)
+ capybara (0.4.0)
+ celerity (>= 0.7.9)
+ culerity (>= 0.2.4)
+ mime-types (>= 1.16)
+ nokogiri (>= 1.3.3)
+ rack (>= 1.0.0)
+ rack-test (>= 0.5.4)
+ selenium-webdriver (>= 0.0.27)
+ xpath (~> 0.1.2)
+ celerity (0.8.6)
+ childprocess (0.1.6)
+ ffi (~> 0.6.3)
+ columnize (0.3.2)
+ configuration (1.2.0)
+ cucumber (0.10.0)
+ builder (>= 2.1.2)
+ diff-lcs (~> 1.1.2)
+ gherkin (~> 2.3.2)
+ json (~> 1.4.6)
+ term-ansicolor (~> 1.0.5)
+ cucumber-rails (0.3.2)
+ cucumber (>= 0.8.0)
+ culerity (0.2.13)
+ database_cleaner (0.6.0)
+ diff-lcs (1.1.2)
+ erubis (2.6.6)
+ abstract (>= 1.0.0)
+ ffi (0.6.3)
+ rake (>= 0.8.7)
+ gherkin (2.3.2)
+ json (~> 1.4.6)
+ term-ansicolor (~> 1.0.5)
+ i18n (0.5.0)
+ json (1.4.6)
+ json_pure (1.4.6)
+ launchy (0.3.7)
+ configuration (>= 0.0.5)
+ rake (>= 0.8.1)
+ linecache19 (0.5.11)
+ ruby_core_source (>= 0.1.4)
+ mail (2.2.12)
+ activesupport (>= 2.3.6)
+ i18n (>= 0.4.0)
+ mime-types (~> 1.16)
+ treetop (~> 1.4.8)
+ mime-types (1.16)
+ mysql2 (0.2.6)
+ nokogiri (1.4.4)
+ polyglot (0.3.1)
+ rack (1.2.1)
+ rack-mount (0.6.13)
+ rack (>= 1.0.0)
+ rack-test (0.5.6)
+ rack (>= 1.0)
+ rails (3.0.3)
+ actionmailer (= 3.0.3)
+ actionpack (= 3.0.3)
+ activerecord (= 3.0.3)
+ activeresource (= 3.0.3)
+ activesupport (= 3.0.3)
+ bundler (~> 1.0)
+ railties (= 3.0.3)
+ railties (3.0.3)
+ actionpack (= 3.0.3)
+ activesupport (= 3.0.3)
+ rake (>= 0.8.7)
+ thor (~> 0.14.4)
+ rake (0.8.7)
+ rspec (2.3.0)
+ rspec-core (~> 2.3.0)
+ rspec-expectations (~> 2.3.0)
+ rspec-mocks (~> 2.3.0)
+ rspec-core (2.3.1)
+ rspec-expectations (2.3.0)
+ diff-lcs (~> 1.1.2)
+ rspec-mocks (2.3.0)
+ rspec-rails (2.3.1)
+ actionpack (~> 3.0)
+ activesupport (~> 3.0)
+ railties (~> 3.0)
+ rspec (~> 2.3.0)
+ ruby-debug-base19 (0.11.24)
+ columnize (>= 0.3.1)
+ linecache19 (>= 0.5.11)
+ ruby_core_source (>= 0.1.4)
+ ruby-debug19 (0.11.6)
+ columnize (>= 0.3.1)
+ linecache19 (>= 0.5.11)
+ ruby-debug-base19 (>= 0.11.19)
+ ruby_core_source (0.1.4)
+ archive-tar-minitar (>= 0.5.2)
+ rubyzip (0.9.4)
+ selenium-webdriver (0.1.2)
+ childprocess (~> 0.1.5)
+ ffi (~> 0.6.3)
+ json_pure
+ rubyzip
+ sorcery (0.2.0)
+ spork (0.8.4)
+ term-ansicolor (1.0.5)
+ thor (0.14.6)
+ treetop (1.4.9)
+ polyglot (>= 0.3.1)
+ tzinfo (0.3.23)
+ xpath (0.1.2)
+ nokogiri (~> 1.3)
+
+PLATFORMS
+ ruby
+
+DEPENDENCIES
+ capybara
+ cucumber
+ cucumber-rails
+ database_cleaner
+ launchy
+ mysql2
+ rails (= 3.0.3)
+ rspec-rails
+ ruby-debug19
+ sorcery
+ spork
256 README
@@ -0,0 +1,256 @@
+== Welcome to Rails
+
+Rails is a web-application framework that includes everything needed to create
+database-backed web applications according to the Model-View-Control pattern.
+
+This pattern splits the view (also called the presentation) into "dumb"
+templates that are primarily responsible for inserting pre-built data in between
+HTML tags. The model contains the "smart" domain objects (such as Account,
+Product, Person, Post) that holds all the business logic and knows how to
+persist themselves to a database. The controller handles the incoming requests
+(such as Save New Account, Update Product, Show Post) by manipulating the model
+and directing data to the view.
+
+In Rails, the model is handled by what's called an object-relational mapping
+layer entitled Active Record. This layer allows you to present the data from
+database rows as objects and embellish these data objects with business logic
+methods. You can read more about Active Record in
+link:files/vendor/rails/activerecord/README.html.
+
+The controller and view are handled by the Action Pack, which handles both
+layers by its two parts: Action View and Action Controller. These two layers
+are bundled in a single package due to their heavy interdependence. This is
+unlike the relationship between the Active Record and Action Pack that is much
+more separate. Each of these packages can be used independently outside of
+Rails. You can read more about Action Pack in
+link:files/vendor/rails/actionpack/README.html.
+
+
+== Getting Started
+
+1. At the command prompt, create a new Rails application:
+ <tt>rails new myapp</tt> (where <tt>myapp</tt> is the application name)
+
+2. Change directory to <tt>myapp</tt> and start the web server:
+ <tt>cd myapp; rails server</tt> (run with --help for options)
+
+3. Go to http://localhost:3000/ and you'll see:
+ "Welcome aboard: You're riding Ruby on Rails!"
+
+4. Follow the guidelines to start developing your application. You can find
+the following resources handy:
+
+* The Getting Started Guide: http://guides.rubyonrails.org/getting_started.html
+* Ruby on Rails Tutorial Book: http://www.railstutorial.org/
+
+
+== Debugging Rails
+
+Sometimes your application goes wrong. Fortunately there are a lot of tools that
+will help you debug it and get it back on the rails.
+
+First area to check is the application log files. Have "tail -f" commands
+running on the server.log and development.log. Rails will automatically display
+debugging and runtime information to these files. Debugging info will also be
+shown in the browser on requests from 127.0.0.1.
+
+You can also log your own messages directly into the log file from your code
+using the Ruby logger class from inside your controllers. Example:
+
+ class WeblogController < ActionController::Base
+ def destroy
+ @weblog = Weblog.find(params[:id])
+ @weblog.destroy
+ logger.info("#{Time.now} Destroyed Weblog ID ##{@weblog.id}!")
+ end
+ end
+
+The result will be a message in your log file along the lines of:
+
+ Mon Oct 08 14:22:29 +1000 2007 Destroyed Weblog ID #1!
+
+More information on how to use the logger is at http://www.ruby-doc.org/core/
+
+Also, Ruby documentation can be found at http://www.ruby-lang.org/. There are
+several books available online as well:
+
+* Programming Ruby: http://www.ruby-doc.org/docs/ProgrammingRuby/ (Pickaxe)
+* Learn to Program: http://pine.fm/LearnToProgram/ (a beginners guide)
+
+These two books will bring you up to speed on the Ruby language and also on
+programming in general.
+
+
+== Debugger
+
+Debugger support is available through the debugger command when you start your
+Mongrel or WEBrick server with --debugger. This means that you can break out of
+execution at any point in the code, investigate and change the model, and then,
+resume execution! You need to install ruby-debug to run the server in debugging
+mode. With gems, use <tt>sudo gem install ruby-debug</tt>. Example:
+
+ class WeblogController < ActionController::Base
+ def index
+ @posts = Post.find(:all)
+ debugger
+ end
+ end
+
+So the controller will accept the action, run the first line, then present you
+with a IRB prompt in the server window. Here you can do things like:
+
+ >> @posts.inspect
+ => "[#<Post:0x14a6be8
+ @attributes={"title"=>nil, "body"=>nil, "id"=>"1"}>,
+ #<Post:0x14a6620
+ @attributes={"title"=>"Rails", "body"=>"Only ten..", "id"=>"2"}>]"
+ >> @posts.first.title = "hello from a debugger"
+ => "hello from a debugger"
+
+...and even better, you can examine how your runtime objects actually work:
+
+ >> f = @posts.first
+ => #<Post:0x13630c4 @attributes={"title"=>nil, "body"=>nil, "id"=>"1"}>
+ >> f.
+ Display all 152 possibilities? (y or n)
+
+Finally, when you're ready to resume execution, you can enter "cont".
+
+
+== Console
+
+The console is a Ruby shell, which allows you to interact with your
+application's domain model. Here you'll have all parts of the application
+configured, just like it is when the application is running. You can inspect
+domain models, change values, and save to the database. Starting the script
+without arguments will launch it in the development environment.
+
+To start the console, run <tt>rails console</tt> from the application
+directory.
+
+Options:
+
+* Passing the <tt>-s, --sandbox</tt> argument will rollback any modifications
+ made to the database.
+* Passing an environment name as an argument will load the corresponding
+ environment. Example: <tt>rails console production</tt>.
+
+To reload your controllers and models after launching the console run
+<tt>reload!</tt>
+
+More information about irb can be found at:
+link:http://www.rubycentral.com/pickaxe/irb.html
+
+
+== dbconsole
+
+You can go to the command line of your database directly through <tt>rails
+dbconsole</tt>. You would be connected to the database with the credentials
+defined in database.yml. Starting the script without arguments will connect you
+to the development database. Passing an argument will connect you to a different
+database, like <tt>rails dbconsole production</tt>. Currently works for MySQL,
+PostgreSQL and SQLite 3.
+
+== Description of Contents
+
+The default directory structure of a generated Ruby on Rails application:
+
+ |-- app
+ | |-- controllers
+ | |-- helpers
+ | |-- mailers
+ | |-- models
+ | `-- views
+ | `-- layouts
+ |-- config
+ | |-- environments
+ | |-- initializers
+ | `-- locales
+ |-- db
+ |-- doc
+ |-- lib
+ | `-- tasks
+ |-- log
+ |-- public
+ | |-- images
+ | |-- javascripts
+ | `-- stylesheets
+ |-- script
+ |-- test
+ | |-- fixtures
+ | |-- functional
+ | |-- integration
+ | |-- performance
+ | `-- unit
+ |-- tmp
+ | |-- cache
+ | |-- pids
+ | |-- sessions
+ | `-- sockets
+ `-- vendor
+ `-- plugins
+
+app
+ Holds all the code that's specific to this particular application.
+
+app/controllers
+ Holds controllers that should be named like weblogs_controller.rb for
+ automated URL mapping. All controllers should descend from
+ ApplicationController which itself descends from ActionController::Base.
+
+app/models
+ Holds models that should be named like post.rb. Models descend from
+ ActiveRecord::Base by default.
+
+app/views
+ Holds the template files for the view that should be named like
+ weblogs/index.html.erb for the WeblogsController#index action. All views use
+ eRuby syntax by default.
+
+app/views/layouts
+ Holds the template files for layouts to be used with views. This models the
+ common header/footer method of wrapping views. In your views, define a layout
+ using the <tt>layout :default</tt> and create a file named default.html.erb.
+ Inside default.html.erb, call <% yield %> to render the view using this
+ layout.
+
+app/helpers
+ Holds view helpers that should be named like weblogs_helper.rb. These are
+ generated for you automatically when using generators for controllers.
+ Helpers can be used to wrap functionality for your views into methods.
+
+config
+ Configuration files for the Rails environment, the routing map, the database,
+ and other dependencies.
+
+db
+ Contains the database schema in schema.rb. db/migrate contains all the
+ sequence of Migrations for your schema.
+
+doc
+ This directory is where your application documentation will be stored when
+ generated using <tt>rake doc:app</tt>
+
+lib
+ Application specific libraries. Basically, any kind of custom code that
+ doesn't belong under controllers, models, or helpers. This directory is in
+ the load path.
+
+public
+ The directory available for the web server. Contains subdirectories for
+ images, stylesheets, and javascripts. Also contains the dispatchers and the
+ default HTML files. This should be set as the DOCUMENT_ROOT of your web
+ server.
+
+script
+ Helper scripts for automation and generation.
+
+test
+ Unit and functional tests along with fixtures. When using the rails generate
+ command, template test files will be generated for you and placed in this
+ directory.
+
+vendor
+ External libraries that the application depends on. Also includes the plugins
+ subdirectory. If the app has frozen rails, those gems also go here, under
+ vendor/rails/. This directory is in the load path.
7 Rakefile
@@ -0,0 +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.expand_path('../config/application', __FILE__)
+require 'rake'
+
+Collaboration::Application.load_tasks
17 app/controllers/application_controller.rb
@@ -0,0 +1,17 @@
+class ApplicationController < ActionController::Base
+ protect_from_forgery
+
+ activate_sorcery! do |config|
+ config.session_timeout = 10.minutes
+ config.session_timeout_from_last_action = false
+ end
+
+ before_filter :authenticate, :except => [:not_authenticated]
+
+ protected
+
+ def not_authenticated
+ redirect_to root_path, :alert => "Please login first."
+ end
+
+end
30 app/controllers/password_resets_controller.rb
@@ -0,0 +1,30 @@
+class PasswordResetsController < ApplicationController
+ skip_before_filter :authenticate
+
+ def create # request password reset
+ @user = User.find_by_email(params[:email])
+
+ @user.reset_password! if @user
+
+ # Tell the user instructions have been sent whether or not email was found.
+ # This is to not leak information to attackers about which emails exist in the system.
+ redirect_to(root_path, :notice => 'Instructions have been sent to your email.')
+ end
+
+ def edit
+ @user = User.find(params[:id])
+ @code = params[:c]
+ not_authenticated if @user.reset_password_code != @code
+ end
+
+ def update
+ @user = User.find(params[:id])
+ @code = params[:code]
+ if @code = @user.reset_password_code && @user.update_attributes(params[:user])
+ redirect_to(root_path, :notice => 'Password was successfully updated.')
+ else
+ render :action => "edit"
+ end
+ end
+
+end
26 app/controllers/user_sessions_controller.rb
@@ -0,0 +1,26 @@
+class UserSessionsController < ApplicationController
+ skip_before_filter :authenticate, :except => [:destroy]
+
+ def new
+ @user = User.new
+ end
+
+ def create
+
+ respond_to do |format|
+ if @user = login(params[:email],params[:password],params[:remember])
+ format.html { redirect_to(:users, :notice => 'Login successfull.') }
+ format.xml { render :xml => @user, :status => :created, :location => @user }
+ else
+ format.html { flash.now[:alert] = "Login failed."; render :action => "new" }
+ format.xml { render :xml => @user.errors, :status => :unprocessable_entity }
+ end
+ end
+ end
+
+ def destroy
+ logout
+ redirect_to(:users, :notice => 'Logged out!')
+ end
+
+end
95 app/controllers/users_controller.rb
@@ -0,0 +1,95 @@
+class UsersController < ApplicationController
+ skip_before_filter :authenticate, :only => [:index, :new, :create, :activate, :reset_password]
+ # GET /users
+ # GET /users.xml
+ def index
+ @users = User.all
+
+ respond_to do |format|
+ format.html # index.html.erb
+ format.xml { render :xml => @users }
+ end
+ end
+
+ # GET /users/1
+ # GET /users/1.xml
+ def show
+ @user = User.find(params[:id])
+
+ respond_to do |format|
+ format.html # show.html.erb
+ format.xml { render :xml => @user }
+ end
+ end
+
+ # GET /users/new
+ # GET /users/new.xml
+ def new
+ @user = User.new
+
+ respond_to do |format|
+ format.html # new.html.erb
+ format.xml { render :xml => @user }
+ end
+ end
+
+ # GET /users/1/edit
+ def edit
+ @user = User.find(params[:id])
+ end
+
+ # POST /users
+ # POST /users.xml
+ def create
+ @user = User.new(params[:user])
+
+ respond_to do |format|
+ if @user.save
+ format.html { redirect_to(:users, :notice => 'Registration successfull.') }
+ format.xml { render :xml => @user, :status => :created, :location => @user }
+ else
+ format.html { render :action => "new" }
+ format.xml { render :xml => @user.errors, :status => :unprocessable_entity }
+ end
+ end
+ end
+
+ # PUT /users/1
+ # PUT /users/1.xml
+ def update
+ @user = User.find(params[:id])
+
+ respond_to do |format|
+ if @user.update_attributes(params[:user])
+ format.html { redirect_to(@user, :notice => 'User was successfully updated.') }
+ format.xml { head :ok }
+ else
+ format.html { render :action => "edit" }
+ format.xml { render :xml => @user.errors, :status => :unprocessable_entity }
+ end
+ end
+ end
+
+ # DELETE /users/1
+ # DELETE /users/1.xml
+ def destroy
+ @user = User.find(params[:id])
+ @user.destroy
+
+ respond_to do |format|
+ format.html { redirect_to(users_url) }
+ format.xml { head :ok }
+ end
+ end
+
+ def activate
+ @user = User.find_by_activation_code(params[:c])
+ if @user
+ @user.activate!
+ redirect_to(login_path, :notice => 'User was successfully activated.')
+ else
+ not_authenticated
+ end
+ end
+
+end
2 app/helpers/application_helper.rb
@@ -0,0 +1,2 @@
+module ApplicationHelper
+end
2 app/helpers/password_resets_helper.rb
@@ -0,0 +1,2 @@
+module PasswordResetsHelper
+end
2 app/helpers/user_sessions_helper.rb
@@ -0,0 +1,2 @@
+module UserSessionsHelper
+end
2 app/helpers/users_helper.rb
@@ -0,0 +1,2 @@
+module UsersHelper
+end
25 app/mailers/my_mailer.rb
@@ -0,0 +1,25 @@
+class MyMailer < ActionMailer::Base
+
+ default :from => "notifications@example.com"
+
+ def activation_needed_email(user)
+ @user = user
+ @url = "http://0.0.0.0:3000/users/activate?c=#{user.activation_code}"
+ mail(:to => user.email,
+ :subject => "Welcome to My Awesome Site")
+ end
+
+ def activation_success_email(user)
+ @user = user
+ @url = "http://0.0.0.0:3000/login"
+ mail(:to => user.email,
+ :subject => "Your account is now activated")
+ end
+
+ def reset_password_email(user)
+ @user = user
+ @url = "http://0.0.0.0:3000/password_resets/#{user.id}/edit?c=#{user.reset_password_code}"
+ mail(:to => user.email,
+ :subject => "Your password has been reset")
+ end
+end
12 app/mailers/user_mailer.rb
@@ -0,0 +1,12 @@
+class UserMailer < ActionMailer::Base
+ default_url_options[:host] = "0.0.0.0:3000"
+ default :from => "notification@example.com"
+
+ def password_reset_instructions(user)
+ @user = user
+ @url = "http://example.com/login"
+ @edit_password_reset_url = edit_password_reset_url(user.perishable_token)
+ mail(:to => user.email,
+ :subject => "Welcome to My Awesome Site")
+ end
+end
10 app/models/user.rb
@@ -0,0 +1,10 @@
+class User < ActiveRecord::Base
+ attr_accessible :email, :password, :password_confirmation
+
+ activate_sorcery! do |config|
+ config.sorcery_mailer = MyMailer
+ config.username_attribute_name = :email
+ end
+
+ validates_confirmation_of :password, :on => :create, :message => "should match confirmation"
+end
23 app/views/layouts/application.html.erb
@@ -0,0 +1,23 @@
+<!DOCTYPE html>
+<html>
+<head>
+ <title>Collaboration</title>
+ <%= stylesheet_link_tag :all %>
+ <%= javascript_include_tag :defaults %>
+ <%= csrf_meta_tag %>
+</head>
+<body>
+
+ <div id="nav">
+ <% if logged_in_user %>
+ <%= link_to "Edit Profile", edit_user_path(logged_in_user.id) %>
+ <%= link_to "Logout", :logout %>
+ <% else %>
+ <%= link_to "Register", new_user_path %> |
+ <%= link_to "Login", :login %> |
+ <% end %>
+ </div>
+<%= yield %>
+
+</body>
+</html>
17 app/views/my_mailer/activation_needed_email.html.erb
@@ -0,0 +1,17 @@
+<!DOCTYPE html>
+<html>
+ <head>
+ <meta content="text/html; charset=UTF-8" http-equiv="Content-Type" />
+ </head>
+ <body>
+ <h1>Welcome to example.com, <%= @user.email %></h1>
+ <p>
+ You have successfully signed up to example.com,
+ your username is: <%= @user.email %>.<br/>
+ </p>
+ <p>
+ To login to the site, just follow this link: <%= @url %>.
+ </p>
+ <p>Thanks for joining and have a great day!</p>
+ </body>
+</html>
9 app/views/my_mailer/activation_needed_email.text.erb
@@ -0,0 +1,9 @@
+Welcome to example.com, <%= @user.email %>
+===============================================
+
+You have successfully signed up to example.com,
+your username is: <%= @user.email %>.
+
+To login to the site, just follow this link: <%= @url %>.
+
+Thanks for joining and have a great day!
17 app/views/my_mailer/activation_success_email.html.erb
@@ -0,0 +1,17 @@
+<!DOCTYPE html>
+<html>
+ <head>
+ <meta content="text/html; charset=UTF-8" http-equiv="Content-Type" />
+ </head>
+ <body>
+ <h1>Congratz, <%= @user.email %></h1>
+ <p>
+ You have successfully activated your example.com account,
+ your username is: <%= @user.email %>.<br/>
+ </p>
+ <p>
+ To login to the site, just follow this link: <%= @url %>.
+ </p>
+ <p>Thanks for joining and have a great day!</p>
+ </body>
+</html>
9 app/views/my_mailer/activation_success_email.text.erb
@@ -0,0 +1,9 @@
+Congratz, <%= @user.email %>
+===============================================
+
+You have successfully activated your example.com account,
+your username is: <%= @user.email %>.
+
+To login to the site, just follow this link: <%= @url %>.
+
+Thanks for joining and have a great day!
16 app/views/my_mailer/reset_password_email.html.erb
@@ -0,0 +1,16 @@
+<!DOCTYPE html>
+<html>
+ <head>
+ <meta content="text/html; charset=UTF-8" http-equiv="Content-Type" />
+ </head>
+ <body>
+ <h1>Hello, <%= @user.email %></h1>
+ <p>
+ You have requested to reset your password.
+ </p>
+ <p>
+ To choose a new password, just follow this link: <%= @url %>.
+ </p>
+ <p>Have a great day!</p>
+ </body>
+</html>
8 app/views/my_mailer/reset_password_email.text.erb
@@ -0,0 +1,8 @@
+Hello, <%= @user.email %>
+===============================================
+
+You have requested to reset your password.
+
+To choose a new password, just follow this link: <%= @url %>.
+
+Have a great day!
30 app/views/password_resets/_form.html.erb
@@ -0,0 +1,30 @@
+<%= form_for @user, :url => password_reset_path(@user), :html => {:method => :put} do |f| %>
+ <% if @user.errors.any? %>
+ <div id="error_explanation">
+ <h2><%= pluralize(@user.errors.count, "error") %> prohibited this user from being saved:</h2>
+
+ <ul>
+ <% @user.errors.full_messages.each do |msg| %>
+ <li><%= msg %></li>
+ <% end %>
+ </ul>
+ </div>
+ <% end %>
+
+ <div class="field">
+ <%= f.label :email %><br />
+ <%= @user.email %>
+ </div>
+ <div class="field">
+ <%= f.label :password %><br />
+ <%= f.password_field :password %>
+ </div>
+ <div class="field">
+ <%= f.label :password_confirmation %><br />
+ <%= f.password_field :password_confirmation %>
+ <%= hidden_field_tag :code, @code %>
+ </div>
+ <div class="actions">
+ <%= f.submit %>
+ </div>
+<% end %>
5 app/views/password_resets/edit.html.erb
@@ -0,0 +1,5 @@
+<h1>Reset Password</h1>
+
+<%= render 'form' %>
+
+<%= link_to 'Back', users_path %>
20 app/views/user_mailer/password_reset_instructions.html.erb
@@ -0,0 +1,20 @@
+<!DOCTYPE html>
+<html>
+ <head>
+ <meta content="text/html; charset=UTF-8" http-equiv="Content-Type" />
+ </head>
+ <body>
+ <p>
+ A request to reset your password has been made.<br/>
+ If you did not make this request, simply ignore this email.<br/>
+ If you did make this request just click the link below:<br/>
+ </p>
+ <p>
+ <%= @edit_password_reset_url %>.
+ </p>
+ <p>
+ If the above URL does not work try copying and pasting it into your browser.<br/>
+ If you continue to have problem please feel free to contact us.<br/>
+ </p>
+ </body>
+</html>
8 app/views/user_mailer/password_reset_instructions.text.erb
@@ -0,0 +1,8 @@
+A request to reset your password has been made.
+If you did not make this request, simply ignore this email.
+If you did make this request just click the link below:
+
+<%= @edit_password_reset_url %>
+
+If the above URL does not work try copying and pasting it into your browser.
+If you continue to have problem please feel free to contact us.
6 app/views/user_sessions/_forgot_password_form.html.erb
@@ -0,0 +1,6 @@
+<%= form_tag password_resets_path, :method => :post do %>
+ <div class="field">
+ <%= label_tag :email %><br />
+ <%= text_field_tag :email %> <%= submit_tag "Reset my password!" %>
+ </div>
+<% end %>
17 app/views/user_sessions/_form.html.erb
@@ -0,0 +1,17 @@
+<%= form_tag user_sessions_path, :method => :post do %>
+ <div class="field">
+ <%= label_tag :email %><br />
+ <%= text_field_tag :email %>
+ </div>
+ <div class="field">
+ <%= label_tag :password %><br />
+ <%= password_field_tag :password %>
+ </div>
+ <div class="actions">
+ <%= submit_tag "Login" %>
+ </div>
+ <div>
+ <%= label_tag "keep me logged in" %><br />
+ <%= check_box_tag :remember %>
+ </div>
+<% end %>
2 app/views/user_sessions/create.html.erb
@@ -0,0 +1,2 @@
+<h1>UserSessions#create</h1>
+<p>Find me in app/views/user_sessions/create.html.erb</p>
2 app/views/user_sessions/destroy.html.erb
@@ -0,0 +1,2 @@
+<h1>UserSessions#destroy</h1>
+<p>Find me in app/views/user_sessions/destroy.html.erb</p>
6 app/views/user_sessions/edit.html.erb
@@ -0,0 +1,6 @@
+<h1>Editing user_session</h1>
+
+<%= render 'form' %>
+
+<%= link_to 'Show', @user_session %> |
+<%= link_to 'Back', user_sessions_path %>
9 app/views/user_sessions/new.html.erb
@@ -0,0 +1,9 @@
+<h1>Login</h1>
+<p id="notice"><%= notice %></p>
+<p id="alert"><%= alert %></p>
+<%= render 'form' %>
+
+<h1>Forgot Password?</h1>
+<%= render 'forgot_password_form' %>
+
+<%= link_to 'Back', user_sessions_path %>
29 app/views/users/_form.html.erb
@@ -0,0 +1,29 @@
+<%= form_for(@user) do |f| %>
+ <% if @user.errors.any? %>
+ <div id="error_explanation">
+ <h2><%= pluralize(@user.errors.count, "error") %> prohibited this user from being saved:</h2>
+
+ <ul>
+ <% @user.errors.full_messages.each do |msg| %>
+ <li><%= msg %></li>
+ <% end %>
+ </ul>
+ </div>
+ <% end %>
+
+ <div class="field">
+ <%= f.label :email %><br />
+ <%= f.text_field :email %>
+ </div>
+ <div class="field">
+ <%= f.label :password %><br />
+ <%= f.password_field :password %>
+ </div>
+ <div class="field">
+ <%= f.label :password_confirmation %><br />
+ <%= f.password_field :password_confirmation %>
+ </div>
+ <div class="actions">
+ <%= f.submit %>
+ </div>
+<% end %>
6 app/views/users/edit.html.erb
@@ -0,0 +1,6 @@
+<h1>Editing user</h1>
+
+<%= render 'form' %>
+
+<%= link_to 'Show', @user %> |
+<%= link_to 'Back', users_path %>
24 app/views/users/index.html.erb
@@ -0,0 +1,24 @@
+<h1>Listing users</h1>
+<p id="notice"><%= notice %></p>
+<p id="alert"><%= alert %></p>
+<table>
+ <tr>
+ <th>Email</th>
+ <th></th>
+ <th></th>
+ <th></th>
+ </tr>
+
+<% @users.each do |user| %>
+ <tr>
+ <td><%= user.email %></td>
+ <td><%= link_to 'Show', user %></td>
+ <td><%= link_to 'Edit', edit_user_path(user) %></td>
+ <td><%= link_to 'Destroy', user, :confirm => 'Are you sure?', :method => :delete %></td>
+ </tr>
+<% end %>
+</table>
+
+<br />
+
+<%= link_to 'New User', new_user_path %>
5 app/views/users/new.html.erb
@@ -0,0 +1,5 @@
+<h1>New user</h1>
+
+<%= render 'form' %>
+
+<%= link_to 'Back', users_path %>
25 app/views/users/show.html.erb
@@ -0,0 +1,25 @@
+<p id="notice"><%= notice %></p>
+
+<p>
+ <b>Email:</b>
+ <%= @user.email %>
+</p>
+
+<p>
+ <b>Crypted password:</b>
+ <%= @user.crypted_password %>
+</p>
+
+<p>
+ <b>Password salt:</b>
+ <%= @user.password_salt %>
+</p>
+
+<p>
+ <b>Persistence token:</b>
+ <%= @user.persistence_token %>
+</p>
+
+
+<%= link_to 'Edit', edit_user_path(@user) %> |
+<%= link_to 'Back', users_path %>
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 Collaboration::Application
44 config/application.rb
@@ -0,0 +1,44 @@
+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 Collaboration
+ 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.
+
+ # 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]
+
+ config.sorcery.submodules = [:user_activation, :remember_me, :password_reset, :session_timeout]
+ end
+end
13 config/boot.rb
@@ -0,0 +1,13 @@
+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)
39 config/database.yml
@@ -0,0 +1,39 @@
+# MySQL. Versions 4.1 and 5.0 are recommended.
+#
+# Install the MySQL driver:
+# gem install mysql2
+#
+# And be sure to use new-style password hashing:
+# http://dev.mysql.com/doc/refman/5.0/en/old-client.html
+development:
+ adapter: mysql2
+ encoding: utf8
+ reconnect: false
+ database: collaboration_development
+ pool: 5
+ username: root
+ password:
+ host: localhost
+
+# Warning: The database defined as "test" will be erased and
+# re-generated from your development database when you run "rake".
+# Do not set this db to the same as development or production.
+test:
+ adapter: mysql2
+ encoding: utf8
+ reconnect: false
+ database: collaboration_test
+ pool: 5
+ username: root
+ password:
+ host: localhost
+
+production:
+ adapter: mysql2
+ encoding: utf8
+ reconnect: false
+ database: collaboration_production
+ pool: 5
+ username: root
+ password:
+ host: localhost
5 config/environment.rb
@@ -0,0 +1,5 @@
+# Load the rails application
+require File.expand_path('../application', __FILE__)
+
+# Initialize the rails application
+Collaboration::Application.initialize!
36 config/environments/development.rb
@@ -0,0 +1,36 @@
+Collaboration::Application.configure do
+ # Settings specified here will take precedence over those in config/application.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
+
+ # Log error messages when you accidentally call methods on nil.
+ config.whiny_nils = true
+
+ # 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
+
+ # Mailer options
+ config.action_mailer.perform_deliveries = true
+ config.action_mailer.raise_delivery_errors = true
+ config.action_mailer.delivery_method = :smtp
+ config.action_mailer.smtp_settings = {
+ :address => "smtp.gmail.com",
+ :port => 587,
+ :domain => 'example.com',
+ :user_name => 'nbenari',
+ :password => 'secret',
+ :authentication => 'plain',
+ :enable_starttls_auto => true }
+
+ # Print deprecation notices to the Rails logger
+ config.active_support.deprecation = :log
+
+ # Only use best-standards-support built into browsers
+ config.action_dispatch.best_standards_support = :builtin
+end
+
49 config/environments/production.rb
@@ -0,0 +1,49 @@
+Collaboration::Application.configure do
+ # Settings specified here will take precedence over those in config/application.rb
+
+ # The production environment is meant for finished, "live" apps.
+ # Code is not reloaded between requests
+ config.cache_classes = true
+
+ # Full error reports are disabled and caching is turned on
+ config.consider_all_requests_local = false
+ config.action_controller.perform_caching = true
+
+ # Specifies the header that your server uses for sending files
+ config.action_dispatch.x_sendfile_header = "X-Sendfile"
+
+ # For nginx:
+ # config.action_dispatch.x_sendfile_header = 'X-Accel-Redirect'
+
+ # If you have no front-end server that supports something like X-Sendfile,
+ # just comment this out and Rails will serve the files
+
+ # 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
35 config/environments/test.rb
@@ -0,0 +1,35 @@
+Collaboration::Application.configure do
+ # Settings specified here will take precedence over those in config/application.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
+
+ # Log error messages when you accidentally call methods on nil.
+ config.whiny_nils = true
+
+ # Show full error reports and disable caching
+ config.consider_all_requests_local = true
+ config.action_controller.perform_caching = false
+
+ # Raise exceptions instead of rendering exception templates
+ config.action_dispatch.show_exceptions = false
+
+ # 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
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!
10 config/initializers/inflections.rb
@@ -0,0 +1,10 @@
+# Be sure to restart your server when you modify this file.
+
+# Add new inflection rules using the following format
+# (all these examples are active by default):
+# ActiveSupport::Inflector.inflections do |inflect|
+# inflect.plural /^(ox)$/i, '\1en'
+# inflect.singular /^(ox)en/i, '\1'
+# inflect.irregular 'person', 'people'
+# inflect.uncountable %w( fish sheep )
+# end
5 config/initializers/mime_types.rb
@@ -0,0 +1,5 @@
+# Be sure to restart your server when you modify this file.
+
+# Add new mime types for use in respond_to blocks:
+# Mime::Type.register "text/richtext", :rtf
+# Mime::Type.register_alias "text/html", :iphone
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.
+Collaboration::Application.config.secret_token = '71c3cda60b08f02cfb9db858ed020470d2e9c9bd4c4342b36672486064ba12ad208624a6c26064079c5d646e4972640dd8d0fb27a95af4c3bf74e8c73cd2e1a0'
8 config/initializers/session_store.rb
@@ -0,0 +1,8 @@
+# Be sure to restart your server when you modify this file.
+
+Collaboration::Application.config.session_store :cookie_store, :key => '_collaboration_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 "rails generate session_migration")
+# Collaboration::Application.config.session_store :active_record_store
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"
72 config/routes.rb
@@ -0,0 +1,72 @@
+Collaboration::Application.routes.draw do
+ root :to => 'users#index'
+
+ resources :users do
+ collection do
+ get :activate
+ end
+ end
+
+ resources :user_sessions
+ resources :password_resets
+
+ match 'login' => 'user_sessions#new', :as => :login
+ match 'logout' => 'user_sessions#destroy', :as => :logout
+
+ # The priority is based upon order of creation:
+ # first created -> highest priority.
+
+ # Sample of regular route:
+ # match 'products/:id' => 'catalog#view'
+ # Keep in mind you can assign values other than :controller and :action
+
+ # Sample of named route:
+ # 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):
+ # resources :products
+
+ # Sample resource route with options:
+ # resources :products do
+ # member do
+ # get 'short'
+ # post 'toggle'
+ # end
+ #
+ # collection do
+ # get 'sold'
+ # end
+ # end
+
+ # Sample resource route with sub-resources:
+ # resources :products do
+ # resources :comments, :sales
+ # resource :seller
+ # end
+
+ # Sample resource route with more complex sub-resources
+ # resources :products do
+ # resources :comments
+ # resources :sales do
+ # get 'recent', :on => :collection
+ # end
+ # end
+
+ # Sample resource route within a namespace:
+ # 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 "root"
+ # just remember to delete public/index.html.
+ # root :to => "welcome#index"
+
+ # See how all your routes lay out with "rake routes"
+
+ # 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
17 db/migrate/20101210151424_create_users.rb
@@ -0,0 +1,17 @@
+class CreateUsers < ActiveRecord::Migration
+ def self.up
+ create_table :users do |t|
+ t.string :email, :null => false
+ t.string :crypted_password, :null => false
+ t.string :salt, :null => false
+
+ t.timestamps
+ end
+
+ add_index :users, :email
+ end
+
+ def self.down
+ drop_table :users
+ end
+end
15 db/migrate/20101224223622_add_activation_to_users.rb
@@ -0,0 +1,15 @@
+class AddActivationToUsers < ActiveRecord::Migration
+ def self.up
+ add_column :users, :activation_state, :string, :default => nil
+ add_column :users, :activation_code, :string, :default => nil
+
+ add_index :users, :activation_code
+ end
+
+ def self.down
+ remove_index :users, :activation_code
+
+ remove_column :users, :activation_code
+ remove_column :users, :activation_state
+ end
+end
15 db/migrate/20101224223623_add_remember_me_token_to_users.rb
@@ -0,0 +1,15 @@
+class AddRememberMeTokenToUsers < ActiveRecord::Migration
+ def self.up
+ add_column :users, :remember_me_token, :string, :default => nil
+ add_column :users, :remember_me_token_expires_at, :datetime, :default => nil
+
+ add_index :users, :remember_me_token
+ end
+
+ def self.down
+ remove_index :users, :remember_me_token
+
+ remove_column :users, :remember_me_token_expires_at
+ remove_column :users, :remember_me_token
+ end
+end
9 db/migrate/20101224223624_add_password_reset_to_users.rb
@@ -0,0 +1,9 @@
+class AddPasswordResetToUsers < ActiveRecord::Migration
+ def self.up
+ add_column :users, :reset_password_code, :string, :default => nil
+ end
+
+ def self.down
+ remove_column :users, :reset_password_code
+ end
+end
32 db/schema.rb
@@ -0,0 +1,32 @@
+# 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
+# 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 => 20101224223624) do
+
+ create_table "users", :force => true do |t|
+ t.string "email", :null => false
+ t.string "crypted_password", :null => false
+ t.string "salt", :null => false
+ t.datetime "created_at"
+ t.datetime "updated_at"
+ t.string "activation_state"
+ t.string "activation_code"
+ t.string "remember_me_token"
+ t.datetime "remember_me_token_expires_at"
+ t.string "reset_password_code"
+ end
+
+ add_index "users", ["activation_code"], :name => "index_users_on_activation_code"
+ add_index "users", ["email"], :name => "index_users_on_email"
+ add_index "users", ["remember_me_token"], :name => "index_users_on_remember_me_token"
+
+end
7 db/seeds.rb
@@ -0,0 +1,7 @@
+# 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)
2 doc/README_FOR_APP
@@ -0,0 +1,2 @@
+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.
0 lib/tasks/.gitkeep
No changes.
26 public/404.html
@@ -0,0 +1,26 @@
+<!DOCTYPE html>
+<html>
+<head>
+ <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>
+</head>
+
+<body>
+ <!-- This file lives in public/404.html -->
+ <div class="dialog">
+ <h1>The page you were looking for doesn't exist.</h1>
+ <p>You may have mistyped the address or the page may have moved.</p>
+ </div>
+</body>
+</html>
26 public/422.html
@@ -0,0 +1,26 @@
+<!DOCTYPE html>
+<html>
+<head>
+ <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>
+</head>
+
+<body>
+ <!-- This file lives in public/422.html -->
+ <div class="dialog">
+ <h1>The change you wanted was rejected.</h1>
+ <p>Maybe you tried to change something you didn't have access to.</p>
+ </div>
+</body>
+</html>
26 public/500.html
@@ -0,0 +1,26 @@
+<!DOCTYPE html>
+<html>
+<head>
+ <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>
+</head>
+
+<body>
+ <!-- This file lives in public/500.html -->
+ <div class="dialog">
+ <h1>We're sorry, but something went wrong.</h1>
+ <p>We've been notified about this issue and we'll take a look at it shortly.</p>
+ </div>
+</body>
+</html>
0 public/favicon.ico
No changes.
BIN public/images/rails.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
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
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) {
+ return this.update.firstChild.childNodes[index];
+ },
+
+ getCurrentEntry: function() {
+ return this.getEntry(this.index);
+ },
+
+ selectEntry: function() {
+ this.active = false;
+ this.updateElement(this.getCurrentEntry());
+ },
+
+ updateElement: function(selectedElement) {
+ if (this.options.updateElement) {
+ this.options.updateElement(selectedElement);
+ return;
+ }
+ var value = '';
+ if (this.options.select) {
+ var nodes = $(selectedElement).select('.' + this.options.select) || [];
+ if(nodes.length>0) value = Element.collectTextNodes(nodes[0], this.options.select);
+ } else
+ value = Element.collectTextNodesIgnoreClass(selectedElement, 'informal');
+
+ var bounds = this.getTokenBounds();
+ if (bounds[0] != -1) {
+ var newValue = this.element.value.substr(0, bounds[0]);
+ var whitespace = this.element.value.substr(bounds[0]).match(/^\s+/);
+ if (whitespace)
+ newValue += whitespace[0];
+ this.element.value = newValue + value + this.element.value.substr(bounds[1]);
+ } else {
+ this.element.value = value;
+ }
+ this.oldElementValue = this.element.value;
+ this.element.focus();
+
+ if (this.options.afterUpdateElement)
+ this.options.afterUpdateElement(this.element, selectedElement);
+ },
+
+ updateChoices: function(choices) {
+ if(!this.changed && this.hasFocus) {
+ this.update.innerHTML = choices;
+ Element.cleanWhitespace(this.update);
+ Element.cleanWhitespace(this.update.down());
+
+ if(this.update.firstChild && this.update.down().childNodes) {
+ this.entryCount =
+ this.update.down().childNodes.length;
+ for (var i = 0; i < this.entryCount; i++) {
+ var entry = this.getEntry(i);
+ entry.autocompleteIndex = i;
+ this.addObservers(entry);
+ }
+ } else {
+ this.entryCount = 0;
+ }
+
+ this.stopIndicator();
+ this.index = 0;
+
+ if(this.entryCount==1 && this.options.autoSelect) {
+ this.selectEntry();
+ this.hide();
+ } else {
+ this.render();
+ }
+ }
+ },
+
+ addObservers: function(element) {
+ Event.observe(element, "mouseover", this.onHover.bindAsEventListener(this));
+ Event.observe(element, "click", this.onClick.bindAsEventListener(this));
+ },
+
+ onObserverEvent: function() {
+ this.changed = false;
+ this.tokenBounds = null;
+ if(this.getToken().length>=this.options.minChars) {
+ this.getUpdatedChoices();
+ } else {
+ this.active = false;
+ this.hide();
+ }
+ this.oldElementValue = this.element.value;
+ },
+
+ getToken: function() {
+ var bounds = this.getTokenBounds();
+ return this.element.value.substring(bounds[0], bounds[1]).strip();
+ },
+
+ getTokenBounds: function() {
+ if (null != this.tokenBounds) return this.tokenBounds;
+ var value = this.element.value;
+ if (value.strip().empty()) return [-1, 0];
+ var diff = arguments.callee.getFirstDifferencePos(value, this.oldElementValue);
+ var offset = (diff == this.oldElementValue.length ? 1 : 0);
+ var prevTokenPos = -1, nextTokenPos = value.length;
+ var tp;
+ for (var index = 0, l = this.options.tokens.length; index < l; ++index) {
+ tp = value.lastIndexOf(this.options.tokens[index], diff + offset - 1);
+ if (tp > prevTokenPos) prevTokenPos = tp;
+ tp = value.indexOf(this.options.tokens[index], diff + offset);
+ if (-1 != tp && tp < nextTokenPos) nextTokenPos = tp;
+ }
+ return (this.tokenBounds = [prevTokenPos + 1, nextTokenPos]);
+ }
+});
+
+Autocompleter.Base.prototype.getTokenBounds.getFirstDifferencePos = function(newS, oldS) {
+ var boundary = Math.min(newS.length, oldS.length);
+ for (var index = 0; index < boundary; ++index)
+ if (newS[index] != oldS[index])
+ return index;
+ return boundary;
+};
+
+Ajax.Autocompleter = Class.create(Autocompleter.Base, {
+ initialize: function(element, update, url, options) {
+ this.baseInitialize(element, update, options);
+ this.options.asynchronous = true;
+ this.options.onComplete = this.onComplete.bind(this);
+ this.options.defaultParams = this.options.parameters || null;
+ this.url = url;
+ },
+
+ getUpdatedChoices: function() {
+ this.startIndicator();
+
+ var entry = encodeURIComponent(this.options.paramName) + '=' +
+ encodeURIComponent(this.getToken());
+
+ this.options.parameters = this.options.callback ?
+ this.options.callback(this.element, entry) : entry;
+
+ if(this.options.defaultParams)
+ this.options.parameters += '&' + this.options.defaultParams;
+
+ new Ajax.Request(this.url, this.options);
+ },
+
+ onComplete: function(request) {
+ this.updateChoices(request.responseText);
+ }
+});
+
+// The local array autocompleter. Used when you'd prefer to
+// inject an array of autocompletion options into the page, rather
+// than sending out Ajax queries, which can be quite slow sometimes.
+//
+// The constructor takes four parameters. The first two are, as usual,
+// the id of the monitored textbox, and id of the autocompletion menu.
+// The third is the array you want to autocomplete from, and the fourth
+// is the options block.
+//
+// Extra local autocompletion options:
+// - choices - How many autocompletion choices to offer
+//
+// - partialSearch - If false, the autocompleter will match entered
+// text only at the beginning of strings in the
+// autocomplete array. Defaults to true, which will
+// match text at the beginning of any *word* in the
+// strings in the autocomplete array. If you want to
+// search anywhere in the string, additionally set
+// the option fullSearch to true (default: off).
+//
+// - fullSsearch - Search anywhere in autocomplete array strings.
+//
+// - partialChars - How many characters to enter before triggering
+// a partial match (unlike minChars, which defines
+// how many characters are required to do any match
+// at all). Defaults to 2.
+//
+// - ignoreCase - Whether to ignore case when autocompleting.
+// Defaults to true.
+//
+// It's possible to pass in a custom function as the 'selector'
+// option, if you prefer to write your own autocompletion logic.
+// In that case, the other options above will not apply unless
+// you support them.
+
+Autocompleter.Local = Class.create(Autocompleter.Base, {
+ initialize: function(element, update, array, options) {
+ this.baseInitialize(element, update, options);
+ this.options.array = array;
+ },
+
+ getUpdatedChoices: function() {
+ this.updateChoices(this.options.selector(this));
+ },
+
+ setOptions: function(options) {
+ this.options = Object.extend({
+ choices: 10,
+ partialSearch: true,
+ partialChars: 2,
+ ignoreCase: true,
+ fullSearch: false,
+ selector: function(instance) {
+ var ret = []; // Beginning matches
+ var partial = []; // Inside matches
+ var entry = instance.getToken();
+ var count = 0;
+
+ for (var i = 0; i < instance.options.array.length &&
+ ret.length < instance.options.choices ; i++) {
+
+ var elem = instance.options.array[i];
+ var foundPos = instance.options.ignoreCase ?
+ elem.toLowerCase().indexOf(entry.toLowerCase()) :
+ elem.indexOf(entry);
+
+ while (foundPos != -1) {
+ if (foundPos == 0 && elem.length != entry.length) {
+ ret.push("<li><strong>" + elem.substr(0, entry.length) + "</strong>" +
+ elem.substr(entry.length) + "</li>");
+ break;
+ } else if (entry.length >= instance.options.partialChars &&
+ instance.options.partialSearch && foundPos != -1) {
+ if (instance.options.fullSearch || /\s/.test(elem.substr(foundPos-1,1))) {
+ partial.push("<li>" + elem.substr(0, foundPos) + "<strong>" +
+ elem.substr(foundPos, entry.length) + "</strong>" + elem.substr(
+ foundPos + entry.length) + "</li>");
+ break;
+ }
+ }
+
+ foundPos = instance.options.ignoreCase ?
+ elem.toLowerCase().indexOf(entry.toLowerCase(), foundPos + 1) :
+ elem.indexOf(entry, foundPos + 1);
+
+ }
+ }
+ if (partial.length)
+ ret = ret.concat(partial.slice(0, instance.