quo_vadis 0.0.1 → 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (72) hide show
  1. data/.gitignore +2 -0
  2. data/Gemfile.lock +114 -0
  3. data/README.md +79 -0
  4. data/Rakefile +11 -0
  5. data/app/controllers/controller_mixin.rb +20 -0
  6. data/app/controllers/quo_vadis/sessions_controller.rb +36 -0
  7. data/app/models/model_mixin.rb +44 -0
  8. data/config/initializers/quo_vadis.rb +50 -0
  9. data/config/locales/quo_vadis.en.yml +7 -0
  10. data/config/routes.rb +7 -0
  11. data/lib/generators/quo_vadis/install_generator.rb +28 -0
  12. data/lib/generators/quo_vadis/templates/migration.rb +11 -0
  13. data/lib/quo_vadis/engine.rb +15 -0
  14. data/lib/quo_vadis/version.rb +1 -1
  15. data/lib/quo_vadis.rb +63 -1
  16. data/quo_vadis.gemspec +8 -1
  17. data/test/dummy/.gitignore +1 -0
  18. data/test/dummy/app/controllers/application_controller.rb +3 -0
  19. data/test/dummy/app/controllers/articles_controller.rb +11 -0
  20. data/test/dummy/app/helpers/application_helper.rb +2 -0
  21. data/test/dummy/app/helpers/articles_helper.rb +2 -0
  22. data/test/dummy/app/models/article.rb +2 -0
  23. data/test/dummy/app/models/user.rb +3 -0
  24. data/test/dummy/app/views/articles/index.html.erb +1 -0
  25. data/test/dummy/app/views/articles/new.html.erb +1 -0
  26. data/test/dummy/app/views/layouts/application.html.erb +27 -0
  27. data/test/dummy/app/views/sessions/new.html.erb +15 -0
  28. data/test/dummy/config/application.rb +21 -0
  29. data/test/dummy/config/boot.rb +10 -0
  30. data/test/dummy/config/database.yml +22 -0
  31. data/test/dummy/config/environment.rb +5 -0
  32. data/test/dummy/config/environments/development.rb +26 -0
  33. data/test/dummy/config/environments/production.rb +49 -0
  34. data/test/dummy/config/environments/test.rb +35 -0
  35. data/test/dummy/config/initializers/backtrace_silencers.rb +7 -0
  36. data/test/dummy/config/initializers/inflections.rb +10 -0
  37. data/test/dummy/config/initializers/mime_types.rb +5 -0
  38. data/test/dummy/config/initializers/secret_token.rb +7 -0
  39. data/test/dummy/config/initializers/session_store.rb +8 -0
  40. data/test/dummy/config/locales/en.yml +5 -0
  41. data/test/dummy/config/routes.rb +4 -0
  42. data/test/dummy/config.ru +4 -0
  43. data/test/dummy/db/migrate/20110124125037_create_users.rb +13 -0
  44. data/test/dummy/db/migrate/20110124125216_add_authentication_to_users.rb +11 -0
  45. data/test/dummy/db/migrate/20110124131535_create_articles.rb +14 -0
  46. data/test/dummy/public/404.html +26 -0
  47. data/test/dummy/public/422.html +26 -0
  48. data/test/dummy/public/500.html +26 -0
  49. data/test/dummy/public/favicon.ico +0 -0
  50. data/test/dummy/public/javascripts/application.js +2 -0
  51. data/test/dummy/public/javascripts/controls.js +965 -0
  52. data/test/dummy/public/javascripts/dragdrop.js +974 -0
  53. data/test/dummy/public/javascripts/effects.js +1123 -0
  54. data/test/dummy/public/javascripts/prototype.js +6001 -0
  55. data/test/dummy/public/javascripts/rails.js +175 -0
  56. data/test/dummy/public/stylesheets/.gitkeep +0 -0
  57. data/test/dummy/script/rails +6 -0
  58. data/test/dummy/tmp/capybara/capybara-20110124133149.html +27 -0
  59. data/test/dummy/tmp/capybara/capybara-20110124133340.html +27 -0
  60. data/test/dummy/tmp/capybara/capybara-20110124134001.html +27 -0
  61. data/test/dummy/tmp/capybara/capybara-20110124134214.html +27 -0
  62. data/test/dummy/tmp/capybara/capybara-20110124135435.html +39 -0
  63. data/test/integration/authenticate_test.rb +39 -0
  64. data/test/integration/config_test.rb +96 -0
  65. data/test/integration/helper_test.rb +18 -0
  66. data/test/integration/navigation_test.rb +7 -0
  67. data/test/integration/sign_in_test.rb +28 -0
  68. data/test/integration/sign_out_test.rb +20 -0
  69. data/test/quo_vadis_test.rb +7 -0
  70. data/test/support/integration_case.rb +5 -0
  71. data/test/test_helper.rb +46 -0
  72. metadata +202 -8
