devise 1.0.10 → 1.1.0

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 (176) hide show
  1. data/CHANGELOG.rdoc +62 -10
  2. data/Gemfile +23 -0
  3. data/Gemfile.lock +118 -0
  4. data/README.rdoc +116 -77
  5. data/Rakefile +4 -2
  6. data/TODO +3 -2
  7. data/app/controllers/{confirmations_controller.rb → devise/confirmations_controller.rb} +1 -1
  8. data/app/controllers/{passwords_controller.rb → devise/passwords_controller.rb} +1 -1
  9. data/app/controllers/{registrations_controller.rb → devise/registrations_controller.rb} +12 -8
  10. data/app/controllers/devise/sessions_controller.rb +23 -0
  11. data/app/controllers/{unlocks_controller.rb → devise/unlocks_controller.rb} +1 -8
  12. data/app/helpers/devise_helper.rb +17 -0
  13. data/app/mailers/devise/mailer.rb +71 -0
  14. data/app/views/devise/confirmations/new.html.erb +12 -0
  15. data/app/views/devise/passwords/edit.html.erb +16 -0
  16. data/app/views/devise/passwords/new.html.erb +12 -0
  17. data/app/views/devise/registrations/edit.html.erb +25 -0
  18. data/app/views/devise/registrations/new.html.erb +18 -0
  19. data/app/views/devise/sessions/new.html.erb +17 -0
  20. data/app/views/devise/shared/_links.erb +19 -0
  21. data/app/views/devise/unlocks/new.html.erb +12 -0
  22. data/{lib/devise → config}/locales/en.yml +16 -12
  23. data/lib/devise/controllers/helpers.rb +57 -52
  24. data/lib/devise/controllers/internal_helpers.rb +19 -50
  25. data/lib/devise/controllers/scoped_views.rb +35 -0
  26. data/lib/devise/controllers/url_helpers.rb +1 -1
  27. data/lib/devise/encryptors/authlogic_sha512.rb +0 -2
  28. data/lib/devise/encryptors/base.rb +1 -1
  29. data/lib/devise/encryptors/bcrypt.rb +2 -4
  30. data/lib/devise/encryptors/clearance_sha1.rb +0 -2
  31. data/lib/devise/encryptors/sha1.rb +6 -8
  32. data/lib/devise/encryptors/sha512.rb +6 -8
  33. data/lib/devise/failure_app.rb +76 -39
  34. data/lib/devise/hooks/activatable.rb +6 -10
  35. data/lib/devise/hooks/forgetable.rb +11 -0
  36. data/lib/devise/hooks/rememberable.rb +40 -30
  37. data/lib/devise/hooks/timeoutable.rb +7 -3
  38. data/lib/devise/hooks/trackable.rb +5 -14
  39. data/lib/devise/mapping.rb +35 -62
  40. data/lib/devise/models/authenticatable.rb +126 -0
  41. data/lib/devise/models/confirmable.rb +19 -22
  42. data/lib/devise/models/database_authenticatable.rb +26 -60
  43. data/lib/devise/models/lockable.rb +43 -28
  44. data/lib/devise/models/recoverable.rb +11 -10
  45. data/lib/devise/models/rememberable.rb +56 -26
  46. data/lib/devise/models/timeoutable.rb +1 -3
  47. data/lib/devise/models/token_authenticatable.rb +14 -43
  48. data/lib/devise/models/trackable.rb +14 -0
  49. data/lib/devise/models/validatable.rb +16 -2
  50. data/lib/devise/models.rb +16 -53
  51. data/lib/devise/modules.rb +23 -0
  52. data/lib/devise/orm/active_record.rb +10 -15
  53. data/lib/devise/orm/mongoid.rb +29 -0
  54. data/lib/devise/path_checker.rb +18 -0
  55. data/lib/devise/rails/routes.rb +232 -117
  56. data/lib/devise/rails/warden_compat.rb +18 -39
  57. data/lib/devise/rails.rb +64 -9
  58. data/lib/devise/schema.rb +47 -23
  59. data/lib/devise/strategies/authenticatable.rb +123 -0
  60. data/lib/devise/strategies/base.rb +2 -3
  61. data/lib/devise/strategies/database_authenticatable.rb +7 -22
  62. data/lib/devise/strategies/rememberable.rb +21 -7
  63. data/lib/devise/strategies/token_authenticatable.rb +31 -19
  64. data/lib/devise/test_helpers.rb +6 -6
  65. data/lib/devise/version.rb +1 -1
  66. data/lib/devise.rb +174 -157
  67. data/lib/generators/active_record/devise_generator.rb +28 -0
  68. data/{generators/devise → lib/generators/active_record}/templates/migration.rb +9 -3
  69. data/lib/generators/devise/devise_generator.rb +17 -0
  70. data/lib/generators/devise/install_generator.rb +24 -0
  71. data/lib/generators/devise/orm_helpers.rb +23 -0
  72. data/{generators/devise_install → lib/generators/devise}/templates/README +9 -7
  73. data/lib/generators/devise/templates/devise.rb +142 -0
  74. data/lib/generators/devise/views_generator.rb +63 -0
  75. data/lib/generators/devise_install_generator.rb +4 -0
  76. data/lib/generators/devise_views_generator.rb +4 -0
  77. data/lib/generators/mongoid/devise_generator.rb +17 -0
  78. data/test/controllers/helpers_test.rb +48 -19
  79. data/test/controllers/internal_helpers_test.rb +12 -16
  80. data/test/controllers/url_helpers_test.rb +21 -10
  81. data/test/devise_test.rb +16 -25
  82. data/test/encryptors_test.rb +2 -3
  83. data/test/failure_app_test.rb +106 -27
  84. data/test/integration/authenticatable_test.rb +138 -126
  85. data/test/integration/confirmable_test.rb +22 -15
  86. data/test/integration/database_authenticatable_test.rb +38 -0
  87. data/test/integration/http_authenticatable_test.rb +9 -12
  88. data/test/integration/lockable_test.rb +22 -15
  89. data/test/integration/recoverable_test.rb +6 -6
  90. data/test/integration/registerable_test.rb +42 -33
  91. data/test/integration/rememberable_test.rb +84 -22
  92. data/test/integration/timeoutable_test.rb +16 -4
  93. data/test/integration/token_authenticatable_test.rb +45 -12
  94. data/test/integration/trackable_test.rb +1 -1
  95. data/test/mailers/confirmation_instructions_test.rb +11 -17
  96. data/test/mailers/reset_password_instructions_test.rb +7 -7
  97. data/test/mailers/unlock_instructions_test.rb +7 -7
  98. data/test/mapping_test.rb +22 -95
  99. data/test/models/confirmable_test.rb +12 -19
  100. data/test/models/{authenticatable_test.rb → database_authenticatable_test.rb} +24 -56
  101. data/test/models/lockable_test.rb +32 -46
  102. data/test/models/recoverable_test.rb +7 -7
  103. data/test/models/rememberable_test.rb +118 -35
  104. data/test/models/timeoutable_test.rb +1 -1
  105. data/test/models/token_authenticatable_test.rb +5 -19
  106. data/test/models/trackable_test.rb +1 -1
  107. data/test/models/validatable_test.rb +20 -27
  108. data/test/models_test.rb +12 -5
  109. data/test/orm/active_record.rb +1 -23
  110. data/test/orm/mongoid.rb +10 -0
  111. data/test/rails_app/app/active_record/admin.rb +1 -5
  112. data/test/rails_app/app/active_record/shim.rb +2 -0
  113. data/test/rails_app/app/active_record/user.rb +3 -3
  114. data/test/rails_app/app/controllers/application_controller.rb +2 -5
  115. data/test/rails_app/app/controllers/home_controller.rb +3 -0
  116. data/test/rails_app/app/controllers/publisher/registrations_controller.rb +2 -0
  117. data/test/rails_app/app/controllers/publisher/sessions_controller.rb +2 -0
  118. data/test/rails_app/app/controllers/sessions_controller.rb +6 -0
  119. data/test/rails_app/app/controllers/users_controller.rb +7 -5
  120. data/test/rails_app/app/mongoid/admin.rb +6 -0
  121. data/test/rails_app/app/mongoid/shim.rb +16 -0
  122. data/test/rails_app/app/mongoid/user.rb +10 -0
  123. data/test/rails_app/config/application.rb +35 -0
  124. data/test/rails_app/config/boot.rb +10 -107
  125. data/test/rails_app/config/environment.rb +4 -41
  126. data/test/rails_app/config/environments/development.rb +15 -13
  127. data/test/rails_app/config/environments/production.rb +25 -20
  128. data/test/rails_app/config/environments/test.rb +33 -28
  129. data/test/rails_app/config/initializers/backtrace_silencers.rb +7 -0
  130. data/test/rails_app/config/initializers/devise.rb +95 -38
  131. data/test/rails_app/config/initializers/secret_token.rb +2 -0
  132. data/test/rails_app/config/routes.rb +47 -25
  133. data/test/rails_app/db/migrate/20100401102949_create_tables.rb +27 -0
  134. data/test/rails_app/db/schema.rb +86 -0
  135. data/test/routes_test.rb +62 -47
  136. data/test/support/{assertions_helper.rb → assertions.rb} +2 -15
  137. data/test/support/{tests_helper.rb → helpers.rb} +18 -3
  138. data/test/support/{integration_tests_helper.rb → integration.rb} +24 -7
  139. data/test/support/webrat/integrations/rails.rb +32 -0
  140. data/test/test_helper.rb +11 -11
  141. data/test/test_helpers_test.rb +30 -15
  142. metadata +105 -64
  143. data/app/controllers/sessions_controller.rb +0 -42
  144. data/app/models/devise_mailer.rb +0 -68
  145. data/app/views/confirmations/new.html.erb +0 -12
  146. data/app/views/passwords/edit.html.erb +0 -16
  147. data/app/views/passwords/new.html.erb +0 -12
  148. data/app/views/registrations/edit.html.erb +0 -25
  149. data/app/views/registrations/new.html.erb +0 -17
  150. data/app/views/sessions/new.html.erb +0 -17
  151. data/app/views/shared/_devise_links.erb +0 -19
  152. data/app/views/unlocks/new.html.erb +0 -12
  153. data/generators/devise/USAGE +0 -5
  154. data/generators/devise/devise_generator.rb +0 -15
  155. data/generators/devise/lib/route_devise.rb +0 -32
  156. data/generators/devise/templates/model.rb +0 -9
  157. data/generators/devise_install/USAGE +0 -3
  158. data/generators/devise_install/devise_install_generator.rb +0 -15
  159. data/generators/devise_install/templates/devise.rb +0 -105
  160. data/generators/devise_views/USAGE +0 -3
  161. data/generators/devise_views/devise_views_generator.rb +0 -21
  162. data/lib/devise/models/activatable.rb +0 -16
  163. data/lib/devise/models/http_authenticatable.rb +0 -23
  164. data/lib/devise/orm/data_mapper.rb +0 -83
  165. data/lib/devise/orm/mongo_mapper.rb +0 -52
  166. data/lib/devise/strategies/http_authenticatable.rb +0 -59
  167. data/rails/init.rb +0 -2
  168. data/test/integration/rack_middleware_test.rb +0 -47
  169. data/test/orm/mongo_mapper.rb +0 -20
  170. data/test/rails_app/app/mongo_mapper/admin.rb +0 -13
  171. data/test/rails_app/app/mongo_mapper/user.rb +0 -14
  172. data/test/rails_app/config/initializers/new_rails_defaults.rb +0 -24
  173. data/test/rails_app/config/initializers/session_store.rb +0 -15
  174. /data/app/views/{devise_mailer → devise/mailer}/confirmation_instructions.html.erb +0 -0
  175. /data/app/views/{devise_mailer → devise/mailer}/reset_password_instructions.html.erb +0 -0
  176. /data/app/views/{devise_mailer → devise/mailer}/unlock_instructions.html.erb +0 -0
