vita-clearance 0.6.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (44) hide show
  1. data/CHANGELOG.textile +123 -0
  2. data/LICENSE +21 -0
  3. data/README.textile +109 -0
  4. data/Rakefile +73 -0
  5. data/TODO.textile +6 -0
  6. data/app/controllers/clearance/confirmations_controller.rb +47 -0
  7. data/app/controllers/clearance/passwords_controller.rb +65 -0
  8. data/app/controllers/clearance/sessions_controller.rb +62 -0
  9. data/app/controllers/clearance/users_controller.rb +30 -0
  10. data/app/models/clearance_mailer.rb +19 -0
  11. data/app/views/clearance_mailer/change_password.html.erb +7 -0
  12. data/app/views/clearance_mailer/confirmation.html.erb +2 -0
  13. data/app/views/passwords/edit.html.erb +23 -0
  14. data/app/views/passwords/new.html.erb +15 -0
  15. data/app/views/sessions/new.html.erb +28 -0
  16. data/app/views/users/_form.html.erb +13 -0
  17. data/app/views/users/new.html.erb +6 -0
  18. data/config/clearance_routes.rb +19 -0
  19. data/generators/clearance/USAGE +1 -0
  20. data/generators/clearance/clearance_generator.rb +41 -0
  21. data/generators/clearance/lib/insert_commands.rb +103 -0
  22. data/generators/clearance/lib/rake_commands.rb +22 -0
  23. data/generators/clearance/templates/README +22 -0
  24. data/generators/clearance/templates/factories.rb +13 -0
  25. data/generators/clearance/templates/migrations/create_users.rb +20 -0
  26. data/generators/clearance/templates/migrations/update_users.rb +41 -0
  27. data/generators/clearance/templates/user.rb +3 -0
  28. data/generators/clearance_features/USAGE +1 -0
  29. data/generators/clearance_features/clearance_features_generator.rb +20 -0
  30. data/generators/clearance_features/templates/features/password_reset.feature +31 -0
  31. data/generators/clearance_features/templates/features/sign_in.feature +41 -0
  32. data/generators/clearance_features/templates/features/sign_out.feature +22 -0
  33. data/generators/clearance_features/templates/features/sign_up.feature +30 -0
  34. data/generators/clearance_features/templates/features/step_definitions/clearance_steps.rb +110 -0
  35. data/generators/clearance_features/templates/features/step_definitions/factory_girl_steps.rb +5 -0
  36. data/generators/clearance_features/templates/features/support/paths.rb +22 -0
  37. data/lib/clearance/authentication.rb +80 -0
  38. data/lib/clearance/extensions/errors.rb +4 -0
  39. data/lib/clearance/extensions/rescue.rb +1 -0
  40. data/lib/clearance/user.rb +114 -0
  41. data/lib/clearance.rb +15 -0
  42. data/rails/init.rb +1 -0
  43. data/shoulda_macros/clearance.rb +248 -0
  44. metadata +129 -0