data/.gitignore CHANGED
@@ -1,3 +1,5 @@
1
1
  pkg/*
2
2
  *.gem
3
3
  .bundle
4
+ test/dummy/log/*
5
+ test/dummy/tmp/*
data/Gemfile.lock ADDED
@@ -0,0 +1,114 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ quo_vadis (1.0.0)
5
+ bcrypt-ruby (~> 2.1.4)
6
+ rails (~> 3.0)
7
+
8
+ GEM
9
+ remote: http://rubygems.org/
10
+ specs:
11
+ abstract (1.0.0)
12
+ actionmailer (3.0.3)
13
+ actionpack (= 3.0.3)
14
+ mail (~> 2.2.9)
15
+ actionpack (3.0.3)
16
+ activemodel (= 3.0.3)
17
+ activesupport (= 3.0.3)
18
+ builder (~> 2.1.2)
19
+ erubis (~> 2.6.6)
20
+ i18n (~> 0.4)
21
+ rack (~> 1.2.1)
22
+ rack-mount (~> 0.6.13)
23
+ rack-test (~> 0.5.6)
24
+ tzinfo (~> 0.3.23)
25
+ activemodel (3.0.3)
26
+ activesupport (= 3.0.3)
27
+ builder (~> 2.1.2)
28
+ i18n (~> 0.4)
29
+ activerecord (3.0.3)
30
+ activemodel (= 3.0.3)
31
+ activesupport (= 3.0.3)
32
+ arel (~> 2.0.2)
33
+ tzinfo (~> 0.3.23)
34
+ activeresource (3.0.3)
35
+ activemodel (= 3.0.3)
36
+ activesupport (= 3.0.3)
37
+ activesupport (3.0.3)
38
+ arel (2.0.4)
39
+ bcrypt-ruby (2.1.4)
40
+ builder (2.1.2)
41
+ capybara (0.4.1.1)
42
+ celerity (>= 0.7.9)
43
+ culerity (>= 0.2.4)
44
+ mime-types (>= 1.16)
45
+ nokogiri (>= 1.3.3)
46
+ rack (>= 1.0.0)
47
+ rack-test (>= 0.5.4)
48
+ selenium-webdriver (>= 0.0.27)
49
+ xpath (~> 0.1.3)
50
+ celerity (0.8.7)
51
+ childprocess (0.1.6)
52
+ ffi (~> 0.6.3)
53
+ configuration (1.2.0)
54
+ culerity (0.2.15)
55
+ erubis (2.6.6)
56
+ abstract (>= 1.0.0)
57
+ ffi (0.6.3)
58
+ rake (>= 0.8.7)
59
+ i18n (0.4.1)
60
+ json_pure (1.5.0)
61
+ launchy (0.3.7)
62
+ configuration (>= 0.0.5)
63
+ rake (>= 0.8.1)
64
+ mail (2.2.10)
65
+ activesupport (>= 2.3.6)
66
+ i18n (~> 0.4.1)
67
+ mime-types (~> 1.16)
68
+ treetop (~> 1.4.8)
69
+ mime-types (1.16)
70
+ nokogiri (1.4.4)
71
+ polyglot (0.3.1)
72
+ rack (1.2.1)
73
+ rack-mount (0.6.13)
74
+ rack (>= 1.0.0)
75
+ rack-test (0.5.6)
76
+ rack (>= 1.0)
77
+ rails (3.0.3)
78
+ actionmailer (= 3.0.3)
79
+ actionpack (= 3.0.3)
80
+ activerecord (= 3.0.3)
81
+ activeresource (= 3.0.3)
82
+ activesupport (= 3.0.3)
83
+ bundler (~> 1.0)
84
+ railties (= 3.0.3)
85
+ railties (3.0.3)
86
+ actionpack (= 3.0.3)
87
+ activesupport (= 3.0.3)
88
+ rake (>= 0.8.7)
89
+ thor (~> 0.14.4)
90
+ rake (0.8.7)
91
+ rubyzip (0.9.4)
92
+ selenium-webdriver (0.1.2)
93
+ childprocess (~> 0.1.5)
94
+ ffi (~> 0.6.3)
95
+ json_pure
96
+ rubyzip
97
+ sqlite3-ruby (1.2.5)
98
+ thor (0.14.6)
99
+ treetop (1.4.8)
100
+ polyglot (>= 0.3.1)
101
+ tzinfo (0.3.23)
102
+ xpath (0.1.3)
103
+ nokogiri (~> 1.3)
104
+
105
+ PLATFORMS
106
+ ruby
107
+
108
+ DEPENDENCIES
109
+ bcrypt-ruby (~> 2.1.4)
110
+ capybara (>= 0.4.0)
111
+ launchy
112
+ quo_vadis!
113
+ rails (~> 3.0)
114
+ sqlite3-ruby
data/README.md ADDED
@@ -0,0 +1,79 @@
1
+ # Quo Vadis?
2
+
3
+ Quo Vadis adds simple username/password authentication to Rails 3 applications.
4
+
5
+ Features:
6
+
7
+ * Minimal effort to add authentication to your app: get up and running in 5 minutes.
8
+ * No surprises: it does what you expect.
9
+ * Easy to customise.
10
+ * Uses BCrypt to encrypt passwords.
11
+ * Sign in, sign out, authenticate actions.
12
+
13
+ Forthcoming features:
14
+
15
+ * Handle forgotten-details.
16
+ * Let you choose which model(s) to authenticate (currently `User`).
17
+ * Let you choose the identification field (currently `username`).
18
+ * Remember authenticated user across browser sessions.
19
+ * HTTP basic/digest authentication (probably).
20
+ * Generate (User) model plus migration if it doesn't exist.
21
+ * Detect presence of `has_secure_password` (see below) and adapt appropriately.
22
+
23
+ What it doesn't and won't do:
24
+
25
+ * Authorisation.
26
+ * Sign up; that's user management, not authentication.
27
+ * Work outside Rails 3.
28
+ * OpenID, OAuth, LDAP, CAS, etc.
29
+ * Separate identity from authentication services (cf OmniAuth).
30
+ * Allow you to have multiple models/scope signed in simultaneously (cf Devise).
31
+ * Offer so much flexibility that it takes more than 10 minutes to wrap your head around it (cf Devise, Authlogic).
32
+
33
+
34
+ ## Quick Start
35
+
36
+ Install and run the generator: add `gem 'quo_vadis'` to your Gemfile and run `rails generate quo_vadis:install`.
37
+
38
+ Edit and run the generated migration to add authentication columns: `rake db:migrate`. Note the migration (currently) assumes you already have a `User` model.
39
+
40
+ In your `User` model, add `authenticates`:
41
+
42
+ class User < ActiveRecord::Base
43
+ authenticates
44
+ end
45
+
46
+ Note Quo Vadis validates the presence of the password, but it's up to you to add any other validations you want.
47
+
48
+ Use `:authenticate` in a `before_filter` to protect your controllers' actions. For example:
49
+
50
+ class ArticleController < ActionController::Base
51
+ before_filter :authenticate, :except => [:index, :show]
52
+ end
53
+
54
+ Write the sign-in view. Your sign-in form must:
55
+
56
+ * be in `app/views/sessions/new.html.:format`
57
+ * post the parameters `:username` and `:password` to `sign_in_url`
58
+
59
+ In your layout, use `current_user` to retrieve the signed-in user, and `sign_in_path` and `sign_out_path` as appropriate.
60
+
61
+
62
+ ## Customisation
63
+
64
+ You can customise the flash messages in `config/locales/quo_vadis.en.yml`.
65
+
66
+ You can customise the sign-in and sign-out redirects in `config/initializers/quo_vadis.rb`; they both default to the root route. You can also hook into the sign-in and sign-out process if you need to run any other code.
67
+
68
+ If you want to add other session management type features, go right ahead: create a `SessionsController` as normal and carry on.
69
+
70
+
71
+ ## See also
72
+
73
+ * Rails 3 edge's [ActiveModel::SecurePassword](https://github.com/rails/rails/blob/master/activemodel/lib/active_model/secure_password.rb). It's `has_secure_password` class method is similar to Quo Vadis's `authenticates` class method.
74
+ * [RailsCast 250: Authentication from Scratch](http://railscasts.com/episodes/250-authentication-from-scratch).
75
+
76
+
77
+ ## What's up with the name?
78
+
79
+ Roman sentries used to challenge intruders with, "Halt! Who goes there?"; quo vadis is Latin for "Who goes there?". At least that's what my Latin teacher told us, but I was 8 years old then so I may not be remembering this entirely accurately.
data/Rakefile CHANGED
@@ -1,2 +1,13 @@
1
1
  require 'bundler'
2
2
  Bundler::GemHelper.install_tasks
3
+
4
+ require 'rake/testtask'
5
+
6
+ Rake::TestTask.new(:test) do |t|
7
+ t.libs << 'lib'
8
+ t.libs << 'test'
9
+ t.pattern = 'test/**/*_test.rb'
10
+ t.verbose = false
11
+ end
12
+
13
+ task :default => :test
@@ -0,0 +1,20 @@
1
+ module ControllerMixin
2
+ def self.included(base)
3
+ base.helper_method :current_user
4
+ end
5
+
6
+ private # TODO: does this mark them as private once mixed in?
7
+
8
+ def current_user=(user)
9
+ session[:current_user_id] = user ? user.id : nil
10
+ end
11
+
12
+ def current_user
13
+ @current_user ||= User.find(session[:current_user_id]) if session[:current_user_id]
14
+ end
15
+
16
+ def authenticate
17
+ session[:quo_vadis_original_url] = request.fullpath
18
+ redirect_to sign_in_url, :notice => t('quo_vadis.flash.before_sign_in') unless current_user
19
+ end
20
+ end
@@ -0,0 +1,36 @@
1
+ class QuoVadis::SessionsController < ApplicationController
2
+
3
+ # sign in
4
+ def new
5
+ render 'sessions/new'
6
+ end
7
+
8
+ # sign in
9
+ def create
10
+ if user = User.authenticate(params[:username], params[:password])
11
+ self.current_user = user
12
+ QuoVadis.signed_in_hook user, request
13
+ redirect_to QuoVadis.signed_in_url(user, original_url), :notice => t('quo_vadis.flash.after_sign_in')
14
+ else
15
+ QuoVadis.failed_sign_in_hook request
16
+ flash.now[:alert] = t('quo_vadis.flash.failed_sign_in')
17
+ render 'sessions/new'
18
+ end
19
+ end
20
+
21
+ # sign out
22
+ def destroy
23
+ QuoVadis.signed_out_hook current_user, request
24
+ self.current_user = nil
25
+ redirect_to QuoVadis.signed_out_url, :notice => t('quo_vadis.flash.sign_out')
26
+ end
27
+
28
+ private
29
+
30
+ def original_url
31
+ url = session[:quo_vadis_original_url]
32
+ session[:quo_vadis_original_url] = nil
33
+ url
34
+ end
35
+
36
+ end
@@ -0,0 +1,44 @@
1
+ require 'bcrypt'
2
+
3
+ module ModelMixin
4
+
5
+ def self.included(base)
6
+ base.send :extend, ClassMethods
7
+ end
8
+
9
+ module ClassMethods
10
+ def authenticates
11
+ send :include, InstanceMethodsOnActivation
12
+
13
+ attr_reader :password
14
+ attr_protected :password_digest
15
+
16
+ validates :username, :presence => true, :uniqueness => true
17
+ validates :password, :on => :create, :presence => true
18
+ validates :password_digest, :presence => true
19
+
20
+ instance_eval <<-END
21
+ def authenticate(username, plain_text_password)
22
+ user = where(:username => username).first
23
+ if user && user.has_matching_password?(plain_text_password)
24
+ user
25
+ else
26
+ nil
27
+ end
28
+ end
29
+ END
30
+ end
31
+ end
32
+
33
+ module InstanceMethodsOnActivation
34
+ def password=(plain_text_password)
35
+ @password = plain_text_password
36
+ self.password_digest = BCrypt::Password.create plain_text_password
37
+ end
38
+
39
+ def has_matching_password?(plain_text_password)
40
+ BCrypt::Password.new(password_digest) == plain_text_password
41
+ end
42
+ end
43
+
44
+ end
@@ -0,0 +1,50 @@
1
+ QuoVadis.configure do |config|
2
+
3
+ #
4
+ # Redirection URLs
5
+ #
6
+
7
+ # The URL to redirect the user to after s/he signs in.
8
+ # Use a proc if the URL depends on the user. E.g.:
9
+ #
10
+ # config.signed_in_url = Proc.new do |user|
11
+ # user.admin? ? :admin : :root
12
+ # end
13
+ #
14
+ # See also `:override_original_url`.
15
+ config.signed_in_url = :root
16
+
17
+ # Whether the `:signed_in_url` should override the URL the user was trying
18
+ # to reach when they were made to authenticate.
19
+ config.override_original_url = false
20
+
21
+ # The URL to redirect the user to after s/he signs out.
22
+ config.signed_out_url = :root
23
+
24
+
25
+ #
26
+ # Hooks
27
+ #
28
+
29
+ # Code to run when the user has signed in. E.g.:
30
+ #
31
+ # config.signed_in_hook = Proc.new do |user, request|
32
+ # user.increment! :sign_in_count # assuming this attribute exists
33
+ # end
34
+ config.signed_in_hook = nil
35
+
36
+ # Code to run when someone has tried but failed to sign in. E.g.:
37
+ #
38
+ # config.failed_sign_in_hook = Proc.new do |request|
39
+ # logger.info "Failed sign in from #{request.remote_ip}"
40
+ # end
41
+ config.failed_sign_in_hook = nil
42
+
43
+ # Code to run just before the user has signed out. E.g.:
44
+ #
45
+ # config.signed_out_hook = Proc.new do |user, request|
46
+ # session.reset
47
+ # end
48
+ config.signed_out_hook = nil
49
+
50
+ end
@@ -0,0 +1,7 @@
1
+ en:
2
+ quo_vadis:
3
+ flash:
4
+ before_sign_in: 'Please sign in first.'
5
+ after_sign_in: 'You have successfully signed in.'
6
+ failed_sign_in: 'Sorry, we did not recognise you.'
7
+ sign_out: 'You have successfully signed out.'
data/config/routes.rb ADDED
@@ -0,0 +1,7 @@
1
+ Rails.application.routes.draw do |map|
2
+ scope :module => 'quo_vadis' do
3
+ get 'sign-in' => 'sessions#new', :as => 'sign_in'
4
+ post 'sign-in' => 'sessions#create', :as => 'sign_in'
5
+ get 'sign-out' => 'sessions#destroy', :as => 'sign_out'
6
+ end
7
+ end
@@ -0,0 +1,28 @@
1
+ require 'rails/generators'
2
+ require 'rails/generators/migration'
3
+ require 'rails/generators/active_record/migration'
4
+
5
+ module QuoVadis
6
+ class InstallGenerator < Rails::Generators::Base
7
+ include Rails::Generators::Migration
8
+ extend ActiveRecord::Generators::Migration
9
+
10
+ source_root File.expand_path('../templates', __FILE__)
11
+
12
+ desc 'Copies an initializer, a locale file, and a migration to your application.'
13
+
14
+
15
+ def copy_locale_file
16
+ copy_file '../../../../config/locales/quo_vadis.en.yml', 'config/locales/quo_vadis.en.yml'
17
+ end
18
+
19
+ def copy_initializer_file
20
+ copy_file '../../../../config/initializers/quo_vadis.rb', 'config/initializers/quo_vadis.rb'
21
+ end
22
+
23
+ def create_migration_file
24
+ migration_template 'migration.rb', 'db/migrate/add_authentication_to_users.rb'
25
+ end
26
+
27
+ end
28
+ end
@@ -0,0 +1,11 @@
1
+ class AddAuthenticationToUsers < ActiveRecord::Migration
2
+ def self.up
3
+ add_column :users, :username, :string # for user identification
4
+ add_column :users, :password_digest, :string
5
+ end
6
+
7
+ def self.down
8
+ remove_column :users, :username
9
+ remove_column :users, :password_digest
10
+ end
11
+ end
@@ -0,0 +1,15 @@
1
+ module QuoVadis
2
+ class Engine < ::Rails::Engine
3
+ initializer 'quo_vadis.model' do |app|
4
+ ActiveSupport.on_load(:active_record) do
5
+ include ModelMixin
6
+ end
7
+ end
8
+
9
+ initializer 'quo_vadis.controller' do |app|
10
+ ActiveSupport.on_load(:action_controller) do
11
+ include ControllerMixin
12
+ end
13
+ end
14
+ end
15
+ end
@@ -1,3 +1,3 @@
1
1
  module QuoVadis
