double_auth_engine 0.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (94) hide show
  1. data/.gitignore +7 -0
  2. data/.rvmrc +1 -0
  3. data/Gemfile +9 -0
  4. data/Gemfile.lock +136 -0
  5. data/MIT-LICENSE +20 -0
  6. data/README.md +59 -0
  7. data/Rakefile +25 -0
  8. data/app/controllers/password_resets_controller.rb +3 -0
  9. data/app/controllers/user_sessions_controller.rb +3 -0
  10. data/app/controllers/users_controller.rb +3 -0
  11. data/app/mailers/notifier.rb +8 -0
  12. data/app/models/assignment.rb +3 -0
  13. data/app/models/role.rb +3 -0
  14. data/app/models/user.rb +3 -0
  15. data/app/models/user_session.rb +3 -0
  16. data/app/views/notifier/password_reset_instructions.text.erb +8 -0
  17. data/app/views/password_resets/edit.html.erb +5 -0
  18. data/app/views/password_resets/new.html.erb +5 -0
  19. data/app/views/user_sessions/new.html.erb +17 -0
  20. data/app/views/users/edit.html.erb +0 -0
  21. data/app/views/users/index.html.erb +0 -0
  22. data/app/views/users/new.html.erb +20 -0
  23. data/app/views/users/show.html.erb +2 -0
  24. data/config/routes.rb +11 -0
  25. data/double_auth_engine.gemspec +26 -0
  26. data/lib/double_auth_engine/controllers/application_controller_mixin.rb +42 -0
  27. data/lib/double_auth_engine/controllers/password_resets_controller_mixin.rb +49 -0
  28. data/lib/double_auth_engine/controllers/user_sessions_controller_mixin.rb +34 -0
  29. data/lib/double_auth_engine/controllers/users_controller_mixin.rb +63 -0
  30. data/lib/double_auth_engine/generators/double_auth_engine/install_generator.rb +48 -0
  31. data/lib/double_auth_engine/generators/double_auth_engine/templates/assignment_migration.rb +13 -0
  32. data/lib/double_auth_engine/generators/double_auth_engine/templates/authorization_rules.rb +19 -0
  33. data/lib/double_auth_engine/generators/double_auth_engine/templates/role_migration.rb +12 -0
  34. data/lib/double_auth_engine/generators/double_auth_engine/templates/setup_mail_initializer.rb +7 -0
  35. data/lib/double_auth_engine/generators/double_auth_engine/templates/user_migration.rb +28 -0
  36. data/lib/double_auth_engine/models/assignment_mixin.rb +10 -0
  37. data/lib/double_auth_engine/models/role_mixin.rb +10 -0
  38. data/lib/double_auth_engine/models/user_mixin.rb +38 -0
  39. data/lib/double_auth_engine/models/user_session_mixin.rb +15 -0
  40. data/lib/double_auth_engine/tasks/migrate_seed.rake +9 -0
  41. data/lib/double_auth_engine/version.rb +3 -0
  42. data/lib/double_auth_engine.rb +15 -0
  43. data/lib/engine.rb +23 -0
  44. data/spec/double_auth_engine_spec.rb +7 -0
  45. data/spec/dummy/Rakefile +7 -0
  46. data/spec/dummy/app/controllers/application_controller.rb +4 -0
  47. data/spec/dummy/app/controllers/dashboard_controller.rb +3 -0
  48. data/spec/dummy/app/helpers/application_helper.rb +2 -0
  49. data/spec/dummy/app/views/dashboard/index.html.erb +0 -0
  50. data/spec/dummy/app/views/layouts/application.html.erb +14 -0
  51. data/spec/dummy/config/application.rb +48 -0
  52. data/spec/dummy/config/authorization_rules.rb +20 -0
  53. data/spec/dummy/config/boot.rb +10 -0
  54. data/spec/dummy/config/database.yml +22 -0
  55. data/spec/dummy/config/environment.rb +5 -0
  56. data/spec/dummy/config/environments/development.rb +29 -0
  57. data/spec/dummy/config/environments/production.rb +52 -0
  58. data/spec/dummy/config/environments/test.rb +35 -0
  59. data/spec/dummy/config/initializers/backtrace_silencers.rb +7 -0
  60. data/spec/dummy/config/initializers/inflections.rb +10 -0
  61. data/spec/dummy/config/initializers/mime_types.rb +5 -0
  62. data/spec/dummy/config/initializers/secret_token.rb +7 -0
  63. data/spec/dummy/config/initializers/session_store.rb +8 -0
  64. data/spec/dummy/config/initializers/setup_mail.rb +9 -0
  65. data/spec/dummy/config/locales/en.yml +5 -0
  66. data/spec/dummy/config/routes.rb +3 -0
  67. data/spec/dummy/config.ru +4 -0
  68. data/spec/dummy/db/migrate/20110408030355_create_users.rb +28 -0
  69. data/spec/dummy/db/migrate/20110408030356_create_roles.rb +12 -0
  70. data/spec/dummy/db/migrate/20110408030357_create_assignments.rb +13 -0
  71. data/spec/dummy/db/schema.rb +51 -0
  72. data/spec/dummy/db/seeds.rb +3 -0
  73. data/spec/dummy/lib/development_mail_interceptor.rb +6 -0
  74. data/spec/dummy/public/404.html +26 -0
  75. data/spec/dummy/public/422.html +26 -0
  76. data/spec/dummy/public/500.html +26 -0
  77. data/spec/dummy/public/favicon.ico +0 -0
  78. data/spec/dummy/public/javascripts/application.js +2 -0
  79. data/spec/dummy/public/javascripts/controls.js +965 -0
  80. data/spec/dummy/public/javascripts/dragdrop.js +974 -0
  81. data/spec/dummy/public/javascripts/effects.js +1123 -0
  82. data/spec/dummy/public/javascripts/prototype.js +6001 -0
  83. data/spec/dummy/public/javascripts/rails.js +175 -0
  84. data/spec/dummy/public/stylesheets/.gitkeep +0 -0
  85. data/spec/dummy/script/rails +6 -0
  86. data/spec/dummy/spec/authorizations/user_spec.rb +104 -0
  87. data/spec/dummy/spec/controllers/user_sessions_controller_spec.rb +48 -0
  88. data/spec/dummy/spec/controllers/users_controller_spec.rb +125 -0
  89. data/spec/dummy/spec/models/user_spec.rb +65 -0
  90. data/spec/integration/navigation_spec.rb +9 -0
  91. data/spec/spec_helper.rb +42 -0
  92. data/spec/support/user_authentication.rb +14 -0
  93. data/spec/support/user_authorization.rb +17 -0
  94. metadata +218 -0
