nagybence-clearance 0.4.1
Sign up to get free protection for your applications and to get access to all the features.
- data/LICENSE +21 -0
- data/README.textile +205 -0
- data/Rakefile +53 -0
- data/TODO.textile +8 -0
- data/generators/clearance/USAGE +1 -0
- data/generators/clearance/clearance_generator.rb +92 -0
- data/generators/clearance/lib/insert_commands.rb +103 -0
- data/generators/clearance/lib/rake_commands.rb +22 -0
- data/generators/clearance/templates/README +54 -0
- data/generators/clearance/templates/app/controllers/application.rb +5 -0
- data/generators/clearance/templates/app/controllers/confirmations_controller.rb +3 -0
- data/generators/clearance/templates/app/controllers/passwords_controller.rb +3 -0
- data/generators/clearance/templates/app/controllers/sessions_controller.rb +3 -0
- data/generators/clearance/templates/app/controllers/users_controller.rb +3 -0
- data/generators/clearance/templates/app/models/clearance_mailer.rb +5 -0
- data/generators/clearance/templates/app/models/user.rb +3 -0
- data/generators/clearance/templates/app/views/clearance_mailer/change_password.html.erb +10 -0
- data/generators/clearance/templates/app/views/clearance_mailer/confirmation.html.erb +1 -0
- data/generators/clearance/templates/app/views/passwords/edit.html.erb +25 -0
- data/generators/clearance/templates/app/views/passwords/new.html.erb +15 -0
- data/generators/clearance/templates/app/views/sessions/new.html.erb +28 -0
- data/generators/clearance/templates/app/views/users/_form.html.erb +13 -0
- data/generators/clearance/templates/app/views/users/edit.html.erb +6 -0
- data/generators/clearance/templates/app/views/users/new.html.erb +6 -0
- data/generators/clearance/templates/db/migrate/create_users_with_clearance_columns.rb +21 -0
- data/generators/clearance/templates/db/migrate/update_users_with_clearance_columns.rb +42 -0
- data/generators/clearance/templates/test/factories/clearance.rb +16 -0
- data/generators/clearance/templates/test/functional/confirmations_controller_test.rb +5 -0
- data/generators/clearance/templates/test/functional/passwords_controller_test.rb +5 -0
- data/generators/clearance/templates/test/functional/sessions_controller_test.rb +5 -0
- data/generators/clearance/templates/test/functional/users_controller_test.rb +5 -0
- data/generators/clearance/templates/test/unit/clearance_mailer_test.rb +6 -0
- data/generators/clearance/templates/test/unit/user_test.rb +5 -0
- data/lib/clearance/app/controllers/application_controller.rb +84 -0
- data/lib/clearance/app/controllers/confirmations_controller.rb +42 -0
- data/lib/clearance/app/controllers/passwords_controller.rb +67 -0
- data/lib/clearance/app/controllers/sessions_controller.rb +68 -0
- data/lib/clearance/app/controllers/users_controller.rb +40 -0
- data/lib/clearance/app/models/clearance_mailer.rb +29 -0
- data/lib/clearance/app/models/user.rb +89 -0
- data/lib/clearance/test/functional/confirmations_controller_test.rb +44 -0
- data/lib/clearance/test/functional/passwords_controller_test.rb +175 -0
- data/lib/clearance/test/functional/sessions_controller_test.rb +194 -0
- data/lib/clearance/test/functional/users_controller_test.rb +72 -0
- data/lib/clearance/test/test_helper.rb +28 -0
- data/lib/clearance/test/unit/clearance_mailer_test.rb +65 -0
- data/lib/clearance/test/unit/user_test.rb +167 -0
- data/lib/clearance.rb +14 -0
- data/rails/init.rb +1 -0
- data/shoulda_macros/clearance.rb +173 -0
- metadata +132 -0
data/LICENSE
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
The MIT License
|
2
|
+
|
3
|
+
Copyright (c) 2008 thoughtbot, inc.
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
7
|
+
in the Software without restriction, including without limitation the rights
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
10
|
+
furnished to do so, subject to the following conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be included in
|
13
|
+
all copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
21
|
+
THE SOFTWARE.
|
data/README.textile
ADDED
@@ -0,0 +1,205 @@
|
|
1
|
+
h1. Clearance
|
2
|
+
|
3
|
+
Rails authentication for developers who write tests.
|
4
|
+
|
5
|
+
"We have clearance, Clarence.":http://www.youtube.com/v/mNRXJEE3Nz8
|
6
|
+
|
7
|
+
h2. Integration with Suspenders
|
8
|
+
|
9
|
+
Clearance is based on the same conventions and tools as "Suspenders":http://github.com/thoughtbot/suspenders Thus if you use it, you may already have some configuration mentioned below in place.
|
10
|
+
|
11
|
+
h2. Gem installation (Rails 2.1+)
|
12
|
+
|
13
|
+
In config/environment.rb:
|
14
|
+
|
15
|
+
config.gem 'mocha'
|
16
|
+
config.gem 'thoughtbot-shoulda',
|
17
|
+
:lib => 'shoulda',
|
18
|
+
:source => "http://gems.github.com",
|
19
|
+
:version => '>= 2.0.6'
|
20
|
+
config.gem 'thoughtbot-factory_girl',
|
21
|
+
:lib => 'factory_girl',
|
22
|
+
:source => "http://gems.github.com",
|
23
|
+
:version => '>= 1.1.5'
|
24
|
+
config.gem "thoughtbot-clearance",
|
25
|
+
:lib => 'clearance',
|
26
|
+
:source => 'http://gems.github.com',
|
27
|
+
:version => '>= 0.3.9'
|
28
|
+
|
29
|
+
Then:
|
30
|
+
|
31
|
+
rake gems:install
|
32
|
+
rake gems:unpack
|
33
|
+
|
34
|
+
h2. The generator
|
35
|
+
|
36
|
+
Make sure the development database exists and run the generator:
|
37
|
+
|
38
|
+
script/generate clearance
|
39
|
+
|
40
|
+
A number of files will be created and instructions will be printed.
|
41
|
+
|
42
|
+
You may already have some of these files. Don't worry. You'll be asked if you want to overwrite them.
|
43
|
+
|
44
|
+
h2. Modules
|
45
|
+
|
46
|
+
Clearance works by mixing behavior into tests, controllers, and models. For any file that you do not want to overwrite, include the corresponding Clearance module. They are namespaced exactly like the directory structure of a Rails app.
|
47
|
+
|
48
|
+
Application controller example:
|
49
|
+
|
50
|
+
class ApplicationController < ActionController::Base
|
51
|
+
include Clearance::App::Controllers::ApplicationController
|
52
|
+
end
|
53
|
+
|
54
|
+
User model example:
|
55
|
+
|
56
|
+
class User < ActiveRecord::Base
|
57
|
+
include Clearance::App::Models::User
|
58
|
+
end
|
59
|
+
|
60
|
+
User test example:
|
61
|
+
|
62
|
+
class UserTest < Test::Unit::TestCase
|
63
|
+
include Clearance::Test::Unit::UserTest
|
64
|
+
end
|
65
|
+
|
66
|
+
h2. The migration
|
67
|
+
|
68
|
+
The generator will also create a migration to add a "users" table and run it. If the table already exists in the database, the migration will just add fields and indexes that are missing and required by Clearance. If the migration fails, the generator will revert all changes back.
|
69
|
+
|
70
|
+
h2. Routes
|
71
|
+
|
72
|
+
Clearance will add these routes to your routes.rb:
|
73
|
+
|
74
|
+
map.resources :users, :has_one => [:password, :confirmation]
|
75
|
+
map.resource :session
|
76
|
+
map.resources :passwords
|
77
|
+
|
78
|
+
Please note that Clearance depends on root_url, so please make sure that it is defined to *something* in your config/routes.rb:
|
79
|
+
|
80
|
+
map.root :controller => 'home'
|
81
|
+
|
82
|
+
h2. Environments
|
83
|
+
|
84
|
+
You need to define HOST constant in your environments files. In config/environments/test.rb and config/environments/development.rb it can be:
|
85
|
+
|
86
|
+
HOST = "localhost"
|
87
|
+
|
88
|
+
While in config/environments/production.rb it must be the actual host your application is deployed to because the constant is used by mailers to generate URLs in emails.
|
89
|
+
|
90
|
+
In config/environment.rb:
|
91
|
+
|
92
|
+
DO_NOT_REPLY = "donotreply@example.com"
|
93
|
+
|
94
|
+
h2. Tests
|
95
|
+
|
96
|
+
The tests use "Shoulda":http://thoughtbot.com/projects/shoulda >= 2.0.6 and "Factory Girl":http://thoughtbot.com/projects/factory_girl >= 1.1.5. There needs to be a Clearance module in your test/test_helper.rb:
|
97
|
+
|
98
|
+
class Test::Unit::TestCase
|
99
|
+
self.use_transactional_fixtures = true
|
100
|
+
self.use_instantiated_fixtures = false
|
101
|
+
include Clearance::Test::TestHelper
|
102
|
+
end
|
103
|
+
|
104
|
+
The generator will create a user factory in test/factories/clearance.rb unless
|
105
|
+
you have it defined somewhere else.
|
106
|
+
|
107
|
+
h2. Usage: basic workflow
|
108
|
+
|
109
|
+
Rails authentication with Clearance uses the standard approach thoughtbot and our clients have agreed upon.
|
110
|
+
|
111
|
+
Users register (UsersController) using an email address and a password (User model). They get an email (ClearanceMailer) with a confirmation link to confirm their registration (ConfirmationController).
|
112
|
+
|
113
|
+
Registered users can sign in and out (SessionsController). If they forget their password, they request an email (ClearanceMailer) containing a link to change it (PasswordsController).
|
114
|
+
|
115
|
+
h2. Usage: actions which require an authenticated user
|
116
|
+
|
117
|
+
To protect your controllers with authentication add:
|
118
|
+
|
119
|
+
class ProtectedController < ApplicationController
|
120
|
+
before_filter :authenticate
|
121
|
+
|
122
|
+
The filter will ensure that only authenticated users can access the controller. If someone who's not signed in tries to access a protected action:
|
123
|
+
|
124
|
+
* the URL is stored in the session,
|
125
|
+
* the user is redirected to sign in page, and
|
126
|
+
* after successful authentication will be be redirected back to that URL.
|
127
|
+
|
128
|
+
h2. Usage: signed_in?, current_user
|
129
|
+
|
130
|
+
Clearance provides two methods that can be used in controllers, helpers, and views to check if current user is authenticated and get the actual user:
|
131
|
+
|
132
|
+
* signed_in?
|
133
|
+
* current_user
|
134
|
+
|
135
|
+
<% if signed_in? -%>
|
136
|
+
Hello, <%= current_user.name %>!
|
137
|
+
<% else -%>
|
138
|
+
Please <%= link_to 'Sign in', new_session_path %>
|
139
|
+
<% end -%>
|
140
|
+
|
141
|
+
h2. Usage: mass assignment
|
142
|
+
|
143
|
+
Please note that all User attributes except email, password and password_confirmation are protected from mass assignment by default. Use attr_accessible to enable it for your custom attributes.
|
144
|
+
|
145
|
+
class User < ActiveRecord::Base
|
146
|
+
include Clearance::App::Models::User
|
147
|
+
attr_accessible :first_name, :last_name
|
148
|
+
end
|
149
|
+
|
150
|
+
h2. Hooks: return_to parameter
|
151
|
+
|
152
|
+
To specify where to redirect a user (say you want to have a sign in form on every page and redirect the user to the same page) after he/she signs in, you can add a "return_to" parameter to the request (thanks to "Phillippe":http://www.sivarg.com/2009/01/clearance-coming-from-where-your-were.html for the tip):
|
153
|
+
|
154
|
+
<% form_for :session, :url => session_path(:return_to => request.request_uri) do |form| %>
|
155
|
+
|
156
|
+
h2. Hooks: url_after_create, url_after_update, url_after_destroy
|
157
|
+
|
158
|
+
Actions that redirect (create, update, and destroy) in Clearance controllers are customizable. If you want to redirect a user to a specific route after signing in, overwrite the "url_after_create" method in the SessionsController:
|
159
|
+
|
160
|
+
class SessionsController < ApplicationController
|
161
|
+
include Clearance::App::Controllers::SessionsController
|
162
|
+
|
163
|
+
private
|
164
|
+
|
165
|
+
def url_after_create
|
166
|
+
new_blog_post_path
|
167
|
+
end
|
168
|
+
end
|
169
|
+
|
170
|
+
There are similar methods in other controllers as well:
|
171
|
+
|
172
|
+
UsersController#url_after_create (register)
|
173
|
+
SessionsController#url_after_create (sign in)
|
174
|
+
SessionsController#url_after_destroy (sign out)
|
175
|
+
PasswordsController#url_after_create (password request)
|
176
|
+
PasswordsController#url_after_update (password)
|
177
|
+
ConfirmationsController#url_after_create (confirmation)
|
178
|
+
|
179
|
+
h2. Hooks: sign_user_in
|
180
|
+
|
181
|
+
Say you want to add a last_signed_in_at attribute to your User model. You would want to update it when the User signs in.
|
182
|
+
|
183
|
+
Clearance has a method named sign_user_in that you can overwrite with that logic. Be sure to call sign_in(user) at the end (and write tests!).
|
184
|
+
|
185
|
+
class ApplicationController < ActionController::Base
|
186
|
+
include Clearance::App::Controllers::ApplicationController
|
187
|
+
|
188
|
+
private
|
189
|
+
|
190
|
+
def sign_user_in(user)
|
191
|
+
# store current time to display "last signed in at" message
|
192
|
+
user.update_attribute(:last_signed_in_at, Time.now)
|
193
|
+
sign_in(user)
|
194
|
+
end
|
195
|
+
end
|
196
|
+
|
197
|
+
h2. Authors
|
198
|
+
|
199
|
+
* thoughtbot, inc.
|
200
|
+
* Dan Croak
|
201
|
+
* Mike Burns
|
202
|
+
* Jason Morrison
|
203
|
+
* Eugene Bolshakov
|
204
|
+
* Josh Nichols
|
205
|
+
* Mike Breen
|
data/Rakefile
ADDED
@@ -0,0 +1,53 @@
|
|
1
|
+
require 'rake'
|
2
|
+
require 'rake/testtask'
|
3
|
+
|
4
|
+
test_files_pattern = 'test/rails_root/test/{unit,functional,other}/**/*_test.rb'
|
5
|
+
namespace :test do
|
6
|
+
Rake::TestTask.new(:all => ['generator:cleanup', 'generator:generate']) do |task|
|
7
|
+
task.libs << 'lib'
|
8
|
+
task.pattern = test_files_pattern
|
9
|
+
task.verbose = false
|
10
|
+
end
|
11
|
+
end
|
12
|
+
|
13
|
+
namespace :generator do
|
14
|
+
desc "Cleans up the test app before running the generator"
|
15
|
+
task :cleanup do
|
16
|
+
FileList["generators/clearance/templates/**/*.*"].each do |each|
|
17
|
+
file = "test/rails_root/#{each.gsub("generators/clearance/templates/",'')}"
|
18
|
+
File.delete(file) if File.exists?(file)
|
19
|
+
end
|
20
|
+
|
21
|
+
FileUtils.rm_rf("test/rails_root/db/migrate")
|
22
|
+
FileUtils.rm_rf("test/rails_root/vendor/plugins/clearance")
|
23
|
+
system "mkdir -p test/rails_root/vendor/plugins/clearance"
|
24
|
+
system "cp -R generators test/rails_root/vendor/plugins/clearance"
|
25
|
+
end
|
26
|
+
|
27
|
+
desc "Run the generator on the tests"
|
28
|
+
task :generate do
|
29
|
+
system "cd test/rails_root && ./script/generate clearance"
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
33
|
+
desc "Run the test suite"
|
34
|
+
task :default => 'test:all'
|
35
|
+
|
36
|
+
gem_spec = Gem::Specification.new do |gem_spec|
|
37
|
+
gem_spec.name = "clearance"
|
38
|
+
gem_spec.version = "0.4.1"
|
39
|
+
gem_spec.summary = "Rails authentication for developers who write tests."
|
40
|
+
gem_spec.email = "support@thoughtbot.com"
|
41
|
+
gem_spec.homepage = "http://github.com/thoughtbot/clearance"
|
42
|
+
gem_spec.description = "Simple, complete Rails authentication scheme."
|
43
|
+
gem_spec.authors = ["thoughtbot, inc.", "Dan Croak", "Mike Burns", "Jason Morrison",
|
44
|
+
"Eugene Bolshakov", "Josh Nichols", "Mike Breen"]
|
45
|
+
gem_spec.files = FileList["[A-Z]*", "{generators,lib,shoulda_macros,rails}/**/*"]
|
46
|
+
end
|
47
|
+
|
48
|
+
desc "Generate a gemspec file"
|
49
|
+
task :gemspec do
|
50
|
+
File.open("#{gem_spec.name}.gemspec", 'w') do |f|
|
51
|
+
f.write gem_spec.to_yaml
|
52
|
+
end
|
53
|
+
end
|
data/TODO.textile
ADDED
@@ -0,0 +1,8 @@
|
|
1
|
+
(highest priority first)
|
2
|
+
|
3
|
+
# refactor password controller test
|
4
|
+
# existing_user? methods ... if salt is wrong, user may not be found b/c of invalid credentials. is :not_found the correct code to return in that use case? if not, method probably needs to be split into another conditional.
|
5
|
+
# document shoulda macros
|
6
|
+
# will SHA512 hashes fit in all the places they are being used? (db columns - fit now, sessions) 128 characters
|
7
|
+
|
8
|
+
http://adam.speaksoutofturn.com/post/57615195/entication-vs-orization
|
@@ -0,0 +1 @@
|
|
1
|
+
script/generate clearance
|
@@ -0,0 +1,92 @@
|
|
1
|
+
require File.expand_path(File.dirname(__FILE__) + "/lib/insert_commands.rb")
|
2
|
+
require File.expand_path(File.dirname(__FILE__) + "/lib/rake_commands.rb")
|
3
|
+
require 'factory_girl'
|
4
|
+
|
5
|
+
class ClearanceGenerator < Rails::Generator::Base
|
6
|
+
|
7
|
+
def manifest
|
8
|
+
record do |m|
|
9
|
+
m.directory File.join("app", "controllers")
|
10
|
+
file = "app/controllers/application.rb"
|
11
|
+
if File.exists?(file)
|
12
|
+
m.insert_into file, "include Clearance::App::Controllers::ApplicationController"
|
13
|
+
else
|
14
|
+
m.file file, file
|
15
|
+
end
|
16
|
+
|
17
|
+
["app/controllers/confirmations_controller.rb",
|
18
|
+
"app/controllers/passwords_controller.rb",
|
19
|
+
"app/controllers/sessions_controller.rb",
|
20
|
+
"app/controllers/users_controller.rb"].each do |file|
|
21
|
+
m.file file, file
|
22
|
+
end
|
23
|
+
|
24
|
+
m.directory File.join("app", "models")
|
25
|
+
["app/models/user.rb", "app/models/clearance_mailer.rb"].each do |file|
|
26
|
+
m.file file, file
|
27
|
+
end
|
28
|
+
|
29
|
+
m.directory File.join("app", "views")
|
30
|
+
|
31
|
+
m.directory File.join("app", "views", "passwords")
|
32
|
+
["app/views/passwords/new.html.erb",
|
33
|
+
"app/views/passwords/edit.html.erb"].each do |file|
|
34
|
+
m.file file, file
|
35
|
+
end
|
36
|
+
|
37
|
+
m.directory File.join("app", "views", "sessions")
|
38
|
+
["app/views/sessions/new.html.erb"].each do |file|
|
39
|
+
m.file file, file
|
40
|
+
end
|
41
|
+
|
42
|
+
m.directory File.join("app", "views", "clearance_mailer")
|
43
|
+
["app/views/clearance_mailer/change_password.html.erb",
|
44
|
+
"app/views/clearance_mailer/confirmation.html.erb"].each do |file|
|
45
|
+
m.file file, file
|
46
|
+
end
|
47
|
+
|
48
|
+
m.directory File.join("app", "views", "users")
|
49
|
+
["app/views/users/_form.html.erb",
|
50
|
+
"app/views/users/edit.html.erb",
|
51
|
+
"app/views/users/new.html.erb"].each do |file|
|
52
|
+
m.file file, file
|
53
|
+
end
|
54
|
+
|
55
|
+
m.directory File.join("test", "functional")
|
56
|
+
["test/functional/confirmations_controller_test.rb",
|
57
|
+
"test/functional/passwords_controller_test.rb",
|
58
|
+
"test/functional/sessions_controller_test.rb",
|
59
|
+
"test/functional/users_controller_test.rb"].each do |file|
|
60
|
+
m.file file, file
|
61
|
+
end
|
62
|
+
|
63
|
+
m.directory File.join("test", "unit")
|
64
|
+
["test/unit/clearance_mailer_test.rb",
|
65
|
+
"test/unit/user_test.rb"].each do |file|
|
66
|
+
m.file file, file
|
67
|
+
end
|
68
|
+
|
69
|
+
m.directory File.join("test", "factories")
|
70
|
+
["test/factories/clearance.rb"].each do |file|
|
71
|
+
m.file file, file
|
72
|
+
end
|
73
|
+
|
74
|
+
m.route_resources ':passwords'
|
75
|
+
m.route_resource ':session'
|
76
|
+
m.route_resources ':users, :has_one => [:password, :confirmation]'
|
77
|
+
|
78
|
+
if ActiveRecord::Base.connection.table_exists?(:users)
|
79
|
+
m.migration_template 'db/migrate/update_users_with_clearance_columns.rb',
|
80
|
+
'db/migrate', :migration_file_name => 'create_or_update_users_with_clearance_columns'
|
81
|
+
else
|
82
|
+
m.migration_template 'db/migrate/create_users_with_clearance_columns.rb',
|
83
|
+
'db/migrate', :migration_file_name => 'create_or_update_users_with_clearance_columns'
|
84
|
+
end
|
85
|
+
|
86
|
+
m.rake_db_migrate
|
87
|
+
|
88
|
+
m.readme "README"
|
89
|
+
end
|
90
|
+
end
|
91
|
+
|
92
|
+
end
|
@@ -0,0 +1,103 @@
|
|
1
|
+
# Mostly pinched from http://github.com/ryanb/nifty-generators/tree/master
|
2
|
+
|
3
|
+
Rails::Generator::Commands::Base.class_eval do
|
4
|
+
def file_contains?(relative_destination, line)
|
5
|
+
File.read(destination_path(relative_destination)).include?(line)
|
6
|
+
end
|
7
|
+
end
|
8
|
+
|
9
|
+
Rails::Generator::Commands::Create.class_eval do
|
10
|
+
|
11
|
+
def route_resources(resource_list)
|
12
|
+
sentinel = 'ActionController::Routing::Routes.draw do |map|'
|
13
|
+
|
14
|
+
logger.route "map.resources #{resource_list}"
|
15
|
+
unless options[:pretend] || file_contains?('config/routes.rb', resource_list)
|
16
|
+
gsub_file 'config/routes.rb', /(#{Regexp.escape(sentinel)})/mi do |match|
|
17
|
+
"#{match}\n map.resources #{resource_list}"
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
def route_resource(resource_list)
|
23
|
+
sentinel = 'ActionController::Routing::Routes.draw do |map|'
|
24
|
+
|
25
|
+
logger.route "map.resource #{resource_list}"
|
26
|
+
unless options[:pretend] || file_contains?('config/routes.rb', resource_list)
|
27
|
+
gsub_file 'config/routes.rb', /(#{Regexp.escape(sentinel)})/mi do |match|
|
28
|
+
"#{match}\n map.resource #{resource_list}"
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
33
|
+
def route_name(name, path, route_options = {})
|
34
|
+
sentinel = 'ActionController::Routing::Routes.draw do |map|'
|
35
|
+
|
36
|
+
logger.route "map.#{name} '#{path}', :controller => '#{route_options[:controller]}', :action => '#{route_options[:action]}'"
|
37
|
+
unless options[:pretend]
|
38
|
+
gsub_file_once 'config/routes.rb', /(#{Regexp.escape(sentinel)})/mi do |match|
|
39
|
+
"#{match}\n map.#{name} '#{path}', :controller => '#{route_options[:controller]}', :action => '#{route_options[:action]}'"
|
40
|
+
end
|
41
|
+
end
|
42
|
+
end
|
43
|
+
|
44
|
+
def insert_into(file, line)
|
45
|
+
logger.insert "#{line} into #{file}"
|
46
|
+
unless options[:pretend] || file_contains?(file, line)
|
47
|
+
gsub_file file, /^(class|module) .+$/ do |match|
|
48
|
+
"#{match}\n #{line}"
|
49
|
+
end
|
50
|
+
end
|
51
|
+
end
|
52
|
+
end
|
53
|
+
|
54
|
+
Rails::Generator::Commands::Destroy.class_eval do
|
55
|
+
def route_resource(resource_list)
|
56
|
+
look_for = " map.resource #{resource_list}\n".gsub(/[\[\]]/, '\\\\\0')
|
57
|
+
logger.route "map.resource #{resource_list} #{look_for}"
|
58
|
+
unless options[:pretend]
|
59
|
+
gsub_file 'config/routes.rb', /(#{look_for})/mi, ''
|
60
|
+
end
|
61
|
+
end
|
62
|
+
|
63
|
+
def route_resources(resource_list)
|
64
|
+
look_for = " map.resources #{resource_list}\n".gsub(/[\[\]]/, '\\\\\0')
|
65
|
+
logger.route "map.resources #{resource_list} #{look_for}"
|
66
|
+
unless options[:pretend]
|
67
|
+
gsub_file 'config/routes.rb', /(#{look_for})/mi, ''
|
68
|
+
end
|
69
|
+
end
|
70
|
+
|
71
|
+
def route_name(name, path, route_options = {})
|
72
|
+
look_for = "\n map.#{name} '#{path}', :controller => '#{route_options[:controller]}', :action => '#{route_options[:action]}'"
|
73
|
+
logger.route "map.#{name} '#{path}', :controller => '#{route_options[:controller]}', :action => '#{route_options[:action]}'"
|
74
|
+
unless options[:pretend]
|
75
|
+
gsub_file 'config/routes.rb', /(#{look_for})/mi, ''
|
76
|
+
end
|
77
|
+
end
|
78
|
+
|
79
|
+
def insert_into(file, line)
|
80
|
+
logger.remove "#{line} from #{file}"
|
81
|
+
unless options[:pretend]
|
82
|
+
gsub_file file, "\n #{line}", ''
|
83
|
+
end
|
84
|
+
end
|
85
|
+
end
|
86
|
+
|
87
|
+
Rails::Generator::Commands::List.class_eval do
|
88
|
+
def route_resource(resources_list)
|
89
|
+
logger.route "map.resource #{resource_list}"
|
90
|
+
end
|
91
|
+
|
92
|
+
def route_resources(resources_list)
|
93
|
+
logger.route "map.resource #{resource_list}"
|
94
|
+
end
|
95
|
+
|
96
|
+
def route_name(name, path, options = {})
|
97
|
+
logger.route "map.#{name} '#{path}', :controller => '{options[:controller]}', :action => '#{options[:action]}'"
|
98
|
+
end
|
99
|
+
|
100
|
+
def insert_into(file, line)
|
101
|
+
logger.insert "#{line} into #{file}"
|
102
|
+
end
|
103
|
+
end
|
@@ -0,0 +1,22 @@
|
|
1
|
+
Rails::Generator::Commands::Create.class_eval do
|
2
|
+
def rake_db_migrate
|
3
|
+
logger.rake "db:migrate"
|
4
|
+
unless system("rake db:migrate")
|
5
|
+
logger.rake "db:migrate failed. Rolling back"
|
6
|
+
command(:destroy).invoke!
|
7
|
+
end
|
8
|
+
end
|
9
|
+
end
|
10
|
+
|
11
|
+
Rails::Generator::Commands::Destroy.class_eval do
|
12
|
+
def rake_db_migrate
|
13
|
+
logger.rake "db:rollback"
|
14
|
+
system "rake db:rollback"
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
18
|
+
Rails::Generator::Commands::List.class_eval do
|
19
|
+
def rake_db_migrate
|
20
|
+
logger.rake "db:migrate"
|
21
|
+
end
|
22
|
+
end
|
@@ -0,0 +1,54 @@
|
|
1
|
+
|
2
|
+
*******************************************************************************
|
3
|
+
|
4
|
+
Ok, enough fancy automatic stuff. Time for some old school monkey copy-pasting.
|
5
|
+
|
6
|
+
1. For any other file(s) that you already had and didn't want to overwrite, add
|
7
|
+
the corresponding Clearance module. They are namespaced exactly like the
|
8
|
+
directory structure of a Rails app.
|
9
|
+
|
10
|
+
Application controller example:
|
11
|
+
|
12
|
+
class ApplicationController < ActionController::Base
|
13
|
+
include Clearance::App::Controllers::ApplicationController
|
14
|
+
end
|
15
|
+
|
16
|
+
User model example:
|
17
|
+
|
18
|
+
class User < ActiveRecord::Base
|
19
|
+
include Clearance::App::Models::User
|
20
|
+
end
|
21
|
+
|
22
|
+
User test example:
|
23
|
+
|
24
|
+
class UserTest < Test::Unit::TestCase
|
25
|
+
include Clearance::Test::Unit::UserTest
|
26
|
+
end
|
27
|
+
|
28
|
+
2. You need to define HOST constant in your environments files.
|
29
|
+
In config/environments/test.rb and config/environments/development.rb it can be:
|
30
|
+
|
31
|
+
HOST = "localhost"
|
32
|
+
|
33
|
+
In production.rb it must be the actual host your application is deployed to.
|
34
|
+
The constant is used by mailers to generate URLs in emails.
|
35
|
+
|
36
|
+
In config/environment.rb:
|
37
|
+
|
38
|
+
DO_NOT_REPLY = "donotreply@example.com"
|
39
|
+
|
40
|
+
3. Clearance depends on root_url, so please make sure that it is defined to
|
41
|
+
*something* your config/routes.rb:
|
42
|
+
|
43
|
+
map.root :controller => 'home'
|
44
|
+
|
45
|
+
4. To run tests you need to add the Clearance module to your
|
46
|
+
test/test_helper.rb:
|
47
|
+
|
48
|
+
class Test::Unit::TestCase
|
49
|
+
self.use_transactional_fixtures = true
|
50
|
+
self.use_instantiated_fixtures = false
|
51
|
+
include Clearance::Test::TestHelper
|
52
|
+
end
|
53
|
+
|
54
|
+
*******************************************************************************
|
@@ -0,0 +1,10 @@
|
|
1
|
+
Someone, hopefully you, has requested that we send you a link to change your password.
|
2
|
+
|
3
|
+
Here's the link:
|
4
|
+
|
5
|
+
<%= edit_user_password_url(@user,
|
6
|
+
:email => @user.email,
|
7
|
+
:password => @user.encrypted_password,
|
8
|
+
:escape => false) %>
|
9
|
+
|
10
|
+
If you didn't request this, don't worry: your password hasn't been changed. You can just ignore this email.
|
@@ -0,0 +1 @@
|
|
1
|
+
<%= new_user_confirmation_url :user_id => @user, :salt => @user.salt %>
|
@@ -0,0 +1,25 @@
|
|
1
|
+
<h2>Change your password</h2>
|
2
|
+
|
3
|
+
<p>
|
4
|
+
Your password has been reset. Choose a new password below.
|
5
|
+
</p>
|
6
|
+
|
7
|
+
<%= error_messages_for :user %>
|
8
|
+
|
9
|
+
<% form_for(:user,
|
10
|
+
:url => user_password_path(@user,
|
11
|
+
:email => @user.email,
|
12
|
+
:password => @user.encrypted_password),
|
13
|
+
:html => { :method => :put }) do |form| %>
|
14
|
+
<div class="password_field">
|
15
|
+
<%= form.label :password, "Choose password" %>
|
16
|
+
<%= form.password_field :password %>
|
17
|
+
</div>
|
18
|
+
<div class="password_field">
|
19
|
+
<%= form.label :password_confirmation, "Verify password" %>
|
20
|
+
<%= form.password_field :password_confirmation %>
|
21
|
+
</div>
|
22
|
+
<div class="submit_field">
|
23
|
+
<%= form.submit "Save this password", :disable_with => "Please wait..." %>
|
24
|
+
</div>
|
25
|
+
<% end %>
|
@@ -0,0 +1,15 @@
|
|
1
|
+
<h2>Change your password</h2>
|
2
|
+
|
3
|
+
<p>
|
4
|
+
We will email you a link to change your password.
|
5
|
+
</p>
|
6
|
+
|
7
|
+
<% form_for :password, :url => passwords_path do |form| %>
|
8
|
+
<div class="text_field">
|
9
|
+
<%= form.label :email, "Email address" %>
|
10
|
+
<%= form.text_field :email %>
|
11
|
+
</div>
|
12
|
+
<div class="submit_field">
|
13
|
+
<%= form.submit "Reset password", :disable_with => "Please wait..." %>
|
14
|
+
</div>
|
15
|
+
<% end %>
|