2
- VERSION = "0.0.1"
2
+ VERSION = '1.0.0'
3
3
  end
data/lib/quo_vadis.rb CHANGED
@@ -1,3 +1,65 @@
1
+ require 'quo_vadis/engine'
2
+
1
3
  module QuoVadis
2
- # Your code goes here...
4
+
5
+ #
6
+ # Redirection URLs
7
+ #
8
+
9
+ # The URL to redirect the user to after s/he signs in.
10
+ mattr_accessor :signed_in_url
11
+ @@signed_in_url = :root
12
+
13
+ # Whether the `:signed_in_url` should override the URL the user was trying
14
+ # to reach when they were made to authenticate.
15
+ mattr_accessor :override_original_url
16
+ @@override_original_url = false
17
+
18
+ def self.signed_in_url(user, original_url)
19
+ if original_url && !@@override_original_url
20
+ original_url
21
+ else
22
+ @@signed_in_url.respond_to?(:call) ? @@signed_in_url.call(user) : @@signed_in_url
23
+ end
24
+ end
25
+
26
+ # The URL to redirect the user to after s/he signs out.
27
+ mattr_accessor :signed_out_url
28
+ @@signed_in_url = :root
29
+
30
+
31
+ #
32
+ # Hooks
33
+ #
34
+
35
+ # Code to run when the user has signed in.
36
+ mattr_accessor :signed_in_hook
37
+ @@signed_in_hook = nil
38
+
39
+ def self.signed_in_hook(user, request)
40
+ @@signed_in_hook.call(user, request) if @@signed_in_hook
41
+ end
42
+
43
+ # Code to run when someone has tried but failed to sign in.
44
+ mattr_accessor :failed_sign_in_hook
45
+ @@failed_sign_in_hook = nil
46
+
47
+ def self.failed_sign_in_hook(request)
48
+ @@failed_sign_in_hook.call(request) if @@failed_sign_in_hook
49
+ end
50
+
51
+ # Code to run just before the user has signed out.
52
+ mattr_accessor :signed_out_hook
53
+ @@signed_out_hook = nil
54
+
55
+ def self.signed_out_hook(user, request)
56
+ @@signed_out_hook.call(user, request) if @@signed_out_hook
57
+ end
58
+
59
+
60
+ # Configure from the initializer.
61
+ def self.configure
62
+ yield self
63
+ end
64
+
3
65
  end