data/.gitignore ADDED
@@ -0,0 +1,7 @@
1
+ .bundle/
2
+ log/*.log
3
+ pkg/
4
+ spec/dummy/db/*.sqlite3
5
+ spec/dummy/log/*.log
6
+ spec/dummy/tmp/
7
+ .idea/*
data/.rvmrc ADDED
@@ -0,0 +1 @@
1
+ rvm use 1.9.2@double_auth_engine --create
data/Gemfile ADDED
@@ -0,0 +1,9 @@
1
+ source "http://rubygems.org"
2
+
3
+ gem "rails", "3.0.5"
4
+ gem "sqlite3-ruby", :require => "sqlite3"
5
+ gem "double_auth_engine", :path => "./"
6
+ gem "capybara", ">= 0.4.0"
7
+ gem "rspec-rails"
8
+ gem "ffaker"
9
+ gem "mail"
data/Gemfile.lock ADDED
@@ -0,0 +1,136 @@
1
+ GIT
2
+ remote: git://github.com/jeremydurham/authlogic.git
3
+ revision: 8fc34e1d58ea52e5439e7001eacb6d383f2bf0a0
4
+ specs:
5
+ authlogic (2.1.6)
6
+ activesupport
7
+
8
+ PATH
9
+ remote: .
10
+ specs:
11
+ double_auth_engine (0.0.1)
12
+ authlogic
13
+ declarative_authorization
14
+
15
+ GEM
16
+ remote: http://rubygems.org/
17
+ specs:
18
+ abstract (1.0.0)
19
+ actionmailer (3.0.5)
20
+ actionpack (= 3.0.5)
21
+ mail (~> 2.2.15)
22
+ actionpack (3.0.5)
23
+ activemodel (= 3.0.5)
24
+ activesupport (= 3.0.5)
25
+ builder (~> 2.1.2)
26
+ erubis (~> 2.6.6)
27
+ i18n (~> 0.4)
28
+ rack (~> 1.2.1)
29
+ rack-mount (~> 0.6.13)
30
+ rack-test (~> 0.5.7)
31
+ tzinfo (~> 0.3.23)
32
+ activemodel (3.0.5)
33
+ activesupport (= 3.0.5)
34
+ builder (~> 2.1.2)
35
+ i18n (~> 0.4)
36
+ activerecord (3.0.5)
37
+ activemodel (= 3.0.5)
38
+ activesupport (= 3.0.5)
39
+ arel (~> 2.0.2)
40
+ tzinfo (~> 0.3.23)
41
+ activeresource (3.0.5)
42
+ activemodel (= 3.0.5)
43
+ activesupport (= 3.0.5)
44
+ activesupport (3.0.5)
45
+ arel (2.0.9)
46
+ builder (2.1.2)
47
+ capybara (0.4.1.2)
48
+ celerity (>= 0.7.9)
49
+ culerity (>= 0.2.4)
50
+ mime-types (>= 1.16)
51
+ nokogiri (>= 1.3.3)
52
+ rack (>= 1.0.0)
53
+ rack-test (>= 0.5.4)
54
+ selenium-webdriver (>= 0.0.27)
55
+ xpath (~> 0.1.3)
56
+ celerity (0.8.9)
57
+ childprocess (0.1.8)
58
+ ffi (~> 1.0.6)
59
+ culerity (0.2.15)
60
+ declarative_authorization (0.5.2)
61
+ diff-lcs (1.1.2)
62
+ erubis (2.6.6)
63
+ abstract (>= 1.0.0)
64
+ ffaker (1.5.0)
65
+ ffi (1.0.7)
66
+ rake (>= 0.8.7)
67
+ i18n (0.5.0)
68
+ json_pure (1.5.1)
69
+ mail (2.2.15)
70
+ activesupport (>= 2.3.6)
71
+ i18n (>= 0.4.0)
72
+ mime-types (~> 1.16)
73
+ treetop (~> 1.4.8)
74
+ mime-types (1.16)
75
+ nokogiri (1.4.4)
76
+ polyglot (0.3.1)
77
+ rack (1.2.2)
78
+ rack-mount (0.6.14)
79
+ rack (>= 1.0.0)
80
+ rack-test (0.5.7)
81
+ rack (>= 1.0)
82
+ rails (3.0.5)
83
+ actionmailer (= 3.0.5)
84
+ actionpack (= 3.0.5)
85
+ activerecord (= 3.0.5)
86
+ activeresource (= 3.0.5)
87
+ activesupport (= 3.0.5)
88
+ bundler (~> 1.0)
89
+ railties (= 3.0.5)
90
+ railties (3.0.5)
91
+ actionpack (= 3.0.5)
92
+ activesupport (= 3.0.5)
93
+ rake (>= 0.8.7)
94
+ thor (~> 0.14.4)
95
+ rake (0.8.7)
96
+ rspec (2.5.0)
97
+ rspec-core (~> 2.5.0)
98
+ rspec-expectations (~> 2.5.0)
99
+ rspec-mocks (~> 2.5.0)
100
+ rspec-core (2.5.1)
101
+ rspec-expectations (2.5.0)
102
+ diff-lcs (~> 1.1.2)
103
+ rspec-mocks (2.5.0)
104
+ rspec-rails (2.5.0)
105
+ actionpack (~> 3.0)
106
+ activesupport (~> 3.0)
107
+ railties (~> 3.0)
108
+ rspec (~> 2.5.0)
109
+ rubyzip (0.9.4)
110
+ selenium-webdriver (0.1.4)
111
+ childprocess (>= 0.1.7)
112
+ ffi (>= 1.0.7)
113
+ json_pure
114
+ rubyzip
115
+ sqlite3 (1.3.3)
116
+ sqlite3-ruby (1.3.3)
117
+ sqlite3 (>= 1.3.3)
118
+ thor (0.14.6)
119
+ treetop (1.4.9)
120
+ polyglot (>= 0.3.1)
121
+ tzinfo (0.3.25)
122
+ xpath (0.1.3)
123
+ nokogiri (~> 1.3)
124
+
125
+ PLATFORMS
126
+ ruby
127
+
128
+ DEPENDENCIES
129
+ authlogic (= 2.1.6)!
130
+ capybara (>= 0.4.0)
131
+ double_auth_engine!
132
+ ffaker
133
+ mail
134
+ rails (= 3.0.5)
135
+ rspec-rails
136
+ sqlite3-ruby
data/MIT-LICENSE ADDED
@@ -0,0 +1,20 @@
1
+ Copyright 2011 YOURNAME
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,59 @@
1
+ # Double Auth Engine
2
+ [Authlogic](https://github.com/binarylogic/authlogic) and [Declarative Authorization](https://github.com/stffn/declarative_authorization) together in one fantastic Rails engine. Bladow!
3
+
4
+ ## Usage
5
+ 1. Add double_auth_engine to Gemfile
6
+
7
+ gem "double_auth_engine"
8
+
9
+ 2. Rebundle
10
+
11
+ bundle install
12
+
13
+ 3. Run the DoubleAuthEngine install generator
14
+
15
+ rails g double_auth_engine:install
16
+
17
+ 4. Migrate your DB and seed it with default seeds (:user and :admin)
18
+
19
+ rake db:migrate:seed
20
+
21
+ 6. Update "default@dummy.com" within setup_mail.rb to the default address for your application. This address is used for the engine's password reset mailer.
22
+
23
+ class ActionMailer::Base
24
+ def from_with_default(input=nil)
25
+ return from_without_default(input) || "default@dummy.com" if input.nil?
26
+ from_without_default(input)
27
+ end
28
+ alias_method_chain :from, :default
29
+ end
30
+
31
+ 5. Start app
32
+
33
+ rails s
34
+
35
+ ## Readme Driven Development
36
+
37
+ A <del>strike</del> means its done!
38
+
39
+ * <del>Add Authlogic</del>
40
+ * <del>Add Password Reset</del>
41
+ * <del>Update generator with ActionMailer monkey patch</del>
42
+ * <del>Update install generator to add include to ApplicationController</del>
43
+ * <del>Update README for mailer settings</del>
44
+ * <del>Authlogic specs</del>
45
+ * <del>Add Declarative Authorization</del>
46
+ * <del>Declarative Authorization specs</del>
47
+ * Mailer specs
48
+ * Style views
49
+
50
+ ## Versioning
51
+ <strong>Version 0.0.1 </strong> - This project uses [Semantic Versioning](http://semver.org/)
52
+
53
+ ## Contributors
54
+ All contributions are welcome. Fork repo, make changes, add specs, ensure all specs pass, send a pull request.
55
+
56
+ * [Kyle Bolton](https://github.com/kb) - Creator
57
+ * [Jeremy Durham](https://github.com/jeremydurham)
58
+
59
+ Copyright (c) 2011 Kyle Bolton, released under the MIT license
data/Rakefile ADDED
@@ -0,0 +1,25 @@
1
+ # encoding: UTF-8
2
+ require 'rubygems'
3
+ begin
4
+ require 'bundler/setup'
5
+ rescue LoadError
6
+ puts 'You must `gem install bundler` and `bundle install` to run rake tasks'
7
+ end
8
+
9
+ require 'rake'
10
+ require 'rake/rdoctask'
11
+
12
+ require 'rspec/core'
13
+ require 'rspec/core/rake_task'
14
+
15
+ RSpec::Core::RakeTask.new(:spec)
16
+
17
+ task :default => :spec
18
+
19
+ Rake::RDocTask.new(:rdoc) do |rdoc|
20
+ rdoc.rdoc_dir = 'rdoc'
21
+ rdoc.title = 'DoubleAuthEngine'
22
+ rdoc.options << '--line-numbers' << '--inline-source'
23
+ rdoc.rdoc_files.include('README.rdoc')
24
+ rdoc.rdoc_files.include('lib/**/*.rb')
25
+ end
@@ -0,0 +1,3 @@
1
+ class PasswordResetsController < ApplicationController
2
+ include DoubleAuthEngine::PasswordResetsControllerMixin
3
+ end
@@ -0,0 +1,3 @@
1
+ class UserSessionsController < ApplicationController
2
+ include DoubleAuthEngine::UserSessionsControllerMixin
3
+ end
@@ -0,0 +1,3 @@
1
+ class UsersController < ApplicationController
2
+ include DoubleAuthEngine::UsersControllerMixin
3
+ end
@@ -0,0 +1,8 @@
1
+ class Notifier < ActionMailer::Base
2
+ def password_reset_instructions(user)
3
+ subject "Password Reset Instructions"
4
+ recipients user.email
5
+ sent_on Time.now
6
+ @edit_password_reset_url = edit_password_reset_url(user.perishable_token)
7
+ end
8
+ end
@@ -0,0 +1,3 @@
1
+ class Assignment < ActiveRecord::Base
2
+ include DoubleAuthEngine::AssignmentMixin
3
+ end
@@ -0,0 +1,3 @@
1
+ class Role < ActiveRecord::Base
2
+ include DoubleAuthEngine::RoleMixin
3
+ end
@@ -0,0 +1,3 @@
1
+ class User < ActiveRecord::Base
2
+ include DoubleAuthEngine::UserMixin
3
+ end
@@ -0,0 +1,3 @@
1
+ class UserSession < Authlogic::Session::Base
2
+ include DoubleAuthEngine::UserSessionMixin
3
+ end
@@ -0,0 +1,8 @@
1
+ A request to reset your password has been made.
2
+ If you did not make this request, simply ignore this email.
3
+ If you did make this request just click the link below:
4
+
5
+ <%= @edit_password_reset_url %>
6
+
7
+ If the above URL does not work try copying and pasting it into your browser.
8
+ If you continue to have problem please feel free to contact us.
@@ -0,0 +1,5 @@
1
+ <%= form_tag password_reset_path, :method => :put do %>
2
+ <%= label_tag :password, 'Enter your new password' %>
3
+ <%= password_field_tag :password, nil %>
4
+ <%= submit_tag %>
5
+ <% end %>
@@ -0,0 +1,5 @@
1
+ <%= form_tag password_resets_path do %>
2
+ <%= label_tag :email, nil %>
3
+ <%= text_field_tag :email, nil %>
4
+ <%= submit_tag %>
5
+ <% end %>
@@ -0,0 +1,17 @@
1
+ <!DOCTYPE html>
2
+ <html>
3
+ <head>
4
+ <title>Login</title>
5
+ <%= csrf_meta_tag %>
6
+ </head>
7
+ <body>
8
+ <%= form_for @user_session do |f| %>
9
+ <%= f.label :email, "Email" %>
10
+ <%= f.text_field :email %>
11
+ <%= f.label :password, "Password" %>
12
+ <%= f.password_field :password %>
13
+ <%= link_to 'Forgot Password?', forgot_password_path %>
14
+ <%= f.submit "Login" %>
15
+ <% end %>
16
+ </body>
17
+ </html>
File without changes
File without changes
@@ -0,0 +1,20 @@
1
+ <!DOCTYPE html>
2
+ <html>
3
+ <head>
4
+ <title>New User</title>
5
+ <%= csrf_meta_tag %>
6
+ </head>
7
+ <body>
8
+ <%= form_for @user do |f| %>
9
+ <%= f.label :name, "Name" %>
10
+ <%= f.text_field :name %>
11
+ <%= f.label :email, "Email" %>
12
+ <%= f.text_field :email %>
13
+ <%= f.label :password, "Password" %>
14
+ <%= f.password_field :password %>
15
+ <%= f.label :password_confirmation, "Re-enter password" %>
16
+ <%= f.password_field :password_confirmation %>
17
+ <%= f.submit %>
18
+ <% end %>
19
+ </body>
20
+ </html>
@@ -0,0 +1,2 @@
1
+ <%= @user.name %>
2
+ <%= @user.email %>
data/config/routes.rb ADDED
@@ -0,0 +1,11 @@
1
+ Rails.application.routes.draw do
2
+ match 'signup', :to => 'users#new'
3
+ match 'login', :to => 'user_sessions#new'
4
+ match 'logout', :to => 'user_sessions#destroy'
5
+
6
+ resources :users
7
+ resources :user_sessions
8
+
9
+ match '/forgot_password', :controller => 'password_resets', :action => 'new'
10
+ resources :password_resets
11
+ end
@@ -0,0 +1,26 @@
1
+ # -*- encoding: utf-8 -*-
2
+ lib = File.expand_path('../lib/', __FILE__)
3
+ $:.unshift lib unless $:.include?(lib)
4
+
5
+ require "double_auth_engine/version"
6
+
7
+ Gem::Specification.new do |s|
8
+ s.name = "double_auth_engine"
9
+ s.version = DoubleAuthEngine::VERSION
10
+ s.platform = Gem::Platform::RUBY
11
+ s.authors = ["Kyle Bolton"]
12
+ s.email = "kyle.bolton@gmail.com'"
13
+ s.homepage = "https://github.com/kb/double_auth_engine"
14
+ s.license = "MIT"
15
+ s.summary = "Authlogic and Declarative Authorization Engine"
16
+ s.description = "Authlogic and Declarative Authorization Engine for Rails 3"
17
+
18
+ s.required_rubygems_version = ">= 1.3.6"
19
+
20
+ s.add_dependency("kb-authlogic")
21
+ s.add_dependency("declarative_authorization")
22
+
23
+ s.files = `git ls-files`.split("\n")
24
+ s.test_files = `git ls-files spec/*`.split("\n")
25
+ s.require_paths = ["lib"]
26
+ end
@@ -0,0 +1,42 @@
1
+ module DoubleAuthEngine
2
+ module ApplicationControllerMixin
3
+ def self.included(base)
4
+ base.class_eval do
5
+ before_filter :require_user
6
+ helper_method :current_user_session, :current_user
7
+ end
8
+ base.send :include, InstanceMethods
9
+ end
10
+
11
+ module InstanceMethods
12
+ protected
13
+ def current_user_session
14
+ return @current_user_session if defined?(@current_user_session)
15
+ @current_user_session = UserSession.find
16
+ end
17
+
18
+ def current_user
19
+ return @current_user if defined?(@current_user)
20
+ @current_user = current_user_session && current_user_session.record
21
+ end
22
+
23
+ def require_user
24
+ unless current_user
25
+ store_location
26
+ flash[:notice] = "You must be logged in to access this page" unless request.fullpath == root_path
27
+ redirect_to login_url
28
+ false
29
+ end
30
+ end
31
+
32
+ def store_location
33
+ session[:return_to] = request.fullpath
34
+ end
35
+
36
+ def redirect_back_or_default(default)
37
+ redirect_to(session[:return_to] || default)
38
+ session[:return_to] = nil
39
+ end
40
+ end
41
+ end
42
+ end
@@ -0,0 +1,49 @@
1
+ module DoubleAuthEngine
2
+ module PasswordResetsControllerMixin
3
+ def self.included(base)
4
+ base.class_eval do
5
+ skip_before_filter :require_user
6
+ before_filter :load_user_using_perishable_token, :only => [:edit, :update]
7
+ end
8
+ base.send :include, InstanceMethods
9
+ end
10
+
11
+ module InstanceMethods
12
+ def new
13
+ end
14
+
15
+ def create
16
+ @user = User.find_by_email(params[:email])
17
+ if @user
18
+ @user.deliver_password_reset_instructions!
19
+ redirect_to root_url, :notice => 'Instructions to reset your password have been emailed to you. Please check your email.'
20
+ else
21
+ redirect_to new_password_reset_url, :notice => 'No user was found with that email address'
22
+ end
23
+ end
24
+
25
+ def edit
26
+ end
27
+
28
+ def update
29
+ @user.password = params[:password]
30
+ @user.password_confirmation = params[:password]
31
+ if @user.save
32
+ flash[:success] = "Your password was successfully updated"
33
+ redirect_to root_url
34
+ else
35
+ render :action => :edit
36
+ end
37
+ end
38
+
39
+ private
40
+ def load_user_using_perishable_token
41
+ @user = User.find_using_perishable_token(params[:id])
42
+ unless @user
43
+ flash[:error] = "We're sorry, but we could not locate your account"
44
+ redirect_to root_url
45
+ end
46
+ end
47
+ end
48
+ end
49
+ end
@@ -0,0 +1,34 @@
1
+ module DoubleAuthEngine
2
+ module UserSessionsControllerMixin
3
+ def self.included(base)
4
+ base.class_eval do
5
+ skip_before_filter :require_user, :only => [:new, :create]
6
+ respond_to :html, :json, :js
7
+ end
8
+ base.send :include, InstanceMethods
9
+ end
10
+
11
+ module InstanceMethods
12
+ def new
13
+ @user_session = UserSession.new
14
+ render :layout => false
15
+ end
16
+
17
+ def create
18
+ @user_session = UserSession.new(params[:user_session])
19
+ if @user_session.save
20
+ redirect_to root_url
21
+ else
22
+ render :action => 'new'
23
+ end
24
+ end
25
+
26
+ def destroy
27
+ @user_session = UserSession.find(params[:id])
28
+ @user_session.destroy
29
+ flash[:notice] = 'Successfully logged out'
30
+ redirect_to root_url
31
+ end
32
+ end
33
+ end
34
+ end
@@ -0,0 +1,63 @@
1
+ module DoubleAuthEngine
2
+ module UsersControllerMixin
3
+ def self.included(base)
4
+ base.class_eval do
5
+ skip_before_filter :require_user, :only => [:new, :create]
6
+ filter_access_to [:edit, :update], :attribute_check => true
7
+ respond_to :html, :json, :js
8
+ end
9
+ base.send :include, InstanceMethods
10
+ end
11
+
12
+ module InstanceMethods
13
+ def index
14
+ @users = User.all
15
+ respond_with(@users)
16
+ end
17
+
18
+ def show
19
+ @user = User.find(params[:id])
20
+ respond_with @user
21
+ end
22
+
23
+ def new
24
+ @user = User.new
25
+ respond_with @user
26
+ end
27
+
28
+ def create
29
+ @user = User.new(params[:user])
30
+ if @user.save
31
+ flash[:notice] = 'User successfully created'
32
+ respond_with(@user)
33
+ else
34
+ render :action => 'new'
35
+ end
36
+ end
37
+
38
+ def edit
39
+ @user = User.find(params[:id])
40
+ respond_with(@user)
41
+ end
42
+
43
+ def update
44
+ @user = User.find(params[:id])
45
+ if @user.update_attributes(params[:user])
46
+ flash[:notice] = 'User successfully updated'
47
+ respond_with(@user)
48
+ else
49
+ render :action => 'edit'
50
+ end
51
+ end
52
+
53
+ def destroy
54
+ @user = User.find(params[:id])
55
+ @user.destroy
56
+ respond_to do |format|
57
+ format.html { redirect_to(users_url) }
58
+ format.xml { head :ok }
59
+ end
60
+ end
61
+ end
62
+ end
63
+ end
@@ -0,0 +1,48 @@
1
+ require 'rails/generators'
2
+
3
+ module DoubleAuthEngine
4
+ class InstallGenerator < Rails::Generators::Base
5
+ include Rails::Generators::Migration
6
+
7
+ def self.source_root
8
+ @source_root ||= File.join(File.dirname(__FILE__), 'templates')
9
+ end
10
+
11
+ def self.next_migration_number(path)
12
+ unless @prev_migration_nr
13
+ @prev_migration_nr = Time.now.utc.strftime("%Y%m%d%H%M%S").to_i
14
+ else
15
+ @prev_migration_nr += 1
16
+ end
17
+ @prev_migration_nr.to_s
18
+ end
19
+
20
+ def create_migration_files
21
+ migration_template "user_migration.rb", "db/migrate/create_users.rb"
22
+ migration_template "role_migration.rb", "db/migrate/create_roles.rb"
23
+ migration_template "assignment_migration.rb", "db/migrate/create_assignments.rb"
24
+ end
25
+
26
+ def create_initializer_file
27
+ copy_file "setup_mail_initializer.rb", "config/initializers/setup_mail.rb"
28
+ end
29
+
30
+ def create_authorization_file
31
+ copy_file "authorization_rules.rb", "config/authorization_rules.rb"
32
+ end
33
+
34
+ def update_application_controller
35
+ insert_into_file "app/controllers/application_controller.rb", :after => "class ApplicationController < ActionController::Base\n" do
36
+ "\tinclude DoubleAuthEngine::ApplicationControllerMixin\n"
37
+ end
38
+ end
39
+
40
+ # Passing a block to append_to_file would not format nicely,
41
+ # which is why I opted for separate append statements. Don't judge.
42
+ def add_roles
43
+ append_to_file "db/seeds.rb", "if Role.all.empty?\n"
44
+ append_to_file "db/seeds.rb", "\tRole.create(:name => 'admin')\n"
45
+ append_to_file "db/seeds.rb", "end\n"
46
+ end
47
+ end
48
+ end
@@ -0,0 +1,13 @@
1
+ class CreateAssignments < ActiveRecord::Migration
2
+ def self.up
3
+ create_table :assignments do |t|
4
+ t.belongs_to :user
5
+ t.belongs_to :role
6
+ t.timestamps
7
+ end
8
+ end
9
+
10
+ def self.down
11
+ drop_table :assignments
12
+ end
13
+ end