@@ -1,15 +1,15 @@
1
- class RegistrationsController < ApplicationController
1
+ class Devise::RegistrationsController < ApplicationController
2
2
  prepend_before_filter :require_no_authentication, :only => [ :new, :create ]
3
3
  prepend_before_filter :authenticate_scope!, :only => [:edit, :update, :destroy]
4
4
  include Devise::Controllers::InternalHelpers
5
5
 
6
6
  # GET /resource/sign_up
7
7
  def new
8
- build_resource
8
+ build_resource({})
9
9
  render_with_scope :new
10
10
  end
11
11
 
12
- # POST /resource
12
+ # POST /resource/sign_up
13
13
  def create
14
14
  build_resource
15
15
 
@@ -17,6 +17,7 @@ class RegistrationsController < ApplicationController
17
17
  set_flash_message :notice, :signed_up
18
18
  sign_in_and_redirect(resource_name, resource)
19
19
  else
20
+ clean_up_passwords(resource)
20
21
  render_with_scope :new
21
22
  end
22
23
  end
@@ -28,26 +29,29 @@ class RegistrationsController < ApplicationController
28
29
 
29
30
  # PUT /resource
30
31
  def update
31
- if self.resource.update_with_password(params[resource_name])
32
+ if resource.update_with_password(params[resource_name])
32
33
  set_flash_message :notice, :updated