data/CHANGELOG.textile ADDED
@@ -0,0 +1,123 @@
1
+ h2. 0.6.2 (04/22/2009)
2
+
3
+ * Insert Clearance::User into User model if it exists. (Nick Quaranto)
4
+ * World(NavigationHelpers) Cucumber 3.0 style. (Shay Arnett & Mark Cornick)
5
+
6
+ h2. 0.6.1 (04/21/2009)
7
+ * Scope operators are necessary to keep Rails happy. Reverting the original
8
+ revert so they're back in the library now for constants referenced inside of
9
+ the gem. (Nick Quaranto)
10
+
11
+ h2. 0.6.0 (04/21/2009)
12
+
13
+ * Converted Clearance to a Rails engine. (Dan Croak & Joe Ferris)
14
+ * Include Clearance::User in User model in app. (Dan Croak & Joe Ferris)
15
+ * Include Clearance::Authentication in ApplicationController. (Dan Croak & Joe Ferris)
16
+ * Namespace controllers under Clearance. (Dan Croak & Joe Ferris)
17
+ * Routes move to engine, use namespaced controllers but publicly the same. (Dan Croak & Joe Ferris)
18
+ * If you want to override a controller, subclass it like SessionsController <
19
+ Clearance::SessionsController. This gives you access to usual hooks such as
20
+ url_after_create. (Dan Croak & Joe Ferris)
21
+ * Controllers, mailer, model, routes all unit tested inside engine. Use
22
+ script/generate clearance_features to test integration of Clearance with your
23
+ Rails app. No longer including modules in your app's test files. (Dan Croak & Joe Ferris)
24
+ * Moved views to engine. (Joe Ferris)
25
+ * Converted generated test/factories/clearance.rb to use inheritence for
26
+ email_confirmed_user. (Dan Croak)
27
+ * Corrected some spelling errors with methods (Nick Quaranto)
28
+ * Converted "I should see error messages" to use a regex in the features (Nick
29
+ Quaranto)
30
+ * Loading clearance routes after rails routes via some monkeypatching (Nick
31
+ Quaranto)
32
+ * Made the clearance controllers unloadable to stop constant loading errors in
33
+ development mode (Nick Quaranto)
34
+
35
+ h2. 0.5.6 (4/11/2009)
36
+
37
+ * [#57] Step definition changed for "User should see error messages" so
38
+ features won't fail for certain validations. (Nick Quaranto)
39
+
40
+ h2. 0.5.5 (3/23/2009)
41
+
42
+ * Removing duplicate test to get rid of warning. (Nick Quaranto)
43
+
44
+ h2. 0.5.4 (3/21/2009)
45
+
46
+ * When users fail logging in, redirect them instead of rendering. (Matt
47
+ Jankowski)
48
+
49
+ h2. 0.5.3 (3/5/2009)
50
+
51
+ * Clearance now works with (and requires) Shoulda 2.10.0. (Mark Cornick, Joe
52
+ Ferris, Dan Croak)
53
+ * Prefer flat over nested contexts in sessions_controller_test. (Joe Ferris,
54
+ Dan Croak)
55
+
56
+ h2. 0.5.2 (3/2/2009)
57
+
58
+ * Fixed last remaining errors in Rails 2.3 tests. Now fully compatible. (Joe
59
+ Ferris, Dan Croak)
60
+
61
+ h2. 0.5.1 (2/27/2009)
62
+
63
+ * [#46] A user with unconfirmed email who resets password now confirms email.
64
+ (Marcel Görner)
65
+ * Refactored user_from_cookie, user_from_session, User#authenticate to use
66
+ more direct return code instead of ugly, harder to read ternary. (Dan Croak)
67
+ * 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)
68
+ * Altered generator to interact with application_controller.rb instead of
69
+ application.rb in Rails 2.3 apps. (Dan Croak)
70
+ * [#42] Bug fix. Rack-based session change altered how to test remember me
71
+ cookie. (Mihai Anca)
72
+
73
+ h2. 0.5.0 (2/27/2009)
74
+
75
+ * Fixed problem with Cucumber features. (Dan Croak)
76
+ * Fixed mising HTTP fluency use case. (Dan Croak)
77
+ * Refactored User#update_password to take just parameters it needs. (Dan
78
+ Croak)
79
+ * Refactored User unit tests to be more readable. (Dan Croak)
80
+
81
+ h2. 0.4.9 (2/20/2009)
82
+
83
+ * Protect passwords & confirmations actions with forbidden filters. (Dan Croak)
84
+ * Return 403 Forbidden status code in those cases. (Tim Pope)
85
+ * Test 403 Forbidden status code in Cucumber feature. (Dan Croak, Joe Ferris)
86
+ * Raise custom ActionController::Forbidden error internally. (Joe Ferris, Mike Burns, Jason Morrison)
87
+ * Test ActionController::Forbidden error is raised in functional test. (Joe Ferris, Mike Burns, Dan Croak)
88
+ * [#45] Fixed bug that allowed anyone to edit another user's password (Marcel Görner)
89
+ * Required Factory Girl >= 1.2.0. (Dan Croak)
90
+
91
+ h2. 0.4.8 (2/16/2009)
92
+
93
+ * Added support paths for Cucumber. (Ben Mabey)
94
+ * Added documentation for the flash. (Ben Mabey)
95
+ * Generators require "test_helper" instead of File.join. for rr compatibility. (Joe Ferris)
96
+ * Removed interpolated email address from flash message to make i18n easier. (Bence Nagy)
97
+ * Standardized flash messages that refer to email delivery. (Dan Croak)
98
+
99
+ h2. 0.4.7 (2/12/2009)
100
+
101
+ * Removed Clearance::Test::TestHelper so there is one less setup step. (Dan Croak)
102
+ * All test helpers now in shoulda_macros. (Dan Croak)
103
+
104
+ h2. 0.4.6 (2/11/2009)
105
+
106
+ * Made the modules behave like mixins again. (hat-tip Eloy Duran)
107
+ * Created Actions and PrivateMethods modules on controllers for future RDoc reasons. (Dan Croak, Joe Ferris)
108
+
109
+ h2. 0.4.5 (2/9/2009)
110
+
111
+ * [#43] Removed email downcasing because local-part is case sensitive per RFC5321. (Dan Croak)
112
+ * [#42] Removed dependency on Mocha. (Dan Croak)
113
+ * Required Shoulda >= 2.9.1. (Dan Croak)
114
+ * Added password reset feature to clearance_features generator. (Eugene Bolshakov, Dan Croak)
115
+ * Removed unnecessary session[:salt]. (Dan Croak)
116
+ * [#41] Only store location for session[:return_to] for GET requests. (Dan Croak)
117
+ * Audited "sign up" naming convention. "Register" had slipped in a few places. (Dan Croak)
118
+ * 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)
119
+
120
+ h2. 0.4.4 (2/2/2009)
121
+
122
+ * Added a generator for Cucumber features. (Joe Ferris, Dan Croak)
123
+ * 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,109 @@
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
+ config.gem "thoughtbot-clearance",
18
+ :lib => 'clearance',
19
+ :source => 'http://gems.github.com',
20
+ :version => '0.6.2'
21
+
22
+ Vendor the gem:
23
+
24
+ rake gems:install
25
+ rake gems:unpack
26
+
27
+ Make sure the development database exists and run the generator:
28
+
29
+ script/generate clearance
30
+
31
+ A number of files will be created and instructions will be printed.
32
+
33
+ You may already have some of these files. Don't worry. You'll be asked if you want to overwrite them.
34
+
35
+ h2. Environment
36
+
37
+ Define a HOST constant in your environment files.
38
+ In config/environments/test.rb and config/environments/development.rb it can be:
39
+
40
+ HOST = "localhost"
41
+
42
+ In production.rb it must be the actual host your application is deployed to.
43
+ The constant is used by mailers to generate URLs in emails.
44
+
45
+ In config/environment.rb:
46
+
47
+ DO_NOT_REPLY = "donotreply@example.com"
48
+
49
+ Define root_url to *something* in your config/routes.rb:
50
+
51
+ map.root :controller => 'home'
52
+
53
+ h2. Cucumber Features
54
+
55
+ 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/.
56
+
57
+ In config/environments/test.rb:
58
+
59
+ config.gem 'webrat',
60
+ :version => '= 0.4.4'
61
+ config.gem 'cucumber',
62
+ :version => '= 0.3.0'
63
+ config.gem 'thoughtbot-factory_girl',
64
+ :lib => 'factory_girl',
65
+ :source => "http://gems.github.com",
66
+ :version => '1.2.1'
67
+
68
+ Install nokogiri but don't vendor it (due to its native extensions):
69
+
70
+ sudo gem install nokogiri
71
+
72
+ Vendor the gems:
73
+
74
+ rake gems:install RAILS_ENV=test
75
+ rake gems:unpack RAILS_ENV=test
76
+
77
+ Run the Cucumber generator (if you haven't already) and Clearance's feature generator:
78
+
79
+ script/generate cucumber
80
+ script/generate clearance_features
81
+
82
+ 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:
83
+
84
+ def path_to(page_name)
85
+ case page_name
86
+ ...
87
+ when /the sign up page/i
88
+ new_user_path
89
+ when /the sign in page/i
90
+ new_session_path
91
+ when /the password reset request page/i
92
+ new_password_path
93
+ ...
94
+ end
95
+
96
+ h2. Authors
97
+
98
+ Clearance was extracted out of "Hoptoad":http://hoptoadapp.com. We merged the authentication code from two of thoughtbot's client's Rails apps. The following people have made significant contributions, suggestions, and generally improved the library. Thank you!
99
+
100
+ 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.
101
+
102
+ h2. Questions?
103
+
104
+ * Ask the "mailing list":http://groups.google.com/group/thoughtbot-clearance
105
+
106
+ h2. Bugs?
107
+
108
+ * Open up a "Lighthouse ticket":https://thoughtbot.lighthouseapp.com/projects/18503-clearance
109
+
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.2"
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,6 @@
1
+ h1. To-do
2
+
3
+ * Make insertion of Clearance::User into User model automatic from the generator.
4
+ * Change generated README to include instruction about running the migration.
5
+ * DO_NOT_REPLY, HOST refactoring.
6
+
@@ -0,0 +1,47 @@
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] = "Confirmed email and signed in."
19
+ redirect_to url_after_create
20
+ end
21
+
22
+ private
23
+
24
+ def forbid_confirmed_user
25
+ user = ::User.find_by_id(params[:user_id])
26
+ if user && user.email_confirmed?
27
+ raise ActionController::Forbidden, "confirmed user"
28
+ end
29
+ end
30
+
31
+ def forbid_missing_token
32
+ if params[:token].blank?
33
+ raise ActionController::Forbidden, "missing token"
34
+ end
35
+ end
36
+
37
+ def forbid_non_existent_user
38
+ unless ::User.find_by_id_and_token(params[:user_id], params[:token])
39
+ raise ActionController::Forbidden, "non-existent user"
40
+ end
41
+ end
42
+
43
+ def url_after_create
44
+ root_url
45
+ end
46
+
47
+ end
@@ -0,0 +1,65 @@
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] = "You will receive an email within the next few minutes. " <<
17
+ "It contains instructions for changing your password."
18
+ redirect_to url_after_create
19
+ else
20
+ flash.now[:notice] = "Unknown email"
21
+ render :template => 'passwords/new'
22
+ end
23
+ end
24
+
25
+ def edit
26
+ @user = ::User.find_by_id_and_token(params[:user_id], params[:token])
27
+ render :template => 'passwords/edit'
28
+ end
29
+
30
+ def update
31
+ @user = ::User.find_by_id_and_token(params[:user_id], params[:token])
32
+
33
+ if @user.update_password(params[:user][:password],
34
+ params[:user][:password_confirmation])
35
+ @user.confirm_email! unless @user.email_confirmed?
36
+ sign_user_in(@user)
37
+ redirect_to url_after_update
38
+ else
39
+ render :template => 'passwords/edit'
40
+ end
41
+ end
42
+
43
+ private
44
+
45
+ def forbid_missing_token
46
+ if params[:token].blank?
47
+ raise ActionController::Forbidden, "missing token"
48
+ end
49
+ end
50
+
51
+ def forbid_non_existent_user
52
+ unless ::User.find_by_id_and_token(params[:user_id], params[:token])
53
+ raise ActionController::Forbidden, "non-existent user"
54
+ end
55
+ end
56
+
57
+ def url_after_create
58
+ new_session_url
59
+ end
60
+
61
+ def url_after_update
62
+ root_url
63
+ end
64
+
65
+ end
@@ -0,0 +1,62 @@
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[:notice] = "Bad email or password."
16
+ render :template => 'sessions/new', :status => :unauthorized
17
+ else
18
+ if @user.email_confirmed?
19
+ remember(@user) if remember?
20
+ sign_user_in(@user)
21
+ flash[:notice] = "Signed in successfully."
22
+ redirect_back_or url_after_create
23
+ else
24
+ ClearanceMailer.deliver_confirmation(@user)
25
+ deny_access("User has not confirmed email. Confirmation email will be resent.")
26
+ end
27
+ end
28
+ end
29
+
30
+ def destroy
31
+ forget(current_user)
32
+ reset_session
33
+ flash[:notice] = "You have been signed out."
34
+ redirect_to url_after_destroy
35
+ end
36
+
37
+ private
38
+
39
+ def remember?
40
+ params[:session] && params[:session][:remember_me] == "1"
41
+ end
42
+
43
+ def remember(user)
44
+ user.remember_me!
45
+ cookies[:remember_token] = { :value => user.token,
46
+ :expires => user.token_expires_at }
47
+ end
48
+
49
+ def forget(user)
50
+ user.forget_me! if user
51
+ cookies.delete :remember_token
52
+ end
53
+
54
+ def url_after_create
55
+ root_url
56
+ end
57
+
58
+ def url_after_destroy
59
+ new_session_url
60
+ end
61
+
62
+ end
@@ -0,0 +1,30 @@
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] = "You will receive an email within the next few minutes. " <<
17
+ "It contains instructions for confirming your account."
18
+ redirect_to url_after_create
19
+ else
20
+ render :template => 'users/new'
21
+ end
22
+ end
23
+
24
+ private
25
+
26
+ def url_after_create
27
+ new_session_url
28
+ end
29
+
30
+ end
@@ -0,0 +1,19 @@
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 "Change your password"
9
+ body :user => user
10
+ end
11
+
12
+ def confirmation(user)
13
+ from DO_NOT_REPLY
14
+ recipients user.email
15
+ subject "Account confirmation"
16
+ body :user => user
17
+ end
18
+
19
+ 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,2 @@
1
+
2
+ <%= new_user_confirmation_url :user_id => @user, :token => @user.token, :encode => false %>
@@ -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>
@@ -0,0 +1,13 @@
1
+ <%= form.error_messages %>
2
+ <div class="text_field">
3
+ <%= form.label :email %>
4
+ <%= form.text_field :email %>
5
+ </div>
6
+ <div class="password_field">
7
+ <%= form.label :password %>
8
+ <%= form.password_field :password %>
9
+ </div>
10
+ <div class="password_field">
11
+ <%= form.label :password_confirmation, "Confirm password" %>
12
+ <%= form.password_field :password_confirmation %>
13
+ </div>
@@ -0,0 +1,6 @@
1
+ <h2>Sign up</h2>
2
+
3
+ <% form_for @user do |form| %>
4
+ <%= render :partial => '/users/form', :object => form %>
5
+ <%= form.submit 'Sign up', :disable_with => 'Please wait...' %>
6
+ <% end %>