activerain-clearance 0.6.6
Sign up to get free protection for your applications and to get access to all the features.
- data/CHANGELOG.textile +144 -0
- data/LICENSE +21 -0
- data/README.textile +125 -0
- data/Rakefile +73 -0
- data/TODO.textile +6 -0
- data/app/controllers/clearance/confirmations_controller.rb +48 -0
- data/app/controllers/clearance/passwords_controller.rb +69 -0
- data/app/controllers/clearance/sessions_controller.rb +50 -0
- data/app/controllers/clearance/users_controller.rb +31 -0
- data/app/models/clearance_mailer.rb +23 -0
- data/app/views/clearance_mailer/change_password.html.erb +7 -0
- data/app/views/clearance_mailer/confirmation.html.erb +2 -0
- data/app/views/passwords/edit.html.erb +23 -0
- data/app/views/passwords/new.html.erb +15 -0
- data/app/views/sessions/new.html.erb +28 -0
- data/app/views/users/_form.html.erb +13 -0
- data/app/views/users/new.html.erb +6 -0
- data/config/clearance_routes.rb +19 -0
- data/generators/clearance/USAGE +1 -0
- data/generators/clearance/clearance_generator.rb +41 -0
- data/generators/clearance/lib/insert_commands.rb +103 -0
- data/generators/clearance/lib/rake_commands.rb +22 -0
- data/generators/clearance/templates/README +22 -0
- data/generators/clearance/templates/factories.rb +13 -0
- data/generators/clearance/templates/migrations/create_users.rb +20 -0
- data/generators/clearance/templates/migrations/update_users.rb +41 -0
- data/generators/clearance/templates/user.rb +3 -0
- data/generators/clearance_features/USAGE +1 -0
- data/generators/clearance_features/clearance_features_generator.rb +20 -0
- data/generators/clearance_features/templates/features/password_reset.feature +33 -0
- data/generators/clearance_features/templates/features/sign_in.feature +42 -0
- data/generators/clearance_features/templates/features/sign_out.feature +23 -0
- data/generators/clearance_features/templates/features/sign_up.feature +28 -0
- data/generators/clearance_features/templates/features/step_definitions/clearance_steps.rb +110 -0
- data/generators/clearance_features/templates/features/step_definitions/factory_girl_steps.rb +5 -0
- data/generators/clearance_features/templates/features/support/paths.rb +22 -0
- data/lib/clearance/authentication.rb +96 -0
- data/lib/clearance/extensions/errors.rb +4 -0
- data/lib/clearance/extensions/rescue.rb +1 -0
- data/lib/clearance/user.rb +143 -0
- data/lib/clearance.rb +6 -0
- data/rails/init.rb +1 -0
- data/shoulda_macros/clearance.rb +261 -0
- metadata +129 -0
data/CHANGELOG.textile
ADDED
@@ -0,0 +1,144 @@
|
|
1
|
+
h2. 0.6.6 (5/18/2009)
|
2
|
+
|
3
|
+
* [#14] replaced class_eval in Clearance::User with modules. This was needed
|
4
|
+
in a thoughtbot client app so we could write our own validations. (Dan Croak)
|
5
|
+
|
6
|
+
h2. 0.6.5 (5/17/2009)
|
7
|
+
|
8
|
+
* [#6] Make Clearance i18n aware. (Timur Vafin, Marcel Goerner, Eugene Bolshakov, Dan Croak)
|
9
|
+
|
10
|
+
h2. 0.6.4 (05/12/2009)
|
11
|
+
|
12
|
+
* Moved issue tracking to Github from Lighthouse. (Dan Croak)
|
13
|
+
* [#7] asking higher-level questions of controllers in webrat steps, such as signed_in? instead of what's in the session. same for accessors. (Dan Croak)
|
14
|
+
* [#11] replacing sign_in_as & sign_out shoulda macros with a stubbing (requires no dependency) approach. this will avoid dealing with the internals of current_user, such as session & cookies. added sign_in macro which signs in an email confirmed user from clearance's factories. (Dan Croak)
|
15
|
+
* [#13] move private methods on sessions controller into Clearance::Authentication module (Dan Croak)
|
16
|
+
* [#9] audited flash keys. (Dan Croak)
|
17
|
+
|
18
|
+
h2. 0.6.3 (04/23/2009)
|
19
|
+
|
20
|
+
* Scoping ClearanceMailer properly within controllers so it works in production environments. (Nick Quaranto)
|
21
|
+
|
22
|
+
h2. 0.6.2 (04/22/2009)
|
23
|
+
|
24
|
+
* Insert Clearance::User into User model if it exists. (Nick Quaranto)
|
25
|
+
* World(NavigationHelpers) Cucumber 3.0 style. (Shay Arnett & Mark Cornick)
|
26
|
+
|
27
|
+
h2. 0.6.1 (04/21/2009)
|
28
|
+
* Scope operators are necessary to keep Rails happy. Reverting the original
|
29
|
+
revert so they're back in the library now for constants referenced inside of
|
30
|
+
the gem. (Nick Quaranto)
|
31
|
+
|
32
|
+
h2. 0.6.0 (04/21/2009)
|
33
|
+
|
34
|
+
* Converted Clearance to a Rails engine. (Dan Croak & Joe Ferris)
|
35
|
+
* Include Clearance::User in User model in app. (Dan Croak & Joe Ferris)
|
36
|
+
* Include Clearance::Authentication in ApplicationController. (Dan Croak & Joe Ferris)
|
37
|
+
* Namespace controllers under Clearance. (Dan Croak & Joe Ferris)
|
38
|
+
* Routes move to engine, use namespaced controllers but publicly the same. (Dan Croak & Joe Ferris)
|
39
|
+
* If you want to override a controller, subclass it like SessionsController <
|
40
|
+
Clearance::SessionsController. This gives you access to usual hooks such as
|
41
|
+
url_after_create. (Dan Croak & Joe Ferris)
|
42
|
+
* Controllers, mailer, model, routes all unit tested inside engine. Use
|
43
|
+
script/generate clearance_features to test integration of Clearance with your
|
44
|
+
Rails app. No longer including modules in your app's test files. (Dan Croak & Joe Ferris)
|
45
|
+
* Moved views to engine. (Joe Ferris)
|
46
|
+
* Converted generated test/factories/clearance.rb to use inheritence for
|
47
|
+
email_confirmed_user. (Dan Croak)
|
48
|
+
* Corrected some spelling errors with methods (Nick Quaranto)
|
49
|
+
* Converted "I should see error messages" to use a regex in the features (Nick
|
50
|
+
Quaranto)
|
51
|
+
* Loading clearance routes after rails routes via some monkeypatching (Nick
|
52
|
+
Quaranto)
|
53
|
+
* Made the clearance controllers unloadable to stop constant loading errors in
|
54
|
+
development mode (Nick Quaranto)
|
55
|
+
|
56
|
+
h2. 0.5.6 (4/11/2009)
|
57
|
+
|
58
|
+
* [#57] Step definition changed for "User should see error messages" so
|
59
|
+
features won't fail for certain validations. (Nick Quaranto)
|
60
|
+
|
61
|
+
h2. 0.5.5 (3/23/2009)
|
62
|
+
|
63
|
+
* Removing duplicate test to get rid of warning. (Nick Quaranto)
|
64
|
+
|
65
|
+
h2. 0.5.4 (3/21/2009)
|
66
|
+
|
67
|
+
* When users fail logging in, redirect them instead of rendering. (Matt
|
68
|
+
Jankowski)
|
69
|
+
|
70
|
+
h2. 0.5.3 (3/5/2009)
|
71
|
+
|
72
|
+
* Clearance now works with (and requires) Shoulda 2.10.0. (Mark Cornick, Joe
|
73
|
+
Ferris, Dan Croak)
|
74
|
+
* Prefer flat over nested contexts in sessions_controller_test. (Joe Ferris,
|
75
|
+
Dan Croak)
|
76
|
+
|
77
|
+
h2. 0.5.2 (3/2/2009)
|
78
|
+
|
79
|
+
* Fixed last remaining errors in Rails 2.3 tests. Now fully compatible. (Joe
|
80
|
+
Ferris, Dan Croak)
|
81
|
+
|
82
|
+
h2. 0.5.1 (2/27/2009)
|
83
|
+
|
84
|
+
* [#46] A user with unconfirmed email who resets password now confirms email.
|
85
|
+
(Marcel Görner)
|
86
|
+
* Refactored user_from_cookie, user_from_session, User#authenticate to use
|
87
|
+
more direct return code instead of ugly, harder to read ternary. (Dan Croak)
|
88
|
+
* Switch order of cookies and sessions to take advantage of Rails 2.3's "Rack-based lazy-loaded sessions":http://is.gd/i23E. (Dan Croak)
|
89
|
+
* Altered generator to interact with application_controller.rb instead of
|
90
|
+
application.rb in Rails 2.3 apps. (Dan Croak)
|
91
|
+
* [#42] Bug fix. Rack-based session change altered how to test remember me
|
92
|
+
cookie. (Mihai Anca)
|
93
|
+
|
94
|
+
h2. 0.5.0 (2/27/2009)
|
95
|
+
|
96
|
+
* Fixed problem with Cucumber features. (Dan Croak)
|
97
|
+
* Fixed mising HTTP fluency use case. (Dan Croak)
|
98
|
+
* Refactored User#update_password to take just parameters it needs. (Dan
|
99
|
+
Croak)
|
100
|
+
* Refactored User unit tests to be more readable. (Dan Croak)
|
101
|
+
|
102
|
+
h2. 0.4.9 (2/20/2009)
|
103
|
+
|
104
|
+
* Protect passwords & confirmations actions with forbidden filters. (Dan Croak)
|
105
|
+
* Return 403 Forbidden status code in those cases. (Tim Pope)
|
106
|
+
* Test 403 Forbidden status code in Cucumber feature. (Dan Croak, Joe Ferris)
|
107
|
+
* Raise custom ActionController::Forbidden error internally. (Joe Ferris, Mike Burns, Jason Morrison)
|
108
|
+
* Test ActionController::Forbidden error is raised in functional test. (Joe Ferris, Mike Burns, Dan Croak)
|
109
|
+
* [#45] Fixed bug that allowed anyone to edit another user's password (Marcel Görner)
|
110
|
+
* Required Factory Girl >= 1.2.0. (Dan Croak)
|
111
|
+
|
112
|
+
h2. 0.4.8 (2/16/2009)
|
113
|
+
|
114
|
+
* Added support paths for Cucumber. (Ben Mabey)
|
115
|
+
* Added documentation for the flash. (Ben Mabey)
|
116
|
+
* Generators require "test_helper" instead of File.join. for rr compatibility. (Joe Ferris)
|
117
|
+
* Removed interpolated email address from flash message to make i18n easier. (Bence Nagy)
|
118
|
+
* Standardized flash messages that refer to email delivery. (Dan Croak)
|
119
|
+
|
120
|
+
h2. 0.4.7 (2/12/2009)
|
121
|
+
|
122
|
+
* Removed Clearance::Test::TestHelper so there is one less setup step. (Dan Croak)
|
123
|
+
* All test helpers now in shoulda_macros. (Dan Croak)
|
124
|
+
|
125
|
+
h2. 0.4.6 (2/11/2009)
|
126
|
+
|
127
|
+
* Made the modules behave like mixins again. (hat-tip Eloy Duran)
|
128
|
+
* Created Actions and PrivateMethods modules on controllers for future RDoc reasons. (Dan Croak, Joe Ferris)
|
129
|
+
|
130
|
+
h2. 0.4.5 (2/9/2009)
|
131
|
+
|
132
|
+
* [#43] Removed email downcasing because local-part is case sensitive per RFC5321. (Dan Croak)
|
133
|
+
* [#42] Removed dependency on Mocha. (Dan Croak)
|
134
|
+
* Required Shoulda >= 2.9.1. (Dan Croak)
|
135
|
+
* Added password reset feature to clearance_features generator. (Eugene Bolshakov, Dan Croak)
|
136
|
+
* Removed unnecessary session[:salt]. (Dan Croak)
|
137
|
+
* [#41] Only store location for session[:return_to] for GET requests. (Dan Croak)
|
138
|
+
* Audited "sign up" naming convention. "Register" had slipped in a few places. (Dan Croak)
|
139
|
+
* Switched to SHA1 encryption. Cypher doesn't matter much for email confirmation, password reset. Better to have shorter hashes in the emails for clients who line break on 72 chars. (Dan Croak)
|
140
|
+
|
141
|
+
h2. 0.4.4 (2/2/2009)
|
142
|
+
|
143
|
+
* Added a generator for Cucumber features. (Joe Ferris, Dan Croak)
|
144
|
+
* Standarized naming for "Sign up," "Sign in," and "Sign out". (Dan Croak)
|
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,125 @@
|
|
1
|
+
h1. Clearance
|
2
|
+
|
3
|
+
Rails authentication with email & password.
|
4
|
+
|
5
|
+
"We have clearance, Clarence.":http://www.youtube.com/v/mNRXJEE3Nz8
|
6
|
+
|
7
|
+
h2. Wiki
|
8
|
+
|
9
|
+
Most information regarding Clearance is on the "Github Wiki":http://wiki.github.com/thoughtbot/clearance.
|
10
|
+
|
11
|
+
h2. Engine
|
12
|
+
|
13
|
+
Clearance is a Rails engine. It works with versions of Rails greater than 2.3.
|
14
|
+
|
15
|
+
In config/environment.rb:
|
16
|
+
|
17
|
+
<pre>
|
18
|
+
config.gem "thoughtbot-clearance",
|
19
|
+
:lib => 'clearance',
|
20
|
+
:source => 'http://gems.github.com',
|
21
|
+
:version => '0.6.4'
|
22
|
+
</pre>
|
23
|
+
|
24
|
+
Vendor the gem:
|
25
|
+
|
26
|
+
<pre>
|
27
|
+
rake gems:install
|
28
|
+
rake gems:unpack
|
29
|
+
</pre>
|
30
|
+
|
31
|
+
Make sure the development database exists and run the generator:
|
32
|
+
|
33
|
+
@script/generate clearance@
|
34
|
+
|
35
|
+
A number of files will be created and instructions will be printed.
|
36
|
+
|
37
|
+
You may already have some of these files. Don't worry. You'll be asked if you want to overwrite them.
|
38
|
+
|
39
|
+
Run the migration:
|
40
|
+
|
41
|
+
@rake db:migrate@
|
42
|
+
|
43
|
+
h2. Environment
|
44
|
+
|
45
|
+
Define a HOST constant in your environment files.
|
46
|
+
In config/environments/test.rb and config/environments/development.rb it can be:
|
47
|
+
|
48
|
+
@HOST = "localhost"@
|
49
|
+
|
50
|
+
In production.rb it must be the actual host your application is deployed to.
|
51
|
+
The constant is used by mailers to generate URLs in emails.
|
52
|
+
|
53
|
+
In config/environment.rb:
|
54
|
+
|
55
|
+
@DO_NOT_REPLY = "donotreply@example.com"@
|
56
|
+
|
57
|
+
Define root_url to *something* in your config/routes.rb:
|
58
|
+
|
59
|
+
@map.root :controller => 'home'@
|
60
|
+
|
61
|
+
h2. Cucumber Features
|
62
|
+
|
63
|
+
As your app evolves, you want to know that authentication still works. Clearance's opinion is that you should test its integration with your app using "Cucumber":http://cukes.info/.
|
64
|
+
|
65
|
+
In config/environments/test.rb:
|
66
|
+
|
67
|
+
<pre>
|
68
|
+
config.gem 'webrat',
|
69
|
+
:version => '= 0.4.4'
|
70
|
+
config.gem 'cucumber',
|
71
|
+
:version => '= 0.3.0'
|
72
|
+
config.gem 'thoughtbot-factory_girl',
|
73
|
+
:lib => 'factory_girl',
|
74
|
+
:source => "http://gems.github.com",
|
75
|
+
:version => '1.2.1'
|
76
|
+
</pre>
|
77
|
+
|
78
|
+
Vendor the gems:
|
79
|
+
|
80
|
+
<pre>
|
81
|
+
rake gems:install RAILS_ENV=test
|
82
|
+
rake gems:unpack RAILS_ENV=test
|
83
|
+
</pre>
|
84
|
+
|
85
|
+
Don't vendor nokogiri (due to its native extensions):
|
86
|
+
|
87
|
+
@rm -rf vendor/gems/nokogiri-1.2.3@
|
88
|
+
|
89
|
+
Run the Cucumber generator (if you haven't already) and Clearance's feature generator:
|
90
|
+
|
91
|
+
<pre>
|
92
|
+
script/generate cucumber
|
93
|
+
script/generate clearance_features
|
94
|
+
</pre>
|
95
|
+
|
96
|
+
All of the files generated should be new with the exception of the features/support/paths.rb file. If you have not modified your paths.rb then you will be okay to replace it with this one. If you need to keep your paths.rb file then add these locations in your paths.rb manually:
|
97
|
+
|
98
|
+
<pre>
|
99
|
+
def path_to(page_name)
|
100
|
+
case page_name
|
101
|
+
...
|
102
|
+
when /the sign up page/i
|
103
|
+
new_user_path
|
104
|
+
when /the sign in page/i
|
105
|
+
new_session_path
|
106
|
+
when /the password reset request page/i
|
107
|
+
new_password_path
|
108
|
+
...
|
109
|
+
end
|
110
|
+
</pre>
|
111
|
+
|
112
|
+
h2. Authors
|
113
|
+
|
114
|
+
Clearance was extracted out of "Hoptoad":http://hoptoadapp.com. We merged the authentication code from two of thoughtbot's client's Rails apps and have since used it each time we need authentication. The following people have improved the library. Thank you!
|
115
|
+
|
116
|
+
Dan Croak, Mike Burns, Jason Morrison, Joe Ferris, Eugene Bolshakov, Nick Quaranto, Josh Nichols, Mike Breen, Marcel Görner, Bence Nagy, Ben Mabey, Eloy Duran, Tim Pope, Mihai Anca, Mark Cornick, & Shay Arnett.
|
117
|
+
|
118
|
+
h2. Questions?
|
119
|
+
|
120
|
+
Ask the "mailing list":http://groups.google.com/group/thoughtbot-clearance
|
121
|
+
|
122
|
+
h2. Suggestions, Bugs, Refactoring?
|
123
|
+
|
124
|
+
Fork away and create a "Github Issue":http://github.com/thoughtbot/clearance/issues. Please don't send pull requests.
|
125
|
+
|
data/Rakefile
ADDED
@@ -0,0 +1,73 @@
|
|
1
|
+
require 'rake'
|
2
|
+
require 'rake/testtask'
|
3
|
+
require 'cucumber/rake/task'
|
4
|
+
|
5
|
+
namespace :test do
|
6
|
+
Rake::TestTask.new(:all => ["generator:cleanup",
|
7
|
+
"generator:generate"]) do |task|
|
8
|
+
task.libs << "lib"
|
9
|
+
task.libs << "test"
|
10
|
+
task.pattern = "test/**/*_test.rb"
|
11
|
+
task.verbose = false
|
12
|
+
end
|
13
|
+
|
14
|
+
Cucumber::Rake::Task.new(:features) do |t|
|
15
|
+
t.cucumber_opts = "--format progress"
|
16
|
+
t.feature_pattern = "test/rails_root/features/*.feature"
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
generators = %w(clearance clearance_features)
|
21
|
+
|
22
|
+
namespace :generator do
|
23
|
+
desc "Cleans up the test app before running the generator"
|
24
|
+
task :cleanup do
|
25
|
+
generators.each do |generator|
|
26
|
+
FileList["generators/#{generator}/templates/**/*.*"].each do |each|
|
27
|
+
file = "test/rails_root/#{each.gsub("generators/#{generator}/templates/",'')}"
|
28
|
+
File.delete(file) if File.exists?(file)
|
29
|
+
end
|
30
|
+
end
|
31
|
+
|
32
|
+
FileList["test/rails_root/db/**/*"].each do |each|
|
33
|
+
FileUtils.rm_rf(each)
|
34
|
+
end
|
35
|
+
FileUtils.rm_rf("test/rails_root/vendor/plugins/clearance")
|
36
|
+
FileUtils.mkdir_p("test/rails_root/vendor/plugins")
|
37
|
+
clearance_root = File.expand_path(File.dirname(__FILE__))
|
38
|
+
system("ln -s #{clearance_root} test/rails_root/vendor/plugins/clearance")
|
39
|
+
end
|
40
|
+
|
41
|
+
desc "Run the generator on the tests"
|
42
|
+
task :generate do
|
43
|
+
generators.each do |generator|
|
44
|
+
system "cd test/rails_root && ./script/generate #{generator} && rake db:migrate db:test:prepare"
|
45
|
+
end
|
46
|
+
end
|
47
|
+
end
|
48
|
+
|
49
|
+
desc "Run the test suite"
|
50
|
+
task :default => ['test:all', 'test:features']
|
51
|
+
|
52
|
+
gem_spec = Gem::Specification.new do |gem_spec|
|
53
|
+
gem_spec.name = "clearance"
|
54
|
+
gem_spec.version = "0.6.6"
|
55
|
+
gem_spec.summary = "Rails authentication with email & password."
|
56
|
+
gem_spec.email = "support@thoughtbot.com"
|
57
|
+
gem_spec.homepage = "http://github.com/thoughtbot/clearance"
|
58
|
+
gem_spec.description = "Rails authentication with email & password."
|
59
|
+
gem_spec.authors = ["Dan Croak", "Mike Burns", "Jason Morrison",
|
60
|
+
"Joe Ferris", "Eugene Bolshakov", "Nick Quaranto",
|
61
|
+
"Josh Nichols", "Mike Breen", "Marcel Görner",
|
62
|
+
"Bence Nagy", "Ben Mabey", "Eloy Duran",
|
63
|
+
"Tim Pope", "Mihai Anca", "Mark Cornick",
|
64
|
+
"Shay Arnett"]
|
65
|
+
gem_spec.files = FileList["[A-Z]*", "{app,config,generators,lib,shoulda_macros,rails}/**/*"]
|
66
|
+
end
|
67
|
+
|
68
|
+
desc "Generate a gemspec file"
|
69
|
+
task :gemspec do
|
70
|
+
File.open("#{gem_spec.name}.gemspec", 'w') do |f|
|
71
|
+
f.write gem_spec.to_yaml
|
72
|
+
end
|
73
|
+
end
|
data/TODO.textile
ADDED
@@ -0,0 +1,48 @@
|
|
1
|
+
class Clearance::ConfirmationsController < ApplicationController
|
2
|
+
unloadable
|
3
|
+
|
4
|
+
before_filter :forbid_confirmed_user, :only => :new
|
5
|
+
before_filter :forbid_missing_token, :only => :new
|
6
|
+
before_filter :forbid_non_existent_user, :only => :new
|
7
|
+
filter_parameter_logging :token
|
8
|
+
|
9
|
+
def new
|
10
|
+
create
|
11
|
+
end
|
12
|
+
|
13
|
+
def create
|
14
|
+
@user = ::User.find_by_id_and_token(params[:user_id], params[:token])
|
15
|
+
@user.confirm_email!
|
16
|
+
|
17
|
+
sign_user_in(@user)
|
18
|
+
flash[:success] = translate(:confirmed_email,
|
19
|
+
:scope => [:clearance, :controllers, :confirmations],
|
20
|
+
:default => "Confirmed email and signed in.")
|
21
|
+
redirect_to url_after_create
|
22
|
+
end
|
23
|
+
|
24
|
+
private
|
25
|
+
|
26
|
+
def forbid_confirmed_user
|
27
|
+
user = ::User.find_by_id(params[:user_id])
|
28
|
+
if user && user.email_confirmed?
|
29
|
+
raise ActionController::Forbidden, "confirmed user"
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
33
|
+
def forbid_missing_token
|
34
|
+
if params[:token].blank?
|
35
|
+
raise ActionController::Forbidden, "missing token"
|
36
|
+
end
|
37
|
+
end
|
38
|
+
|
39
|
+
def forbid_non_existent_user
|
40
|
+
unless ::User.find_by_id_and_token(params[:user_id], params[:token])
|
41
|
+
raise ActionController::Forbidden, "non-existent user"
|
42
|
+
end
|
43
|
+
end
|
44
|
+
|
45
|
+
def url_after_create
|
46
|
+
root_url
|
47
|
+
end
|
48
|
+
end
|
@@ -0,0 +1,69 @@
|
|
1
|
+
class Clearance::PasswordsController < ApplicationController
|
2
|
+
unloadable
|
3
|
+
|
4
|
+
before_filter :forbid_missing_token, :only => [:edit, :update]
|
5
|
+
before_filter :forbid_non_existent_user, :only => [:edit, :update]
|
6
|
+
filter_parameter_logging :password, :password_confirmation
|
7
|
+
|
8
|
+
def new
|
9
|
+
render :template => 'passwords/new'
|
10
|
+
end
|
11
|
+
|
12
|
+
def create
|
13
|
+
if user = ::User.find_by_email(params[:password][:email])
|
14
|
+
user.forgot_password!
|
15
|
+
::ClearanceMailer.deliver_change_password user
|
16
|
+
flash[:notice] = translate(:deliver_change_password,
|
17
|
+
:scope => [:clearance, :controllers, :passwords],
|
18
|
+
:default => "You will receive an email within the next few minutes. " <<
|
19
|
+
"It contains instructions for changing your password.")
|
20
|
+
redirect_to url_after_create
|
21
|
+
else
|
22
|
+
flash.now[:failure] = translate(:unknown_email,
|
23
|
+
:scope => [:clearance, :controllers, :passwords],
|
24
|
+
:default => "Unknown email.")
|
25
|
+
render :template => 'passwords/new'
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
29
|
+
def edit
|
30
|
+
@user = ::User.find_by_id_and_token(params[:user_id], params[:token])
|
31
|
+
render :template => 'passwords/edit'
|
32
|
+
end
|
33
|
+
|
34
|
+
def update
|
35
|
+
@user = ::User.find_by_id_and_token(params[:user_id], params[:token])
|
36
|
+
|
37
|
+
if @user.update_password(params[:user][:password],
|
38
|
+
params[:user][:password_confirmation])
|
39
|
+
@user.confirm_email! unless @user.email_confirmed?
|
40
|
+
sign_user_in(@user)
|
41
|
+
flash[:success] = translate(:signed_in, :default => "Signed in.")
|
42
|
+
redirect_to url_after_update
|
43
|
+
else
|
44
|
+
render :template => 'passwords/edit'
|
45
|
+
end
|
46
|
+
end
|
47
|
+
|
48
|
+
private
|
49
|
+
|
50
|
+
def forbid_missing_token
|
51
|
+
if params[:token].blank?
|
52
|
+
raise ActionController::Forbidden, "missing token"
|
53
|
+
end
|
54
|
+
end
|
55
|
+
|
56
|
+
def forbid_non_existent_user
|
57
|
+
unless ::User.find_by_id_and_token(params[:user_id], params[:token])
|
58
|
+
raise ActionController::Forbidden, "non-existent user"
|
59
|
+
end
|
60
|
+
end
|
61
|
+
|
62
|
+
def url_after_create
|
63
|
+
new_session_url
|
64
|
+
end
|
65
|
+
|
66
|
+
def url_after_update
|
67
|
+
root_url
|
68
|
+
end
|
69
|
+
end
|
@@ -0,0 +1,50 @@
|
|
1
|
+
class Clearance::SessionsController < ApplicationController
|
2
|
+
unloadable
|
3
|
+
|
4
|
+
protect_from_forgery :except => :create
|
5
|
+
filter_parameter_logging :password
|
6
|
+
|
7
|
+
def new
|
8
|
+
render :template => 'sessions/new'
|
9
|
+
end
|
10
|
+
|
11
|
+
def create
|
12
|
+
@user = ::User.authenticate(params[:session][:email],
|
13
|
+
params[:session][:password])
|
14
|
+
if @user.nil?
|
15
|
+
flash.now[:failure] = translate(:bad_email_or_password,
|
16
|
+
:scope => [:clearance, :controllers, :sessions],
|
17
|
+
:default => "Bad email or password.")
|
18
|
+
render :template => 'sessions/new', :status => :unauthorized
|
19
|
+
else
|
20
|
+
if @user.email_confirmed?
|
21
|
+
sign_user_in(@user)
|
22
|
+
remember(@user) if remember?
|
23
|
+
flash[:success] = translate(:signed_in, :default => "Signed in.")
|
24
|
+
redirect_back_or url_after_create
|
25
|
+
else
|
26
|
+
::ClearanceMailer.deliver_confirmation(@user)
|
27
|
+
deny_access(translate(:unconfirmed_email,
|
28
|
+
:scope => [:clearance, :controllers, :sessions],
|
29
|
+
:default => "User has not confirmed email. " <<
|
30
|
+
"Confirmation email will be resent."))
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
34
|
+
|
35
|
+
def destroy
|
36
|
+
forget(current_user)
|
37
|
+
flash[:success] = translate(:signed_out, :default => "Signed out.")
|
38
|
+
redirect_to url_after_destroy
|
39
|
+
end
|
40
|
+
|
41
|
+
private
|
42
|
+
|
43
|
+
def url_after_create
|
44
|
+
root_url
|
45
|
+
end
|
46
|
+
|
47
|
+
def url_after_destroy
|
48
|
+
new_session_url
|
49
|
+
end
|
50
|
+
end
|
@@ -0,0 +1,31 @@
|
|
1
|
+
class Clearance::UsersController < ApplicationController
|
2
|
+
unloadable
|
3
|
+
|
4
|
+
before_filter :redirect_to_root, :only => [:new, :create], :if => :signed_in?
|
5
|
+
filter_parameter_logging :password
|
6
|
+
|
7
|
+
def new
|
8
|
+
@user = ::User.new(params[:user])
|
9
|
+
render :template => 'users/new'
|
10
|
+
end
|
11
|
+
|
12
|
+
def create
|
13
|
+
@user = ::User.new params[:user]
|
14
|
+
if @user.save
|
15
|
+
::ClearanceMailer.deliver_confirmation @user
|
16
|
+
flash[:notice] = translate(:deliver_confirmation,
|
17
|
+
:scope => [:clearance, :controllers, :users],
|
18
|
+
:default => "You will receive an email within the next few minutes. " <<
|
19
|
+
"It contains instructions for confirming your account.")
|
20
|
+
redirect_to url_after_create
|
21
|
+
else
|
22
|
+
render :template => 'users/new'
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
private
|
27
|
+
|
28
|
+
def url_after_create
|
29
|
+
new_session_url
|
30
|
+
end
|
31
|
+
end
|
@@ -0,0 +1,23 @@
|
|
1
|
+
class ClearanceMailer < ActionMailer::Base
|
2
|
+
|
3
|
+
default_url_options[:host] = HOST
|
4
|
+
|
5
|
+
def change_password(user)
|
6
|
+
from DO_NOT_REPLY
|
7
|
+
recipients user.email
|
8
|
+
subject I18n.t(:change_password,
|
9
|
+
:scope => [:clearance, :models, :clearance_mailer],
|
10
|
+
:default => "Change your password")
|
11
|
+
body :user => user
|
12
|
+
end
|
13
|
+
|
14
|
+
def confirmation(user)
|
15
|
+
from DO_NOT_REPLY
|
16
|
+
recipients user.email
|
17
|
+
subject I18n.t(:confirmation,
|
18
|
+
:scope => [:clearance, :models, :clearance_mailer],
|
19
|
+
:default => "Account confirmation")
|
20
|
+
body :user => user
|
21
|
+
end
|
22
|
+
|
23
|
+
end
|
@@ -0,0 +1,7 @@
|
|
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, :token => @user.token, :escape => false) %>
|
6
|
+
|
7
|
+
If you didn't request this, ignore this email. Don't worry. Your password hasn't been changed.
|
@@ -0,0 +1,23 @@
|
|
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, :token => @user.token),
|
11
|
+
:html => { :method => :put }) do |form| %>
|
12
|
+
<div class="password_field">
|
13
|
+
<%= form.label :password, "Choose password" %>
|
14
|
+
<%= form.password_field :password %>
|
15
|
+
</div>
|
16
|
+
<div class="password_field">
|
17
|
+
<%= form.label :password_confirmation, "Confirm password" %>
|
18
|
+
<%= form.password_field :password_confirmation %>
|
19
|
+
</div>
|
20
|
+
<div class="submit_field">
|
21
|
+
<%= form.submit "Save this password", :disable_with => "Please wait..." %>
|
22
|
+
</div>
|
23
|
+
<% 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 %>
|
@@ -0,0 +1,28 @@
|
|
1
|
+
<h2>Sign in</h2>
|
2
|
+
|
3
|
+
<% form_for :session, :url => session_path do |form| %>
|
4
|
+
<div class="text_field">
|
5
|
+
<%= form.label :email %>
|
6
|
+
<%= form.text_field :email %>
|
7
|
+
</div>
|
8
|
+
<div class="text_field">
|
9
|
+
<%= form.label :password %>
|
10
|
+
<%= form.password_field :password %>
|
11
|
+
</div>
|
12
|
+
<div class="text_field">
|
13
|
+
<%= form.check_box :remember_me %>
|
14
|
+
<%= form.label :remember_me %>
|
15
|
+
</div>
|
16
|
+
<div class="submit_field">
|
17
|
+
<%= form.submit "Sign in", :disable_with => "Please wait..." %>
|
18
|
+
</div>
|
19
|
+
<% end %>
|
20
|
+
|
21
|
+
<ul>
|
22
|
+
<li>
|
23
|
+
<%= link_to "Sign up", new_user_path %>
|
24
|
+
</li>
|
25
|
+
<li>
|
26
|
+
<%= link_to "Forgot password?", new_password_path %>
|
27
|
+
</li>
|
28
|
+
</ul>
|