33
- redirect_to after_sign_in_path_for(self.resource)
34
+ redirect_to after_update_path_for(resource)
34
35
  else
36
+ clean_up_passwords(resource)
35
37
  render_with_scope :edit
36
38
  end
37
39
  end
38
40
 
39
41
  # DELETE /resource
40
42
  def destroy
41
- self.resource.destroy
43
+ resource.destroy
42
44
  set_flash_message :notice, :destroyed
43
45
  sign_out_and_redirect(self.resource)
44
46
  end
45
47
 
46
48
  protected
47
49
 
48
- # Authenticates the current scope and dup the resource
50
+ # Authenticates the current scope and gets a copy of the current resource.
51
+ # We need to use a copy because we don't want actions like update changing
52
+ # the current user in place.
49
53
  def authenticate_scope!
50
54
  send(:"authenticate_#{resource_name}!")
51
- self.resource = send(:"current_#{resource_name}").dup
55
+ self.resource = resource_class.find(send(:"current_#{resource_name}").id)
52
56
  end
53
57
  end
@@ -0,0 +1,23 @@
1
+ class Devise::SessionsController < ApplicationController
2
+ prepend_before_filter :require_no_authentication, :only => [ :new, :create ]
3
+ include Devise::Controllers::InternalHelpers
4
+
5
+ # GET /resource/sign_in
6
+ def new
7
+ clean_up_passwords(build_resource)
8
+ render_with_scope :new
9
+ end
10
+
11
+ # POST /resource/sign_in
12
+ def create
13
+ resource = warden.authenticate!(:scope => resource_name, :recall => "new")
14
+ set_flash_message :notice, :signed_in
15
+ sign_in_and_redirect(resource_name, resource)
16
+ end
17
+
18
+ # GET /resource/sign_out
19
+ def destroy
20
+ set_flash_message :notice, :signed_out if signed_in?(resource_name)
21
+ sign_out_and_redirect(resource_name)
22
+ end
23
+ end
@@ -1,5 +1,4 @@
1
- class UnlocksController < ApplicationController
2
- prepend_before_filter :ensure_email_as_unlock_strategy
1
+ class Devise::UnlocksController < ApplicationController
3
2
  prepend_before_filter :require_no_authentication