data/quo_vadis.gemspec CHANGED
@@ -9,7 +9,7 @@ Gem::Specification.new do |s|
9
9
  s.authors = ['Andy Stewart']
10
10
  s.email = ['boss@airbladesoftware.com']
11
11
  s.homepage = ''
12
- s.summary = %q{Simple authentication for Rails 3.}
12
+ s.summary = 'Simple authentication for Rails 3.'
13
13
  s.description = s.summary
14
14
 
15
15
  s.rubyforge_project = 'quo_vadis'
@@ -18,4 +18,11 @@ Gem::Specification.new do |s|
18
18
  s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
19
19
  s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
20
20
  s.require_paths = ['lib']
21
+
22
+ s.add_dependency 'rails', '~>3.0'
23
+ s.add_dependency 'bcrypt-ruby', '~>2.1.4'
24
+
25
+ s.add_development_dependency 'sqlite3-ruby'
26
+ s.add_development_dependency 'capybara', '>= 0.4.0'
27
+ s.add_development_dependency 'launchy'
21
28
  end
@@ -0,0 +1 @@
1
+ db/*.sqlite3
@@ -0,0 +1,3 @@
1
+ class ApplicationController < ActionController::Base
2
+ protect_from_forgery
3
+ end
@@ -0,0 +1,11 @@
1
+ class ArticlesController < ApplicationController
2
+ before_filter :authenticate, :except => [:index, :show]
3
+
4
+ def index
5
+ @articles = Article.all
6
+ end
7
+
8
+ def new
9
+ @article = Article.new
10
+ end
11
+ end
@@ -0,0 +1,2 @@
1
+ module ApplicationHelper
2
+ end
@@ -0,0 +1,2 @@
1
+ module ArticlesHelper
2
+ end
@@ -0,0 +1,2 @@
1
+ class Article < ActiveRecord::Base
2
+ end
@@ -0,0 +1,3 @@
1
+ class User < ActiveRecord::Base
2
+ authenticates
3
+ end
@@ -0,0 +1 @@
1
+ <h1>Articles</h1>
@@ -0,0 +1 @@
1
+ <h1>New Article</h1>
@@ -0,0 +1,27 @@
1
+ <!DOCTYPE html>
2
+ <html>
3
+ <head>
4
+ <title>Dummy</title>
5
+ <%= stylesheet_link_tag :all %>
6
+ <%= javascript_include_tag :defaults %>
7
+ <%= csrf_meta_tag %>
8
+ </head>
9
+ <body>
10
+
11
+ <div id='topnav'>
12
+ <% if current_user %>
13
+ You are signed in as <%= current_user.name %>.
14
+ <%= link_to 'Sign out', sign_out_path %>
15
+ <% else %>
16
+ <%= link_to 'Sign in', sign_in_path %>
17
+ <% end %>
18
+ </div>
19
+
20
+ <% flash.each do |key, value| %>
21
+ <div class='flash <%= key %>'><%= value %></div>
22
+ <% end %>
23
+
24
+ <%= yield %>
25
+
26
+ </body>
27
+ </html>
@@ -0,0 +1,15 @@
1
+ <h1>Sign in</h1>
2
+
3
+ <%= form_tag sign_in_path do %>
4
+ <p>
5
+ <%= label_tag :username %>
6
+ <%= text_field_tag :username %>
7
+ </p>
8
+ <p>
9
+ <%= label_tag :password %>
10
+ <%= password_field_tag :password %>
11
+ </p>
12
+ <p>
13
+ <%= submit_tag 'Sign in' %>
14
+ </p>
15
+ <% end %>
@@ -0,0 +1,21 @@
1
+ require File.expand_path('../boot', __FILE__)
2
+
3
+ require "active_model/railtie"
4
+ require "active_record/railtie"
5
+ require "action_controller/railtie"
6
+ require "action_view/railtie"
7
+ require "action_mailer/railtie"
8
+
9
+ Bundler.require
10
+ require 'quo_vadis'
11
+
12
+ module Dummy
13
+ class Application < Rails::Application
14
+ # Configure the default encoding used in templates for Ruby 1.9.
15
+ config.encoding = "utf-8"
16
+
17
+ # Configure sensitive parameters which will be filtered from the log file.
18
+ config.filter_parameters += [:password]
19
+ end
20
+ end
21
+
@@ -0,0 +1,10 @@
1
+ require 'rubygems'
2
+ gemfile = File.expand_path('../../../../Gemfile', __FILE__)
3
+
4
+ if File.exist?(gemfile)
5
+ ENV['BUNDLE_GEMFILE'] = gemfile
6
+ require 'bundler'
7
+ Bundler.setup
8
+ end
9
+
10
+ $:.unshift File.expand_path('../../../../lib', __FILE__)