4
3
  include Devise::Controllers::InternalHelpers
5
4
 
@@ -32,10 +31,4 @@ class UnlocksController < ApplicationController
32
31
  render_with_scope :new
33
32
  end
34
33
  end
35
-
36
- protected
37
-
38
- def ensure_email_as_unlock_strategy
39
- raise ActionController::UnknownAction unless resource_class.unlock_strategy_enabled?(:email)
40
- end
41
34
  end
@@ -0,0 +1,17 @@
1
+ module DeviseHelper
2
+ def devise_error_messages!
3
+ return "" if resource.errors.empty?
4
+
5
+ messages = resource.errors.full_messages.map { |msg| content_tag(:li, msg) }.join
6
+ sentence = "#{pluralize(resource.errors.count, "error")} prohibited this #{resource_name} from being saved:"
7
+
8
+ html = <<-HTML
9
+ <div id="error_explanation">
10
+ <h2>#{sentence}</h2>
11
+ <ul>#{messages}</ul>
12
+ </div>
13
+ HTML
14
+
15
+ html.html_safe
16
+ end
17
+ end
@@ -0,0 +1,71 @@
1
+ class Devise::Mailer < ::ActionMailer::Base
2
+ include Devise::Controllers::ScopedViews
3
+ attr_reader :devise_mapping, :resource
4
+
5
+ def confirmation_instructions(record)
6
+ setup_mail(record, :confirmation_instructions)
7
+ end
8
+
9
+ def reset_password_instructions(record)
10
+ setup_mail(record, :reset_password_instructions)
11
+ end
12
+
13
+ def unlock_instructions(record)
14
+ setup_mail(record, :unlock_instructions)
15
+ end
16
+
17
+ private
18
+
19
+ # Configure default email options
20
+ def setup_mail(record, action)
21
+ @scope_name = Devise::Mapping.find_scope!(record)
22
+ @devise_mapping = Devise.mappings[@scope_name]
23
+ @resource = instance_variable_set("@#{@devise_mapping.name}", record)
24
+
25
+ headers = {
26
+ :subject => translate(@devise_mapping, action),
27
+ :from => mailer_sender(@devise_mapping),
28
+ :to => record.email,
29
+ :template_path => template_paths
30
+ }
31
+
32
+ headers.merge!(record.headers_for(action)) if record.respond_to?(:headers_for)
33
+ mail(headers)
34
+ end
35
+
36
+ def mailer_sender(mapping)
37
+ if Devise.mailer_sender.is_a?(Proc)
38
+ Devise.mailer_sender.call(mapping.name)
39
+ else
40
+ Devise.mailer_sender
41
+ end
42
+ end
43
+
44
+ def template_paths
45
+ template_path = [self.class.mailer_name]
46
+ template_path.unshift "#{@devise_mapping.plural}/mailer" if self.class.scoped_views?
47
+ template_path
48
+ end
49
+
50
+ # Setup a subject doing an I18n lookup. At first, it attemps to set a subject
51
+ # based on the current mapping:
52
+ #
53
+ # en:
54
+ # devise:
55
+ # mailer:
56
+ # confirmation_instructions:
57
+ # user_subject: '...'
58
+ #
59
+ # If one does not exist, it fallbacks to ActionMailer default:
60
+ #
61
+ # en:
62
+ # devise:
63
+ # mailer:
64
+ # confirmation_instructions:
65
+ # subject: '...'
66
+ #
67
+ def translate(mapping, key)
68
+ I18n.t(:"#{mapping.name}_subject", :scope => [:devise, :mailer, key],
69
+ :default => [:subject, key.to_s.humanize])
70
+ end
71
+ end
@@ -0,0 +1,12 @@
1
+ <h2>Resend confirmation instructions</h2>
2
+
3
+ <%= form_for(resource, :as => resource_name, :url => confirmation_path(resource_name), :html => { :method => :post }) do |f| %>
4
+ <%= devise_error_messages! %>
5
+
6
+ <p><%= f.label :email %><br />
7
+ <%= f.text_field :email %></p>
8
+
9
+ <p><%= f.submit "Resend confirmation instructions" %></p>
10
+ <% end %>
11
+
12
+ <%= render :partial => "devise/shared/links" %>
@@ -0,0 +1,16 @@
1
+ <h2>Change your password</h2>
2
+
3
+ <%= form_for(resource, :as => resource_name, :url => password_path(resource_name), :html => { :method => :put }) do |f| %>
4
+ <%= devise_error_messages! %>
5
+ <%= f.hidden_field :reset_password_token %>
6
+
7
+ <p><%= f.label :password %><br />
8
+ <%= f.password_field :password %></p>
9
+
10
+ <p><%= f.label :password_confirmation %><br />
11
+ <%= f.password_field :password_confirmation %></p>
12
+
13
+ <p><%= f.submit "Change my password" %></p>
14
+ <% end %>
15
+
16
+ <%= render :partial => "devise/shared/links" %>
@@ -0,0 +1,12 @@
1
+ <h2>Forgot your password?</h2>
2
+
3
+ <%= form_for(resource, :as => resource_name, :url => password_path(resource_name), :html => { :method => :post }) do |f| %>
4
+ <%= devise_error_messages! %>
5
+
6
+ <p><%= f.label :email %><br />
7
+ <%= f.text_field :email %></p>
8
+
9
+ <p><%= f.submit "Send me reset password instructions" %></p>
10
+ <% end %>
11
+
12
+ <%= render :partial => "devise/shared/links" %>
@@ -0,0 +1,25 @@
1
+ <h2>Edit <%= resource_name.to_s.humanize %></h2>
2
+
3
+ <%= form_for(resource, :as => resource_name, :url => registration_path(resource_name), :html => { :method => :put }) do |f| %>
4
+ <%= devise_error_messages! %>
5
+
6
+ <p><%= f.label :email %><br />
7
+ <%= f.text_field :email %></p>
8
+
9
+ <p><%= f.label :password %> <i>(leave blank if you don't want to change it)</i><br />
10
+ <%= f.password_field :password %></p>
11
+
12
+ <p><%= f.label :password_confirmation %><br />
13
+ <%= f.password_field :password_confirmation %></p>
14
+
15
+ <p><%= f.label :current_password %> <i>(we need your current password to confirm your changes)</i><br />
16
+ <%= f.password_field :current_password %></p>
17
+
18
+ <p><%= f.submit "Update" %></p>
19
+ <% end %>
20
+
21
+ <h3>Cancel my account</h3>
22
+
23
+ <p>Unhappy? <%= link_to "Cancel my account", registration_path(resource_name), :confirm => "Are you sure?", :method => :delete %>.</p>
24
+
25
+ <%= link_to "Back", :back %>
@@ -0,0 +1,18 @@
1
+ <h2>Sign up</h2>
2
+
3
+ <%= form_for(resource, :as => resource_name, :url => registration_path(resource_name)) do |f| %>
4
+ <%= devise_error_messages! %>
5
+
6
+ <p><%= f.label :email %><br />
7
+ <%= f.text_field :email %></p>
8
+
9
+ <p><%= f.label :password %><br />
10
+ <%= f.password_field :password %></p>
11
+
12
+ <p><%= f.label :password_confirmation %><br />
13
+ <%= f.password_field :password_confirmation %></p>
14
+
15
+ <p><%= f.submit "Sign up" %></p>
16
+ <% end %>
17
+
18
+ <%= render :partial => "devise/shared/links" %>
@@ -0,0 +1,17 @@
1
+ <h2>Sign in</h2>
2
+
3
+ <%= form_for(resource, :as => resource_name, :url => session_path(resource_name)) do |f| %>
4
+ <p><%= f.label :email %><br />
5
+ <%= f.text_field :email %></p>
6
+
7
+ <p><%= f.label :password %><br />
8
+ <%= f.password_field :password %></p>
9
+
10
+ <% if devise_mapping.rememberable? -%>
11
+ <p><%= f.check_box :remember_me %> <%= f.label :remember_me %></p>
12
+ <% end -%>
13
+
14
+ <p><%= f.submit "Sign in" %></p>
15
+ <% end %>
16
+
17
+ <%= render :partial => "devise/shared/links" %>
@@ -0,0 +1,19 @@
1
+ <%- if controller_name != 'sessions' %>
2
+ <%= link_to "Sign in", new_session_path(resource_name) %><br />
3
+ <% end -%>
4
+
5
+ <%- if devise_mapping.registerable? && controller_name != 'registrations' %>
6
+ <%= link_to "Sign up", new_registration_path(resource_name) %><br />
7
+ <% end -%>
8
+
9
+ <%- if devise_mapping.recoverable? && controller_name != 'passwords' %>
10
+ <%= link_to "Forgot your password?", new_password_path(resource_name) %><br />
11
+ <% end -%>
12
+
13
+ <%- if devise_mapping.confirmable? && controller_name != 'confirmations' %>
14
+ <%= link_to "Didn't receive confirmation instructions?", new_confirmation_path(resource_name) %><br />
15
+ <% end -%>
16
+
17
+ <%- if devise_mapping.lockable? && resource_class.unlock_strategy_enabled?(:email) && controller_name != 'unlocks' %>
18
+ <%= link_to "Didn't receive unlock instructions?", new_unlock_path(resource_name) %><br />
19
+ <% end -%>
@@ -0,0 +1,12 @@
1
+ <h2>Resend unlock instructions</h2>
2
+
3
+ <%= form_for(resource, :as => resource_name, :url => unlock_path(resource_name), :html => { :method => :post }) do |f| %>
4
+ <%= devise_error_messages! %>
5
+
6
+ <p><%= f.label :email %><br />
7
+ <%= f.text_field :email %></p>
8
+
9
+ <p><%= f.submit "Resend unlock instructions" %></p>
10
+ <% end %>
11
+
12
+ <%= render :partial => "devise/shared/links" %>
@@ -1,9 +1,12 @@
1
1
  en:
2
+ errors:
3
+ messages:
4
+ not_found: "not found"
5
+ already_confirmed: "was already confirmed"
6
+ not_locked: "was not locked"
7
+
2
8
  devise:
3
- sessions:
4
- link: 'Sign in'
5
- signed_in: 'Signed in successfully.'
6
- signed_out: 'Signed out successfully.'
9
+ failure:
7
10
  unauthenticated: 'You need to sign in or sign up before continuing.'
8
11
  unconfirmed: 'You have to confirm your account before continuing.'
9
12
  locked: 'Your account is locked.'
@@ -11,25 +14,26 @@ en:
11
14
  invalid_token: 'Invalid authentication token.'
12
15
  timeout: 'Your session expired, please sign in again to continue.'
13
16
  inactive: 'Your account was not activated yet.'
17
+ sessions:
18
+ signed_in: 'Signed in successfully.'
19
+ signed_out: 'Signed out successfully.'
14
20
  passwords:
15
- link: 'Forgot password?'
16
21
  send_instructions: 'You will receive an email with instructions about how to reset your password in a few minutes.'
17
22
  updated: 'Your password was changed successfully. You are now signed in.'
18
23
  confirmations:
19
- link: "Didn't receive confirmation instructions?"
20
24
  send_instructions: 'You will receive an email with instructions about how to confirm your account in a few minutes.'
21
25
  confirmed: 'Your account was successfully confirmed. You are now signed in.'
22
26
  registrations:
23
- link: 'Sign up'
24
27
  signed_up: 'You have signed up successfully. If enabled, a confirmation was sent to your e-mail.'
25
28
  updated: 'You updated your account successfully.'
26
29
  destroyed: 'Bye! Your account was successfully cancelled. We hope to see you again soon.'
27
30
  unlocks:
28
- link: "Didn't receive unlock instructions?"
29
31
  send_instructions: 'You will receive an email with instructions about how to unlock your account in a few minutes.'
30
32
  unlocked: 'Your account was successfully unlocked. You are now signed in.'
31
33
  mailer:
32
- confirmation_instructions: 'Confirmation instructions'
33
- reset_password_instructions: 'Reset password instructions'
34
- unlock_instructions: 'Unlock Instructions'
35
-
34
+ confirmation_instructions:
35
+ subject: 'Confirmation instructions'
36
+ reset_password_instructions:
37
+ subject: 'Reset password instructions'
38
+ unlock_instructions:
39
+ subject: 'Unlock Instructions'
@@ -2,18 +2,11 @@ module Devise
2
2
  module Controllers
3
3
  # Those helpers are convenience methods added to ApplicationController.
4
4
  module Helpers
5
+ extend ActiveSupport::Concern
5
6
 
6
- def self.included(base)
7
- base.class_eval do
8
- helper_method :warden, :signed_in?, :devise_controller?, :anybody_signed_in?,
9
- *Devise.mappings.keys.map { |m| [:"current_#{m}", :"#{m}_signed_in?", :"#{m}_session"] }.flatten
10
-
11
- # Use devise default_url_options. We have to declare it here to overwrite
12
- # default definitions.
13
- def default_url_options(options=nil)
14
- Devise::Mapping.default_url_options
15
- end
16
- end
7
+ included do
8
+ helper_method :warden, :signed_in?, :devise_controller?, :anybody_signed_in?,
9
+ *Devise.mappings.keys.map { |m| [:"current_#{m}", :"#{m}_signed_in?", :"#{m}_session"] }.flatten
17
10
  end
18
11
 
19
12
  # The main accessor for the warden proxy instance
@@ -30,18 +23,6 @@ module Devise
30
23
  false
31
24
  end
32
25
 
33
- # Attempts to authenticate the given scope by running authentication hooks,
34
- # but does not redirect in case of failures.
35
- def authenticate(scope)
36
- warden.authenticate(:scope => scope)
37
- end
38
-
39
- # Attempts to authenticate the given scope by running authentication hooks,
40
- # redirecting in case of failures.
41
- def authenticate!(scope)
42
- warden.authenticate!(:scope => scope)
43
- end
44
-
45
26
  # Check if the given scope is signed in session, without running
46
27
  # authentication hooks.
47
28
  def signed_in?(scope)
@@ -66,7 +47,6 @@ module Devise
66
47
  scope = Devise::Mapping.find_scope!(resource_or_scope)
67
48
  resource ||= resource_or_scope
68
49
  warden.set_user(resource, :scope => scope)
69
- @_session = request.session # Recalculate session
70
50
  end
71
51
 
72
52
  # Sign out a given user or scope. This helper is useful for signing out an user
@@ -84,6 +64,16 @@ module Devise
84
64
  warden.logout(scope)
85
65
  end
86
66
 
67
+ # Sign out all active users or scopes. This helper is useful for signing out all roles
68
+ # in one click.
69
+ def sign_out_all_scopes
70
+ # Not "warden.logout" since we need to sign_out only devise-defined scopes.
71
+ scopes = Devise.mappings.keys
72
+ scopes.each { |scope| warden.user(scope) }
73
+ warden.raw_session.inspect
74
+ warden.logout(*scopes)
75
+ end
76
+
87
77
  # Returns and delete the url stored in the session for the given scope. Useful
88
78
  # for giving redirect backs after sign up:
89
79
  #
@@ -93,8 +83,7 @@ module Devise
93
83
  #
94
84
  def stored_location_for(resource_or_scope)
95
85
  scope = Devise::Mapping.find_scope!(resource_or_scope)
96
- key = "#{scope}.return_to"
97
- session.delete(key) || session.delete(key.to_sym)
86
+ session.delete(:"#{scope}_return_to")
98
87
  end
99
88
 
100
89
  # The default url to be used after signing in. This is used by all Devise
@@ -125,10 +114,40 @@ module Devise
125
114
  #
126
115
  def after_sign_in_path_for(resource_or_scope)
127
116
  scope = Devise::Mapping.find_scope!(resource_or_scope)
128
- home_path = "#{scope}_root_path"
117
+ home_path = :"#{scope}_root_path"
129
118
  respond_to?(home_path, true) ? send(home_path) : root_path
130
119
  end
131
120
 
121
+ # The default url to be used after updating a resource. This is used by all Devise
122
+ # controllers and you can overwrite it in your ApplicationController to
123
+ # provide a custom hook for a custom resource.
124
+ #
125
+ # By default, it first tries to find a resource_root_path, otherwise it
126
+ # uses the root path. For a user scope, you can define the default url in
127
+ # the following way:
128
+ #
129
+ # map.user_root '/users', :controller => 'users' # creates user_root_path
130
+ #
131
+ # map.resources :users do |users|
132
+ # users.root # creates user_root_path
133
+ # end
134
+ #
135
+ #
136
+ # If none of these are defined, root_path is used. However, if this default
137
+ # is not enough, you can customize it, for example:
138
+ #
139
+ # def after_update_path_for(resource)
140
+ # if resource.is_a?(User) && resource.can_publish?
141
+ # publisher_url
142
+ # else
143
+ # super
144
+ # end
145
+ # end
146
+ #
147
+ def after_update_path_for(resource_or_scope)
148
+ after_sign_in_path_for(resource_or_scope)
149
+ end
150
+
132
151
  # Method used by sessions controller to sign out an user. You can overwrite
133
152
  # it in your ApplicationController to provide a custom hook for a custom
134
153
  # scope. Notice that differently from +after_sign_in_path_for+ this method
@@ -144,14 +163,10 @@ module Devise
144
163
  #
145
164
  # If just a symbol is given, consider that the user was already signed in
146
165
  # through other means and just perform the redirection.
147
- def sign_in_and_redirect(resource_or_scope, resource=nil, skip=false)
166
+ def sign_in_and_redirect(resource_or_scope, resource=nil)
148
167
  scope = Devise::Mapping.find_scope!(resource_or_scope)
149
168
  resource ||= resource_or_scope
150
- if skip
151
- @_session = request.session # Recalculate session
152
- else
153
- sign_in(scope, resource)
154
- end
169
+ sign_in(scope, resource) unless warden.user(scope) == resource
155
170
  redirect_to stored_location_for(scope) || after_sign_in_path_for(resource)
156
171
  end
157
172
 
@@ -159,33 +174,23 @@ module Devise
159
174
  # after_sign_out_path_for.
160
175
  def sign_out_and_redirect(resource_or_scope)
161
176
  scope = Devise::Mapping.find_scope!(resource_or_scope)
162
- sign_out(scope)
177
+ if Devise.sign_out_all_scopes
178
+ sign_out_all_scopes
179
+ else
180
+ sign_out(scope)
181
+ end
163
182
  redirect_to after_sign_out_path_for(scope)
164
183
  end
165
184
 
166
- # Sign out all active users or scopes. This helper is useful for signing out all roles
167
- # in one click. This signs out ALL scopes in warden.
168
- def sign_out_all_scopes
169
- Devise.mappings.keys.each { |s| warden.user(s) }
170
- warden.raw_session.inspect
171
- warden.logout
172
- end
173
-
174
- # Override Rails' handle unverified request to sign out all scopes.
175
- def handle_unverified_request
176
- sign_out_all_scopes
177
- super # call the default behaviour which resets the session
178
- end
179
-
180
185
  # Define authentication filters and accessor helpers based on mappings.
181
186
  # These filters should be used inside the controllers as before_filters,
182
187
  # so you can control the scope of the user who should be signed in to
183
188
  # access that specific controller/action.
184
189
  # Example:
185
190
  #
186
- # Maps:
187
- # User => :authenticatable
188
- # Admin => :authenticatable
191
+ # Roles:
192
+ # User
193
+ # Admin
189
194
  #
190
195
  # Generated methods:
191
196
  # authenticate_user! # Signs user in or redirect
@@ -193,7 +198,7 @@ module Devise
193
198
  # user_signed_in? # Checks whether there is an user signed in or not
194
199
  # admin_signed_in? # Checks whether there is an admin signed in or not
195
200
  # current_user # Current signed in user
196
- # current_admin # Current signed in admin
201
+ # current_admin # Currend signed in admin
197
202
  # user_session # Session data available only to the user scope
198
203
  # admin_session # Session data available only to the admin scope
199
204
  #